From f130b6d8dcecf0a4db7606ef53f73883c8370cd8 Mon Sep 17 00:00:00 2001 From: Konrad Lipinski Date: Wed, 5 Jun 2019 14:55:16 +0200 Subject: [PATCH] Make GStore members pure virtual Change-Id: I88347d7c7fcab49e97398d3d4878a4d448123a54 --- src/manager/crypto/generic-backend/gstore.h | 28 ++------- 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 638532d..0a16d42 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 -#include #include #include #include @@ -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 5814a26..c71e5dd 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(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::Equals<0, 1, 2, 3, 4>, - Crypto::DefaultGetter>; - - 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::Equals<0, 1, 2, 3, 4>, - Crypto::DefaultGetter>; - - 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::Equals<0, 1, 2, 3, 4>, - Crypto::DefaultGetter, 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() -- 2.7.4