Keyvault macros deprecate and new names (#5647)

* deprecate macros

* dasda

* need to remove from cpp due to deprecated error

* test

* hgjg

* comments

* definitions

* clangs

* Update sdk/keyvault/azure-security-keyvault-keys/CHANGELOG.md

Co-authored-by: Ahson Khan <ahkha@microsoft.com>

* move test app to build_testing

---------

Co-authored-by: Ahson Khan <ahkha@microsoft.com>
This commit is contained in:
George Arama 2024-05-22 15:29:31 -07:00 committed by GitHub
parent 4de01d6ed7
commit 1e806a17b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 246 additions and 19 deletions

View File

@ -6,6 +6,10 @@
### Breaking Changes
- Deprecated `KeyEncryptionAlgorithm::CKM_RSA_AES_KEY_WRAP` in favor of `KeyEncryptionAlgorithm::CkmRsaAesKeyWrap`.
- Deprecated `KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_256` in favor of `KeyEncryptionAlgorithm::RsaAesKeyWrap256`.
- Deprecated `KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_384` in favor of `KeyEncryptionAlgorithm::RsaAesKeyWrap384`.
### Bugs Fixed
### Other Changes

View File

@ -147,6 +147,7 @@ if(BUILD_TESTING)
add_subdirectory(test/ut)
add_subdirectory(test/ut-hsm)
add_subdirectory(test/macros-build)
endif()
if (BUILD_PERFORMANCE_TESTS)

View File

@ -312,24 +312,59 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
* @param value The string value of the instance.
*/
explicit KeyEncryptionAlgorithm(std::string value) : ExtendableEnumeration(std::move(value)) {}
#ifndef CKM_RSA_AES_KEY_WRAP
/**
* @brief Gets the CKM_RSA_AES_KEY_WRAP algorithm.
*
* @deprecated Use KeyEncryptionAlgorithm::CkmRsaAesKeyWrap.
*/
[[deprecated("Use "
"KeyEncryptionAlgorithm::"
"CkmRsaAesKeyWrap"
".")]] AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyEncryptionAlgorithm
CKM_RSA_AES_KEY_WRAP;
#endif // !CKM_RSA_AES_KEY_WRAP
/**
* @brief Gets the CKM_RSA_AES_KEY_WRAP algorithm.
*
*/
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyEncryptionAlgorithm CKM_RSA_AES_KEY_WRAP;
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyEncryptionAlgorithm CkmRsaAesKeyWrap;
#ifndef RSA_AES_KEY_WRAP_256
/**
* @brief Gets the RSA_AES_KEY_WRAP_256 algorithm.
*
* @deprecated Use KeyEncryptionAlgorithm::RsaAesKeyWrap256.
*/
[[deprecated("Use "
"KeyEncryptionAlgorithm::"
"RsaAesKeyWrap256"
".")]] AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyEncryptionAlgorithm
RSA_AES_KEY_WRAP_256;
#endif // !RSA_AES_KEY_WRAP_256
/**
* @brief Gets the RSA_AES_KEY_WRAP_256 algorithm.
*
*/
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyEncryptionAlgorithm RSA_AES_KEY_WRAP_256;
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyEncryptionAlgorithm RsaAesKeyWrap256;
#ifndef RSA_AES_KEY_WRAP_384
/**
* @brief Gets the RSA_AES_KEY_WRAP_384 algorithm.
*
* @deprecated Use KeyEncryptionAlgorithm::RsaAesKeyWrap384.
*/
[[deprecated("Use "
"KeyEncryptionAlgorithm::"
"RsaAesKeyWrap384"
".")]] AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyEncryptionAlgorithm
RSA_AES_KEY_WRAP_384;
#endif // !RSA_AES_KEY_WRAP_384
/**
* @brief Gets the RSA_AES_KEY_WRAP_384 algorithm.
*
*/
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyEncryptionAlgorithm RSA_AES_KEY_WRAP_384;
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyEncryptionAlgorithm RsaAesKeyWrap384;
};
/**

View File

@ -5,13 +5,38 @@
#include "private/key_constants.hpp"
namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
// Disable deprecation warning
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4996)
#elif defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
const KeyEncryptionAlgorithm KeyEncryptionAlgorithm::CKM_RSA_AES_KEY_WRAP(
_detail::CKM_RSA_AES_KEY_WRAP_Value);
const KeyEncryptionAlgorithm KeyEncryptionAlgorithm::CKM_RSA_AES_KEY_WRAP(
_detail::CKM_RSA_AES_KEY_WRAP_Value);
const KeyEncryptionAlgorithm KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_256(
_detail::RSA_AES_KEY_WRAP_256_Value);
const KeyEncryptionAlgorithm KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_256(
_detail::RSA_AES_KEY_WRAP_256_Value);
const KeyEncryptionAlgorithm KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_384(
_detail::RSA_AES_KEY_WRAP_384_Value);
#if defined(_MSC_VER)
#pragma warning(pop)
#elif defined(__clang__)
#pragma clang diagnostic pop
#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#endif // _MSC_VER
const KeyEncryptionAlgorithm KeyEncryptionAlgorithm::CkmRsaAesKeyWrap(
_detail::CKM_RSA_AES_KEY_WRAP_Value);
const KeyEncryptionAlgorithm KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_384(
_detail::RSA_AES_KEY_WRAP_384_Value);
const KeyEncryptionAlgorithm KeyEncryptionAlgorithm::RsaAesKeyWrap256(
_detail::RSA_AES_KEY_WRAP_256_Value);
const KeyEncryptionAlgorithm KeyEncryptionAlgorithm::RsaAesKeyWrap384(
_detail::RSA_AES_KEY_WRAP_384_Value);
}}}} // namespace Azure::Security::KeyVault::Keys

View File

@ -0,0 +1,17 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
cmake_minimum_required (VERSION 3.13)
project (macros-test LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
add_executable (
macros-build
macros_build.cpp
macros_build.hpp)
create_per_service_target_build_for_sample(keyvault macros-build)
target_link_libraries(macros-build PRIVATE azure-security-keyvault-keys)

View File

@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* @brief Tests the ability to build when certain macros are defined outside the keyvault
* code simulating the customer scenario. If there is an issue there is a build break
*
*/
#include "macros_build.hpp"
#include <azure/keyvault/keys.hpp>
#include <chrono>
#include <fstream>
#include <iostream>
#include <memory>
#include <thread>
using namespace Azure::Security::KeyVault::Keys;
int main()
{
std::cout << "CKM_RSA_AES_KEY_WRAP : " << CKM_RSA_AES_KEY_WRAP << std::endl;
std::cout << "RSA_AES_KEY_WRAP_256 : " << RSA_AES_KEY_WRAP_256 << std::endl;
std::cout << "RSA_AES_KEY_WRAP_384 : " << RSA_AES_KEY_WRAP_384 << std::endl;
std::cout << "KeyEncryptionAlgorithm::CkmRsaAesKeyWrap : "
<< KeyEncryptionAlgorithm::CkmRsaAesKeyWrap.ToString() << std::endl;
std::cout << "KeyEncryptionAlgorithm::RsaAesKeyWrap256 : "
<< KeyEncryptionAlgorithm::RsaAesKeyWrap256.ToString() << std::endl;
std::cout << "KeyEncryptionAlgorithm::RsaAesKeyWrap384 : "
<< KeyEncryptionAlgorithm::RsaAesKeyWrap384.ToString() << std::endl;
}

