Rename SHA256 and others to Sha256Hash and update header name. (#2525)

First review https://github.com/Azure/azure-sdk-for-cpp/pull/2523

Relevant commit to review: f207fe80b9

Second step of of https://github.com/Azure/azure-sdk-for-cpp/issues/2500#issuecomment-871761727
This commit is contained in:
Ahson Khan 2021-07-01 11:55:58 -07:00 committed by GitHub
parent 5b5cb9b5f7
commit 773beffd64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 47 deletions

View File

@ -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(

View File

@ -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:
/**

View File

@ -12,7 +12,7 @@
#include <openssl/evp.h>
#endif
#include "azure/keyvault/common/internal/sha.hpp"
#include "azure/keyvault/common/internal/sha_hash.hpp"
#include <memory>
#include <stdexcept>
@ -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<uint8_t>(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<SHAWithOpenSSL>(SHASize::SHA256))
{
}
Azure::Security::KeyVault::_internal::SHA384::SHA384()
Azure::Security::KeyVault::_internal::Sha384Hash::Sha384Hash()
: m_portableImplementation(std::make_unique<SHAWithOpenSSL>(SHASize::SHA384))
{
}
Azure::Security::KeyVault::_internal::SHA512::SHA512()
Azure::Security::KeyVault::_internal::Sha512Hash::Sha512Hash()
: m_portableImplementation(std::make_unique<SHAWithOpenSSL>(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<SHAWithBCrypt>(BCRYPT_SHA256_ALGORITHM))
{
}
Azure::Security::KeyVault::_internal::SHA384::SHA384()
Azure::Security::KeyVault::_internal::Sha384Hash::Sha384Hash()
: m_portableImplementation(std::make_unique<SHAWithBCrypt>(BCRYPT_SHA384_ALGORITHM))
{
}
Azure::Security::KeyVault::_internal::SHA512::SHA512()
Azure::Security::KeyVault::_internal::Sha512Hash::Sha512Hash()
: m_portableImplementation(std::make_unique<SHAWithBCrypt>(BCRYPT_SHA512_ALGORITHM))
{
}

View File

@ -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));

View File

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include <azure/keyvault/common/internal/sha.hpp>
#include <azure/keyvault/common/internal/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::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);
}

View File

@ -7,7 +7,7 @@
#include "gtest/gtest.h"
#include <azure/keyvault/common/internal/sha.hpp>
#include <azure/keyvault/common/internal/sha_hash.hpp>
#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<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::SHA256 sha256;
Azure::Security::KeyVault::_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::SHA256 sha256;
Azure::Security::KeyVault::_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::SHA256 sha256;
Azure::Security::KeyVault::_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::SHA384 sha384;
Azure::Security::KeyVault::_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::SHA384 sha384;
Azure::Security::KeyVault::_internal::Sha384Hash sha384;
auto signatureAlgorithm = SignatureAlgorithm::PS384;
std::vector<uint8_t> digest
= sha384.Final(reinterpret_cast<const uint8_t*>(digestSource.data()), digestSource.size());