Make GStore members pure virtual
authorKonrad Lipinski <k.lipinski2@partner.samsung.com>
Wed, 5 Jun 2019 12:55:16 +0000 (14:55 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 26 Jun 2019 08:53:08 +0000 (10:53 +0200)
Change-Id: I88347d7c7fcab49e97398d3d4878a4d448123a54

src/manager/crypto/generic-backend/gstore.h
tests/test_generic-backend.cpp

index 638532d..0a16d42 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2015 - 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015-2019 Samsung Electronics Co., Ltd. All rights reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -22,7 +22,6 @@
 
 #include <memory>
 
-#include <generic-backend/exception.h>
 #include <generic-backend/gobj.h>
 #include <generic-backend/encryption-params.h>
 #include <ckm/ckm-type.h>
@@ -42,34 +41,19 @@ struct Data {
 
 class GStore {
 public:
-       virtual GObjUPtr getObject(const Token &, const Password &)
-       {
-               ThrowErr(Exc::Crypto::OperationNotSupported);
-       }
+       virtual GObjUPtr getObject(const Token &, const Password &) = 0;
        virtual TokenPair generateAKey(const CryptoAlgorithm &,
                                       const Password &,
-                                      const Password &)
-       {
-               ThrowErr(Exc::Crypto::OperationNotSupported);
-       }
-       virtual Token generateSKey(const CryptoAlgorithm &, const Password &)
-       {
-               ThrowErr(Exc::Crypto::OperationNotSupported);
-       }
+                                      const Password &) = 0;
+       virtual Token generateSKey(const CryptoAlgorithm &, const Password &) = 0;
 
        /*
         * EncryptionParams parameter makes sense only on device with built-in key.
         * EncryptionParams parameter is used for decryption of Data.
         * If Data is not encrypted it's ok to pass empty EncryptionParams.
         */
-       virtual Token import(const Data &, const Password &, const EncryptionParams &)
-       {
-               ThrowErr(Exc::Crypto::OperationNotSupported);
-       }
-       virtual void destroy(const Token &)
-       {
-               ThrowErr(Exc::Crypto::OperationNotSupported);
-       }
+       virtual Token import(const Data &, const Password &, const EncryptionParams &) = 0;
+       virtual void destroy(const Token &) = 0;
        virtual ~GStore() {}
 
 protected:
index 5814a26..c71e5dd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2017 - 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2017-2019 Samsung Electronics Co., Ltd. All rights reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -29,11 +29,6 @@ public:
        GObjTest() : Crypto::GObj() {}
 };
 
-class GStoreTest : public Crypto::GStore {
-public:
-       GStoreTest(CryptoBackend backendId) : Crypto::GStore(backendId) {}
-};
-
 struct TestException : public std::exception {};
 
 class ThrowingHandlerTest {
@@ -63,90 +58,4 @@ BOOST_AUTO_TEST_CASE(gobj)
                                                Exc::Crypto::OperationNotSupported);
 }
 
-BOOST_AUTO_TEST_CASE(gstore)
-{
-       GStoreTest store(static_cast<CryptoBackend>(0));
-
-       BOOST_REQUIRE_THROW(store.getObject(Token(), Password()),
-                                               Exc::Crypto::OperationNotSupported);
-       BOOST_REQUIRE_THROW(store.generateAKey(CryptoAlgorithm(), Password(), Password()),
-                                               Exc::Crypto::OperationNotSupported);
-       BOOST_REQUIRE_THROW(store.generateSKey(CryptoAlgorithm(), Password()),
-                                               Exc::Crypto::OperationNotSupported);
-       BOOST_REQUIRE_THROW(store.import(Crypto::Data(), Password(), Crypto::EncryptionParams()),
-                                               Exc::Crypto::OperationNotSupported);
-       BOOST_REQUIRE_THROW(store.destroy(Token()),
-                                               Exc::Crypto::OperationNotSupported);
-}
-
-#if 0
-BOOST_AUTO_TEST_CASE(algo_validation_not_mandatory)
-{
-       constexpr ParamName pn = ParamName::ALGO_TYPE;
-       using Checker = Crypto::ParamCheck<
-                       pn, int, false, Crypto::Type<int>::Equals<0, 1, 2, 3, 4>,
-                       Crypto::DefaultGetter<int>>;
-
-       Checker checker;
-       CryptoAlgorithm ca;
-
-       BOOST_REQUIRE_NO_THROW(checker.Check(ca));
-
-       for (int i = 0; i < 5; ++i) {
-               ca.setParam(pn, i);
-               BOOST_REQUIRE_NO_THROW(checker.Check(ca));
-       }
-
-       for (int i = 5; i < 10; ++i) {
-               ca.setParam(pn, i);
-               BOOST_REQUIRE_THROW(checker.Check(ca), Exc::Crypto::InputParam);
-       }
-}
-
-BOOST_AUTO_TEST_CASE(algo_validation_mandatory)
-{
-       constexpr ParamName pn = ParamName::ALGO_TYPE;
-       using Checker = Crypto::ParamCheck<
-                       pn, int, true, Crypto::Type<int>::Equals<0, 1, 2, 3, 4>,
-                       Crypto::DefaultGetter<int>>;
-
-       Checker checker;
-       CryptoAlgorithm ca;
-
-       BOOST_REQUIRE_THROW(checker.Check(ca), Exc::Crypto::InputParam);
-
-       for (int i = 0; i < 5; ++i) {
-               ca.setParam(pn, i);
-               BOOST_REQUIRE_NO_THROW(checker.Check(ca));
-       }
-
-       for (int i = 5; i < 10; ++i) {
-               ca.setParam(pn, i);
-               BOOST_REQUIRE_THROW(checker.Check(ca), Exc::Crypto::InputParam);
-       }
-}
-
-BOOST_AUTO_TEST_CASE(algo_validation_throwing_handler)
-{
-       constexpr ParamName pn = ParamName::ALGO_TYPE;
-       using Checker = Crypto::ParamCheck<
-                       pn, int, true, Crypto::Type<int>::Equals<0, 1, 2, 3, 4>,
-                       Crypto::DefaultGetter<int>, ThrowingHandlerTest>;
-
-       Checker checker;
-       CryptoAlgorithm ca;
-       BOOST_REQUIRE_THROW(checker.Check(ca), TestException);
-
-       for (int i = 0; i < 5; ++i) {
-               ca.setParam(pn, i);
-               BOOST_REQUIRE_NO_THROW(checker.Check(ca));
-       }
-
-       for (int i = 5; i < 10; ++i) {
-               ca.setParam(pn, i);
-               BOOST_REQUIRE_THROW(checker.Check(ca), TestException);
-       }
-}
-#endif
-
 BOOST_AUTO_TEST_SUITE_END()