security: Restore automatic key ID generation for symmetric keys
Change-Id: Ic846b02e347b85f0053495a76ebcf8746138d8cf
Refs: #3989
diff --git a/src/security/key-params.hpp b/src/security/key-params.hpp
index ee46c71..4c7d118 100644
--- a/src/security/key-params.hpp
+++ b/src/security/key-params.hpp
@@ -238,6 +238,20 @@
setKeySize(size);
}
+ /**
+ * @brief Create key parameter with auto-created keyId.
+ *
+ * This method is used only if user does not want to maintain the uniqueness of key name.
+ * By default, an 8-byte random number will be used as the key Id.
+ */
+ explicit
+ SimpleSymmetricKeyParams(uint32_t size = KeyParamsInfo::getDefaultSize(),
+ KeyIdType keyIdType = KeyIdType::RANDOM)
+ : KeyParams(KeyParamsInfo::getType(), keyIdType)
+ {
+ setKeySize(size);
+ }
+
uint32_t
getKeySize() const
{
diff --git a/tests/unit-tests/security/key-params.t.cpp b/tests/unit-tests/security/key-params.t.cpp
index a877625..8903e46 100644
--- a/tests/unit-tests/security/key-params.t.cpp
+++ b/tests/unit-tests/security/key-params.t.cpp
@@ -100,6 +100,11 @@
BOOST_CHECK_EQUAL(params5.getKeySize(), 128);
BOOST_CHECK_EQUAL(params5.getKeyIdType(), KeyIdType::USER_SPECIFIED);
BOOST_CHECK_EQUAL(params5.getKeyId(), keyId);
+
+ AesKeyParams params6(192);
+ BOOST_CHECK(params6.getKeyType() == KeyType::AES);
+ BOOST_CHECK_EQUAL(params6.getKeySize(), 192);
+ BOOST_CHECK(params6.getKeyIdType() == KeyIdType::RANDOM);
}
BOOST_AUTO_TEST_CASE(KeyIdTypeInfo)