View File

@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#define CKM_RSA_AES_KEY_WRAP 1
#define RSA_AES_KEY_WRAP_256 2
#define RSA_AES_KEY_WRAP_384 3

View File

@ -86,24 +86,129 @@ TEST(KeyReleaseOptionsUnitTest, Most)
TEST(KeyReleaseOptionsUnitTest, All)
{
KeyReleaseOptions options;
options.Target = "xyz";
options.Nonce = "abc";
options.Encryption = KeyEncryptionAlgorithm::CKM_RSA_AES_KEY_WRAP;
auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options);
auto deserialized = Azure::Core::Json::_internal::json::parse(serialized);
{
KeyReleaseOptions options;
options.Target = "xyz";
options.Nonce = "abc";
options.Encryption = KeyEncryptionAlgorithm::CkmRsaAesKeyWrap;
auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options);
auto deserialized = Azure::Core::Json::_internal::json::parse(serialized);
EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]);
EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]);
EXPECT_EQ(options.Encryption.Value().ToString(), deserialized[_detail::EncryptionValue]);
EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]);
EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]);
EXPECT_EQ(options.Encryption.Value().ToString(), deserialized[_detail::EncryptionValue]);
}
{
KeyReleaseOptions options;
options.Target = "xyz";
options.Nonce = "abc";
options.Encryption = KeyEncryptionAlgorithm::RsaAesKeyWrap256;
auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options);
auto deserialized = Azure::Core::Json::_internal::json::parse(serialized);
EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]);
EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]);
EXPECT_EQ(options.Encryption.Value().ToString(), deserialized[_detail::EncryptionValue]);
}
{
KeyReleaseOptions options;
options.Target = "xyz";
options.Nonce = "abc";
options.Encryption = KeyEncryptionAlgorithm::RsaAesKeyWrap384;
auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options);
auto deserialized = Azure::Core::Json::_internal::json::parse(serialized);
EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]);
EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]);
EXPECT_EQ(options.Encryption.Value().ToString(), deserialized[_detail::EncryptionValue]);
}
// Disable deprecation warning
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4996)
#elif defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
{
KeyReleaseOptions options;
options.Target = "xyz";
options.Nonce = "abc";
options.Encryption = KeyEncryptionAlgorithm::CKM_RSA_AES_KEY_WRAP;
auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options);
auto deserialized = Azure::Core::Json::_internal::json::parse(serialized);
EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]);
EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]);
EXPECT_EQ(options.Encryption.Value().ToString(), deserialized[_detail::EncryptionValue]);
}
{
KeyReleaseOptions options;
options.Target = "xyz";
options.Nonce = "abc";
options.Encryption = KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_256;
auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options);
auto deserialized = Azure::Core::Json::_internal::json::parse(serialized);
EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]);
EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]);
EXPECT_EQ(options.Encryption.Value().ToString(), deserialized[_detail::EncryptionValue]);
}
{
KeyReleaseOptions options;
options.Target = "xyz";
options.Nonce = "abc";
options.Encryption = KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_384;
auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options);
auto deserialized = Azure::Core::Json::_internal::json::parse(serialized);
EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]);
EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]);
EXPECT_EQ(options.Encryption.Value().ToString(), deserialized[_detail::EncryptionValue]);
}
#if defined(_MSC_VER)
#pragma warning(pop)
#elif defined(__clang__)
#pragma clang diagnostic pop
#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#endif // _MSC_VER
}
TEST(KeyEncryptionAlgorithmUnitTest, CheckValues)
{
// Disable deprecation warning
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4996)
#elif defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
EXPECT_EQ(
KeyEncryptionAlgorithm::CKM_RSA_AES_KEY_WRAP.ToString(), _detail::CKM_RSA_AES_KEY_WRAP_Value);
EXPECT_EQ(
KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_256.ToString(), _detail::RSA_AES_KEY_WRAP_256_Value);
EXPECT_EQ(
KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_384.ToString(), _detail::RSA_AES_KEY_WRAP_384_Value);
#if defined(_MSC_VER)
#pragma warning(pop)
#elif defined(__clang__)
#pragma clang diagnostic pop
#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#endif // _MSC_VER
EXPECT_EQ(
KeyEncryptionAlgorithm::CkmRsaAesKeyWrap.ToString(), _detail::CKM_RSA_AES_KEY_WRAP_Value);
EXPECT_EQ(
KeyEncryptionAlgorithm::RsaAesKeyWrap256.ToString(), _detail::RSA_AES_KEY_WRAP_256_Value);
EXPECT_EQ(
KeyEncryptionAlgorithm::RsaAesKeyWrap384.ToString(), _detail::RSA_AES_KEY_WRAP_384_Value);
}