diff options
author | Konrad Lipinski <k.lipinski2@partner.samsung.com> | 2019-06-05 14:55:16 +0200 |
---|---|---|
committer | Krzysztof Jackiewicz <k.jackiewicz@samsung.com> | 2019-06-26 10:53:08 +0200 |
commit | f130b6d8dcecf0a4db7606ef53f73883c8370cd8 (patch) | |
tree | d334cdc095fc41a35ec1dbdbb5a45ed429942109 | |
parent | 74ecfe2c471808727f76470de50c061aed108bda (diff) | |
download | key-manager-f130b6d8dcecf0a4db7606ef53f73883c8370cd8.tar.gz key-manager-f130b6d8dcecf0a4db7606ef53f73883c8370cd8.tar.bz2 key-manager-f130b6d8dcecf0a4db7606ef53f73883c8370cd8.zip |
Make GStore members pure virtual
Change-Id: I88347d7c7fcab49e97398d3d4878a4d448123a54
-rw-r--r-- | src/manager/crypto/generic-backend/gstore.h | 28 | ||||
-rw-r--r-- | tests/test_generic-backend.cpp | 93 |
2 files changed, 7 insertions, 114 deletions
diff --git a/src/manager/crypto/generic-backend/gstore.h b/src/manager/crypto/generic-backend/gstore.h index 638532d6..0a16d42f 100644 --- a/src/manager/crypto/generic-backend/gstore.h +++ b/src/manager/crypto/generic-backend/gstore.h @@ -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: diff --git a/tests/test_generic-backend.cpp b/tests/test_generic-backend.cpp index 5814a264..c71e5dda 100644 --- a/tests/test_generic-backend.cpp +++ b/tests/test_generic-backend.cpp @@ -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() |