From dcfdfe65365199420d8faf184df14c48e532ba75 Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Thu, 18 May 2023 14:50:41 +0200 Subject: [PATCH] Rename DataType::isSKey Change-Id: I59e553cbf067baf3ad7209e07e5376b6601c5a6a --- src/manager/client-async/storage-receiver.cpp | 2 +- src/manager/client/client-manager-impl.cpp | 4 ++-- src/manager/common/data-type.cpp | 2 +- src/manager/common/data-type.h | 8 +------- src/manager/crypto/platform/decider.cpp | 2 +- src/manager/crypto/sw-backend/obj.cpp | 2 +- src/manager/crypto/sw-backend/store.cpp | 2 +- src/manager/crypto/tz-backend/store.cpp | 2 +- src/manager/service/ckm-logic.cpp | 2 +- unit-tests/test_data-type.cpp | 4 ++-- unit-tests/test_sw-backend.cpp | 2 +- 11 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/manager/client-async/storage-receiver.cpp b/src/manager/client-async/storage-receiver.cpp index 6095d09..8e71e0a 100644 --- a/src/manager/client-async/storage-receiver.cpp +++ b/src/manager/client-async/storage-receiver.cpp @@ -125,7 +125,7 @@ void StorageReceiver::parseGetCommand() return; } - if (dataType.isSKey()) + if (dataType.isSymmetricKey()) m_observer->ReceivedKey(KeyAESImpl(rawData)); else if (dataType.isKey()) m_observer->ReceivedKey(KeyImpl(rawData)); diff --git a/src/manager/client/client-manager-impl.cpp b/src/manager/client/client-manager-impl.cpp index 540c93f..75da00f 100644 --- a/src/manager/client/client-manager-impl.cpp +++ b/src/manager/client/client-manager-impl.cpp @@ -310,7 +310,7 @@ int Manager::Impl::getKey(const Alias &alias, const Password &password, if (retCode != CKM_API_SUCCESS) return retCode; - KeyShPtr keyParsed = recvDataType.isSKey() ? Key::createAES(rawData) : Key::create(rawData); + KeyShPtr keyParsed = recvDataType.isSymmetricKey() ? Key::createAES(rawData) : Key::create(rawData); if (!keyParsed) { LogDebug("Key empty - failed to parse!"); @@ -819,7 +819,7 @@ int Manager::Impl::exportWrappedKey(const CryptoAlgorithm ¶ms, if (retCode != CKM_API_SUCCESS) return retCode; - if (dataTypeKey.isSKey()) { + if (dataTypeKey.isSymmetricKey()) { keyType = KeyType::KEY_AES; } else if (dataTypeKey.isKeyPrivate()) { keyType = KeyType::KEY_RSA_PRIVATE; diff --git a/src/manager/common/data-type.cpp b/src/manager/common/data-type.cpp index c70175f..e59bd3f 100644 --- a/src/manager/common/data-type.cpp +++ b/src/manager/common/data-type.cpp @@ -106,7 +106,7 @@ bool DataType::isKey() const return false; } -bool DataType::isSKey() const +bool DataType::isSymmetricKey() const { return (KEY_AES == m_dataType); } diff --git a/src/manager/common/data-type.h b/src/manager/common/data-type.h index 017e214..1866204 100644 --- a/src/manager/common/data-type.h +++ b/src/manager/common/data-type.h @@ -79,13 +79,7 @@ public: operator int() const; bool isKey() const; - - /* - * Number of times someone mistook it for isKey() (or the opposite): 4 - * Increase the counter if it happened to you. - * I will rename this function if the counter reaches 4. - */ - bool isSKey() const; + bool isSymmetricKey() const; bool isChainCert() const; bool isKeyPrivate() const; bool isKeyPublic() const; diff --git a/src/manager/crypto/platform/decider.cpp b/src/manager/crypto/platform/decider.cpp index 8dca91c..ddfc373 100644 --- a/src/manager/crypto/platform/decider.cpp +++ b/src/manager/crypto/platform/decider.cpp @@ -126,7 +126,7 @@ std::deque Decider::getCompatibleBackends(DataType data, if (!encrypted) addSW(); - if (data.isBinaryData() || (data.isSKey() && !policy.extractable)) + if (data.isBinaryData() || (data.isSymmetricKey() && !policy.extractable)) addTZ(); } else { // generate/derive assert(!encrypted); diff --git a/src/manager/crypto/sw-backend/obj.cpp b/src/manager/crypto/sw-backend/obj.cpp index 49d0616..97ea75c 100644 --- a/src/manager/crypto/sw-backend/obj.cpp +++ b/src/manager/crypto/sw-backend/obj.cpp @@ -78,7 +78,7 @@ Token Key::unwrap(const CryptoAlgorithm ¶ms, } // validate the decrypted key - if (wrappedKey.type.isSKey()) { + if (wrappedKey.type.isSymmetricKey()) { auto tmp = CKM::Key::createAES(decrypted); if (!tmp) ThrowErr(Exc::Crypto::InputParam, "Wrapped data is not a valid AES key"); diff --git a/src/manager/crypto/sw-backend/store.cpp b/src/manager/crypto/sw-backend/store.cpp index 7d610f7..30776f5 100644 --- a/src/manager/crypto/sw-backend/store.cpp +++ b/src/manager/crypto/sw-backend/store.cpp @@ -94,7 +94,7 @@ GObjUPtr Store::getObject(const Token &token, const Password &pass) if (token.dataType.isKeyPrivate() || token.dataType.isKeyPublic()) return make(std::move(data), token.dataType); - if (token.dataType.isSKey()) + if (token.dataType.isSymmetricKey()) return make(std::move(data), token.dataType); if (token.dataType.isCertificate() || token.dataType.isChainCert()) diff --git a/src/manager/crypto/tz-backend/store.cpp b/src/manager/crypto/tz-backend/store.cpp index ff992ed..302fd2a 100644 --- a/src/manager/crypto/tz-backend/store.cpp +++ b/src/manager/crypto/tz-backend/store.cpp @@ -71,7 +71,7 @@ GObjUPtr Store::getObject(const Token &token, const Password &pass) if (token.dataType.isKeyPrivate() || token.dataType.isKeyPublic()) return make(scheme, std::move(id), Pwd(pass, iv, tag), token.dataType); - if (token.dataType.isSKey()) + if (token.dataType.isSymmetricKey()) return make(scheme, std::move(id), Pwd(pass, iv, tag), token.dataType); if (token.dataType.isCertificate() || token.dataType.isChainCert()) diff --git a/src/manager/service/ckm-logic.cpp b/src/manager/service/ckm-logic.cpp index a5b158e..0d0a06b 100644 --- a/src/manager/service/ckm-logic.cpp +++ b/src/manager/service/ckm-logic.cpp @@ -81,7 +81,7 @@ int toBinaryData(const Crypto::Data &input, Crypto::Data &output) if (input.type.isKey()) { KeyShPtr output_key; - if (input.type.isSKey()) + if (input.type.isSymmetricKey()) output_key = CKM::Key::createAES(input.data); else output_key = CKM::Key::create(input.data); diff --git a/unit-tests/test_data-type.cpp b/unit-tests/test_data-type.cpp index a237d6a..984e151 100644 --- a/unit-tests/test_data-type.cpp +++ b/unit-tests/test_data-type.cpp @@ -86,8 +86,8 @@ POSITIVE_TEST_CASE(KEY_TYPE_CASTING) POSITIVE_TEST_CASE(UNARY_OPERATIONS) { - BOOST_REQUIRE(DataType(DataType::KEY_AES).isSKey()); - BOOST_REQUIRE(!DataType(DataType::KEY_RSA_PUBLIC).isSKey()); + BOOST_REQUIRE(DataType(DataType::KEY_AES).isSymmetricKey()); + BOOST_REQUIRE(!DataType(DataType::KEY_RSA_PUBLIC).isSymmetricKey()); BOOST_REQUIRE(DataType(DataType::DB_CHAIN_FIRST).isChainCert()); BOOST_REQUIRE(DataType(DataType::DB_CHAIN_LAST).isChainCert()); diff --git a/unit-tests/test_sw-backend.cpp b/unit-tests/test_sw-backend.cpp index a4e6077..19879ae 100644 --- a/unit-tests/test_sw-backend.cpp +++ b/unit-tests/test_sw-backend.cpp @@ -74,7 +74,7 @@ void checkKey(const Token& token, KeyType keyType, const Password& pass) BOOST_REQUIRE(!data.empty()); KeyShPtr key; - if (dataType.isSKey()) + if (dataType.isSymmetricKey()) key = CKM::Key::createAES(data); else key = CKM::Key::create(data); -- 2.7.4