diff --git a/sdk/keyvault/azure-security-keyvault-common/CMakeLists.txt b/sdk/keyvault/azure-security-keyvault-common/CMakeLists.txt index b444b9acd..d96128bd3 100644 --- a/sdk/keyvault/azure-security-keyvault-common/CMakeLists.txt +++ b/sdk/keyvault/azure-security-keyvault-common/CMakeLists.txt @@ -31,7 +31,7 @@ set( inc/azure/keyvault/common/internal/base64url.hpp inc/azure/keyvault/common/internal/keyvault_pipeline.hpp inc/azure/keyvault/common/internal/single_page.hpp - inc/azure/keyvault/common/internal/sha.hpp + inc/azure/keyvault/common/internal/sha_hash.hpp ) set( @@ -40,7 +40,7 @@ set( src/private/package_version.hpp src/keyvault_pipeline.cpp - src/sha.cpp + src/sha_hash.cpp ) add_library( diff --git a/sdk/keyvault/azure-security-keyvault-common/inc/azure/keyvault/common/internal/sha.hpp b/sdk/keyvault/azure-security-keyvault-common/inc/azure/keyvault/common/internal/sha_hash.hpp similarity index 87% rename from sdk/keyvault/azure-security-keyvault-common/inc/azure/keyvault/common/internal/sha.hpp rename to sdk/keyvault/azure-security-keyvault-common/inc/azure/keyvault/common/internal/sha_hash.hpp index 1e2a6ed32..2e5c83c1b 100644 --- a/sdk/keyvault/azure-security-keyvault-common/inc/azure/keyvault/common/internal/sha.hpp +++ b/sdk/keyvault/azure-security-keyvault-common/inc/azure/keyvault/common/internal/sha_hash.hpp @@ -18,22 +18,22 @@ namespace Azure { namespace Security { namespace KeyVault { namespace _internal { /** - * @brief Defines #SHA256. + * @brief Defines #Sha256Hash. * */ - class SHA256 final : public Azure::Core::Cryptography::Hash { + class Sha256Hash final : public Azure::Core::Cryptography::Hash { public: /** - * @brief Construct a default instance of #SHA256. + * @brief Construct a default instance of #Sha256Hash. * */ - SHA256(); + Sha256Hash(); /** - * @brief Cleanup any state when destroying the instance of #SHA256. + * @brief Cleanup any state when destroying the instance of #Sha256Hash. * */ - ~SHA256(){}; + ~Sha256Hash(){}; private: /** @@ -70,22 +70,22 @@ namespace Azure { namespace Security { namespace KeyVault { namespace _internal }; /** - * @brief Defines #SHA384. + * @brief Defines #Sha384Hash. * */ - class SHA384 final : public Azure::Core::Cryptography::Hash { + class Sha384Hash final : public Azure::Core::Cryptography::Hash { public: /** - * @brief Construct a default instance of #SHA384. + * @brief Construct a default instance of #Sha384Hash. * */ - SHA384(); + Sha384Hash(); /** - * @brief Cleanup any state when destroying the instance of #SHA384. + * @brief Cleanup any state when destroying the instance of #Sha384Hash. * */ - ~SHA384(){}; + ~Sha384Hash(){}; private: /** @@ -122,22 +122,22 @@ namespace Azure { namespace Security { namespace KeyVault { namespace _internal }; /** - * @brief Defines #SHA512. + * @brief Defines #Sha512Hash. * */ - class SHA512 final : public Azure::Core::Cryptography::Hash { + class Sha512Hash final : public Azure::Core::Cryptography::Hash { public: /** - * @brief Construct a default instance of #SHA512. + * @brief Construct a default instance of #Sha512Hash. * */ - SHA512(); + Sha512Hash(); /** - * @brief Cleanup any state when destroying the instance of #SHA512. + * @brief Cleanup any state when destroying the instance of #Sha512Hash. * */ - ~SHA512(){}; + ~Sha512Hash(){}; private: /** diff --git a/sdk/keyvault/azure-security-keyvault-common/src/sha.cpp b/sdk/keyvault/azure-security-keyvault-common/src/sha_hash.cpp similarity index 85% rename from sdk/keyvault/azure-security-keyvault-common/src/sha.cpp rename to sdk/keyvault/azure-security-keyvault-common/src/sha_hash.cpp index 5c48cb3a3..0a7146e8e 100644 --- a/sdk/keyvault/azure-security-keyvault-common/src/sha.cpp +++ b/sdk/keyvault/azure-security-keyvault-common/src/sha_hash.cpp @@ -12,7 +12,7 @@ #include #endif -#include "azure/keyvault/common/internal/sha.hpp" +#include "azure/keyvault/common/internal/sha_hash.hpp" #include #include @@ -31,7 +31,7 @@ enum class SHASize SHA512 }; -/*************************** SHA256 *******************/ +/*************************** Sha256Hash *******************/ class SHAWithOpenSSL final : public Azure::Core::Cryptography::Hash { private: EVP_MD_CTX* m_context; @@ -43,7 +43,7 @@ private: unsigned char finalHash[EVP_MAX_MD_SIZE]; if (1 != EVP_DigestFinal(m_context, finalHash, &size)) { - throw std::runtime_error("Crypto error while computing SHA256."); + throw std::runtime_error("Crypto error while computing Sha256Hash."); } return std::vector(std::begin(finalHash), std::begin(finalHash) + size); } @@ -52,7 +52,7 @@ private: { if (1 != EVP_DigestUpdate(m_context, data, length)) { - throw std::runtime_error("Crypto error while updating SHA256."); + throw std::runtime_error("Crypto error while updating Sha256Hash."); } } @@ -68,21 +68,21 @@ public: case SHASize::SHA256: { if (1 != EVP_DigestInit_ex(m_context, EVP_sha256(), NULL)) { - throw std::runtime_error("Crypto error while init SHA256."); + throw std::runtime_error("Crypto error while init Sha256Hash."); } break; } case SHASize::SHA384: { if (1 != EVP_DigestInit_ex(m_context, EVP_sha384(), NULL)) { - throw std::runtime_error("Crypto error while init SHA384."); + throw std::runtime_error("Crypto error while init Sha384Hash."); } break; } case SHASize::SHA512: { if (1 != EVP_DigestInit_ex(m_context, EVP_sha512(), NULL)) { - throw std::runtime_error("Crypto error while init SHA512."); + throw std::runtime_error("Crypto error while init Sha512Hash."); } break; } @@ -97,17 +97,17 @@ public: } // namespace -Azure::Security::KeyVault::_internal::SHA256::SHA256() +Azure::Security::KeyVault::_internal::Sha256Hash::Sha256Hash() : m_portableImplementation(std::make_unique(SHASize::SHA256)) { } -Azure::Security::KeyVault::_internal::SHA384::SHA384() +Azure::Security::KeyVault::_internal::Sha384Hash::Sha384Hash() : m_portableImplementation(std::make_unique(SHASize::SHA384)) { } -Azure::Security::KeyVault::_internal::SHA512::SHA512() +Azure::Security::KeyVault::_internal::Sha512Hash::Sha512Hash() : m_portableImplementation(std::make_unique(SHASize::SHA512)) { } @@ -222,17 +222,17 @@ public: } // namespace -Azure::Security::KeyVault::_internal::SHA256::SHA256() +Azure::Security::KeyVault::_internal::Sha256Hash::Sha256Hash() : m_portableImplementation(std::make_unique(BCRYPT_SHA256_ALGORITHM)) { } -Azure::Security::KeyVault::_internal::SHA384::SHA384() +Azure::Security::KeyVault::_internal::Sha384Hash::Sha384Hash() : m_portableImplementation(std::make_unique(BCRYPT_SHA384_ALGORITHM)) { } -Azure::Security::KeyVault::_internal::SHA512::SHA512() +Azure::Security::KeyVault::_internal::Sha512Hash::Sha512Hash() : m_portableImplementation(std::make_unique(BCRYPT_SHA512_ALGORITHM)) { } diff --git a/sdk/keyvault/azure-security-keyvault-common/test/ut/sha_test.cpp b/sdk/keyvault/azure-security-keyvault-common/test/ut/sha_test.cpp index d40a42388..7d9d0c3ce 100644 --- a/sdk/keyvault/azure-security-keyvault-common/test/ut/sha_test.cpp +++ b/sdk/keyvault/azure-security-keyvault-common/test/ut/sha_test.cpp @@ -3,14 +3,14 @@ #include "gtest/gtest.h" -#include "azure/keyvault/common/internal/sha.hpp" +#include "azure/keyvault/common/internal/sha_hash.hpp" using namespace Azure::Security::KeyVault::_internal; TEST(SHA, SHA256Test) { - SHA256 sha; - SHA256 sha2; + Sha256Hash sha; + Sha256Hash sha2; uint8_t data[] = "A"; auto shaResult = sha.Final(data, sizeof(data)); auto shaResult2 = sha2.Final(data, sizeof(data)); diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/cryptography/signature_algorithm.cpp b/sdk/keyvault/azure-security-keyvault-keys/src/cryptography/signature_algorithm.cpp index e774077a5..187a19a16 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/src/cryptography/signature_algorithm.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/src/cryptography/signature_algorithm.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // SPDX-License-Identifier: MIT -#include +#include #include "../private/key_constants.hpp" #include "azure/keyvault/keys/cryptography/signature_algorithm.hpp" @@ -28,19 +28,19 @@ namespace Azure { if (*this == SignatureAlgorithm::RS256 || *this == SignatureAlgorithm::PS256 || *this == SignatureAlgorithm::ES256 || *this == SignatureAlgorithm::ES256K) { - return std::make_unique<_internal::SHA256>(); + return std::make_unique<_internal::Sha256Hash>(); } if (*this == SignatureAlgorithm::RS384 || *this == SignatureAlgorithm::PS384 || *this == SignatureAlgorithm::ES384) { - return std::make_unique<_internal::SHA384>(); + return std::make_unique<_internal::Sha384Hash>(); } if (*this == SignatureAlgorithm::RS512 || *this == SignatureAlgorithm::PS512 || *this == SignatureAlgorithm::ES512) { - return std::make_unique<_internal::SHA512>(); + return std::make_unique<_internal::Sha512Hash>(); } throw std::runtime_error("Unkown Hash algorithm for: " + m_value); } diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_cryptographic_client_test_live.cpp b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_cryptographic_client_test_live.cpp index 2a453217b..9bed31a3a 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_cryptographic_client_test_live.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_cryptographic_client_test_live.cpp @@ -7,7 +7,7 @@ #include "gtest/gtest.h" -#include +#include #include "key_client_base_test.hpp" @@ -94,7 +94,7 @@ TEST_P(KeyVaultClientTest, RemoteSignVerifyRSA256) // RS256 { - Azure::Security::KeyVault::_internal::SHA256 sha256; + Azure::Security::KeyVault::_internal::Sha256Hash sha256; auto signatureAlgorithm = SignatureAlgorithm::RS256; std::vector digest = sha256.Final(reinterpret_cast(digestSource.data()), digestSource.size()); @@ -112,7 +112,7 @@ TEST_P(KeyVaultClientTest, RemoteSignVerifyRSA256) // PS256 { - Azure::Security::KeyVault::_internal::SHA256 sha256; + Azure::Security::KeyVault::_internal::Sha256Hash sha256; auto signatureAlgorithm = SignatureAlgorithm::PS256; std::vector digest = sha256.Final(reinterpret_cast(digestSource.data()), digestSource.size()); @@ -142,7 +142,7 @@ TEST_F(KeyVaultClientTest, RemoteSignVerifyES256) auto ecKey = keyClient.CreateEcKey(ecKeyOptions).Value; CryptographyClient cryptoClient(ecKey.Id(), m_credential); - Azure::Security::KeyVault::_internal::SHA256 sha256; + Azure::Security::KeyVault::_internal::Sha256Hash sha256; auto signatureAlgorithm = SignatureAlgorithm::ES256; std::vector digest = sha256.Final(reinterpret_cast(digestSource.data()), digestSource.size()); @@ -165,7 +165,7 @@ TEST_F(KeyVaultClientTest, RemoteSignVerifyES256) auto ecKey = keyClient.CreateEcKey(ecKeyOptions).Value; CryptographyClient cryptoClient(ecKey.Id(), m_credential); - Azure::Security::KeyVault::_internal::SHA256 sha256; + Azure::Security::KeyVault::_internal::Sha256Hash sha256; auto signatureAlgorithm = SignatureAlgorithm::ES256K; std::vector digest = sha256.Final(reinterpret_cast(digestSource.data()), digestSource.size()); @@ -198,7 +198,7 @@ TEST_P(KeyVaultClientTest, RemoteSignVerifyRSA384) // RS384 { - Azure::Security::KeyVault::_internal::SHA384 sha384; + Azure::Security::KeyVault::_internal::Sha384Hash sha384; auto signatureAlgorithm = SignatureAlgorithm::RS384; std::vector digest = sha384.Final(reinterpret_cast(digestSource.data()), digestSource.size()); @@ -216,7 +216,7 @@ TEST_P(KeyVaultClientTest, RemoteSignVerifyRSA384) // PS384 { - Azure::Security::KeyVault::_internal::SHA384 sha384; + Azure::Security::KeyVault::_internal::Sha384Hash sha384; auto signatureAlgorithm = SignatureAlgorithm::PS384; std::vector digest = sha384.Final(reinterpret_cast(digestSource.data()), digestSource.size());