Move Sha256Hash and other Hash algorithm types from KeyVault to Azure::Core (#2526)
* Move the SHA256, 384, and 512 Hash implementations to be internal. * Update changelog and add back missing file. * Rename SHA256 and others to Sha256Hash and update header name. * Fix up path in CMakeList by removing quotes. * Rename the sha.cpp source file to match header. * Move Sha256Hash and other Hash algorithm types from KeyVault to Azure::Core. * Reorder src file in cmakelist to be alpha order just to reset CI * Revert "Reorder src file in cmakelist to be alpha order just to reset CI" This reverts commit 6729cf311af76bb8388738cc519ea40092bc362c.
This commit is contained in:
parent
731d07c2cc
commit
d0ca42643f
@ -61,6 +61,7 @@ set(
|
||||
inc/azure/core/http/transport.hpp
|
||||
inc/azure/core/internal/client_options.hpp
|
||||
inc/azure/core/internal/contract.hpp
|
||||
inc/azure/core/internal/cryptography/sha_hash.hpp
|
||||
inc/azure/core/internal/diagnostics/log.hpp
|
||||
inc/azure/core/internal/http/pipeline.hpp
|
||||
inc/azure/core/internal/io/null_body_stream.hpp
|
||||
@ -95,6 +96,7 @@ set(
|
||||
${WIN_TRANSPORT_ADAPTER_SRC}
|
||||
src/azure_assert.cpp
|
||||
src/cryptography/md5.cpp
|
||||
src/cryptography/sha_hash.cpp
|
||||
src/http/bearer_token_authentication_policy.cpp
|
||||
src/http/http.cpp
|
||||
src/http/log_policy.cpp
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Azure { namespace Security { namespace KeyVault { namespace _internal {
|
||||
namespace Azure { namespace Core { namespace Cryptography { namespace _internal {
|
||||
|
||||
/**
|
||||
* @brief Defines #Sha256Hash.
|
||||
@ -173,4 +173,4 @@ namespace Azure { namespace Security { namespace KeyVault { namespace _internal
|
||||
}
|
||||
};
|
||||
|
||||
}}}} // namespace Azure::Security::KeyVault::_internal
|
||||
}}}} // namespace Azure::Core::Cryptography::_internal
|
||||
@ -12,13 +12,13 @@
|
||||
#include <openssl/evp.h>
|
||||
#endif
|
||||
|
||||
#include "azure/keyvault/common/internal/sha_hash.hpp"
|
||||
#include "azure/core/internal/cryptography/sha_hash.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
using namespace Azure::Security::KeyVault;
|
||||
using namespace Azure::Core::Cryptography;
|
||||
|
||||
#if defined(AZ_PLATFORM_POSIX)
|
||||
|
||||
@ -97,17 +97,17 @@ public:
|
||||
|
||||
} // namespace
|
||||
|
||||
Azure::Security::KeyVault::_internal::Sha256Hash::Sha256Hash()
|
||||
Azure::Core::Cryptography::_internal::Sha256Hash::Sha256Hash()
|
||||
: m_portableImplementation(std::make_unique<SHAWithOpenSSL>(SHASize::SHA256))
|
||||
{
|
||||
}
|
||||
|
||||
Azure::Security::KeyVault::_internal::Sha384Hash::Sha384Hash()
|
||||
Azure::Core::Cryptography::_internal::Sha384Hash::Sha384Hash()
|
||||
: m_portableImplementation(std::make_unique<SHAWithOpenSSL>(SHASize::SHA384))
|
||||
{
|
||||
}
|
||||
|
||||
Azure::Security::KeyVault::_internal::Sha512Hash::Sha512Hash()
|
||||
Azure::Core::Cryptography::_internal::Sha512Hash::Sha512Hash()
|
||||
: m_portableImplementation(std::make_unique<SHAWithOpenSSL>(SHASize::SHA512))
|
||||
{
|
||||
}
|
||||
@ -222,17 +222,17 @@ public:
|
||||
|
||||
} // namespace
|
||||
|
||||
Azure::Security::KeyVault::_internal::Sha256Hash::Sha256Hash()
|
||||
Azure::Core::Cryptography::_internal::Sha256Hash::Sha256Hash()
|
||||
: m_portableImplementation(std::make_unique<SHAWithBCrypt>(BCRYPT_SHA256_ALGORITHM))
|
||||
{
|
||||
}
|
||||
|
||||
Azure::Security::KeyVault::_internal::Sha384Hash::Sha384Hash()
|
||||
Azure::Core::Cryptography::_internal::Sha384Hash::Sha384Hash()
|
||||
: m_portableImplementation(std::make_unique<SHAWithBCrypt>(BCRYPT_SHA384_ALGORITHM))
|
||||
{
|
||||
}
|
||||
|
||||
Azure::Security::KeyVault::_internal::Sha512Hash::Sha512Hash()
|
||||
Azure::Core::Cryptography::_internal::Sha512Hash::Sha512Hash()
|
||||
: m_portableImplementation(std::make_unique<SHAWithBCrypt>(BCRYPT_SHA512_ALGORITHM))
|
||||
{
|
||||
}
|
||||
@ -65,6 +65,7 @@ add_executable (
|
||||
request_id_policy_test.cpp
|
||||
response_t_test.cpp
|
||||
retry_policy_test.cpp
|
||||
sha_test.cpp
|
||||
simplified_header_test.cpp
|
||||
string_test.cpp
|
||||
telemetry_policy_test.cpp
|
||||
|
||||
@ -3,9 +3,9 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "azure/keyvault/common/internal/sha_hash.hpp"
|
||||
#include "azure/core/internal/cryptography/sha_hash.hpp"
|
||||
|
||||
using namespace Azure::Security::KeyVault::_internal;
|
||||
using namespace Azure::Core::Cryptography::_internal;
|
||||
|
||||
TEST(SHA, SHA256Test)
|
||||
{
|
||||
@ -30,16 +30,13 @@ set(
|
||||
AZURE_KEYVAULT_COMMON_HEADER
|
||||
inc/azure/keyvault/common/internal/keyvault_pipeline.hpp
|
||||
inc/azure/keyvault/common/internal/single_page.hpp
|
||||
inc/azure/keyvault/common/internal/sha_hash.hpp
|
||||
)
|
||||
|
||||
set(
|
||||
AZURE_KEYVAULT_COMMON_SOURCE
|
||||
src/private/keyvault_constants.hpp
|
||||
src/private/package_version.hpp
|
||||
|
||||
src/keyvault_pipeline.cpp
|
||||
src/sha_hash.cpp
|
||||
)
|
||||
|
||||
add_library(
|
||||
|
||||
@ -13,7 +13,6 @@ add_executable (
|
||||
azure-security-keyvault-common-test
|
||||
azure_security_keyvault_common_test.cpp
|
||||
pipeline_test.cpp
|
||||
sha_test.cpp
|
||||
)
|
||||
|
||||
if (MSVC)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <azure/keyvault/common/internal/sha_hash.hpp>
|
||||
#include <azure/core/internal/cryptography/sha_hash.hpp>
|
||||
|
||||
#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::Sha256Hash>();
|
||||
return std::make_unique<Azure::Core::Cryptography::_internal::Sha256Hash>();
|
||||
}
|
||||
|
||||
if (*this == SignatureAlgorithm::RS384 || *this == SignatureAlgorithm::PS384
|
||||
|| *this == SignatureAlgorithm::ES384)
|
||||
{
|
||||
return std::make_unique<_internal::Sha384Hash>();
|
||||
return std::make_unique<Azure::Core::Cryptography::_internal::Sha384Hash>();
|
||||
}
|
||||
|
||||
if (*this == SignatureAlgorithm::RS512 || *this == SignatureAlgorithm::PS512
|
||||
|| *this == SignatureAlgorithm::ES512)
|
||||
{
|
||||
return std::make_unique<_internal::Sha512Hash>();
|
||||
return std::make_unique<Azure::Core::Cryptography::_internal::Sha512Hash>();
|
||||
}
|
||||
throw std::runtime_error("Unkown Hash algorithm for: " + m_value);
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <azure/keyvault/common/internal/sha_hash.hpp>
|
||||
#include <azure/core/internal/cryptography/sha_hash.hpp>
|
||||
|
||||
#include "key_client_base_test.hpp"
|
||||
|
||||
@ -94,7 +94,7 @@ TEST_P(KeyVaultClientTest, RemoteSignVerifyRSA256)
|
||||
|
||||
// RS256
|
||||
{
|
||||
Azure::Security::KeyVault::_internal::Sha256Hash sha256;
|
||||
Azure::Core::Cryptography::_internal::Sha256Hash sha256;
|
||||
auto signatureAlgorithm = SignatureAlgorithm::RS256;
|
||||
std::vector<uint8_t> digest
|
||||
= sha256.Final(reinterpret_cast<const uint8_t*>(digestSource.data()), digestSource.size());
|
||||
@ -112,7 +112,7 @@ TEST_P(KeyVaultClientTest, RemoteSignVerifyRSA256)
|
||||
|
||||
// PS256
|
||||
{
|
||||
Azure::Security::KeyVault::_internal::Sha256Hash sha256;
|
||||
Azure::Core::Cryptography::_internal::Sha256Hash sha256;
|
||||
auto signatureAlgorithm = SignatureAlgorithm::PS256;
|
||||
std::vector<uint8_t> digest
|
||||
= sha256.Final(reinterpret_cast<const uint8_t*>(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::Sha256Hash sha256;
|
||||
Azure::Core::Cryptography::_internal::Sha256Hash sha256;
|
||||
auto signatureAlgorithm = SignatureAlgorithm::ES256;
|
||||
std::vector<uint8_t> digest
|
||||
= sha256.Final(reinterpret_cast<const uint8_t*>(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::Sha256Hash sha256;
|
||||
Azure::Core::Cryptography::_internal::Sha256Hash sha256;
|
||||
auto signatureAlgorithm = SignatureAlgorithm::ES256K;
|
||||
std::vector<uint8_t> digest
|
||||
= sha256.Final(reinterpret_cast<const uint8_t*>(digestSource.data()), digestSource.size());
|
||||
@ -198,7 +198,7 @@ TEST_P(KeyVaultClientTest, RemoteSignVerifyRSA384)
|
||||
|
||||
// RS384
|
||||
{
|
||||
Azure::Security::KeyVault::_internal::Sha384Hash sha384;
|
||||
Azure::Core::Cryptography::_internal::Sha384Hash sha384;
|
||||
auto signatureAlgorithm = SignatureAlgorithm::RS384;
|
||||
std::vector<uint8_t> digest
|
||||
= sha384.Final(reinterpret_cast<const uint8_t*>(digestSource.data()), digestSource.size());
|
||||
@ -216,7 +216,7 @@ TEST_P(KeyVaultClientTest, RemoteSignVerifyRSA384)
|
||||
|
||||
// PS384
|
||||
{
|
||||
Azure::Security::KeyVault::_internal::Sha384Hash sha384;
|
||||
Azure::Core::Cryptography::_internal::Sha384Hash sha384;
|
||||
auto signatureAlgorithm = SignatureAlgorithm::PS384;
|
||||
std::vector<uint8_t> digest
|
||||
= sha384.Final(reinterpret_cast<const uint8_t*>(digestSource.data()), digestSource.size());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user