From 22c52996f34099af7e1ef871cef45da29bc39c13 Mon Sep 17 00:00:00 2001 From: Ahson Khan Date: Wed, 23 Oct 2024 10:32:26 -0700 Subject: [PATCH] Move the crytpo headers out of public/internal and into private folders within src. (#6119) --- sdk/tables/azure-data-tables/CMakeLists.txt | 4 +- .../src/account_sas_builder.cpp | 4 +- .../src/cryptography/hmacsha256.cpp | 2 +- .../src/policies/shared_key_lite_policy.cpp | 2 +- .../private}/hmacsha256.hpp | 42 +++---- .../private}/url_encode.hpp | 118 +++++++++--------- .../src/tables_sas_builder.cpp | 4 +- .../test/ut/shared_key_lite_policy_test.cpp | 2 +- 8 files changed, 89 insertions(+), 89 deletions(-) rename sdk/tables/azure-data-tables/{inc/azure/data/tables/internal/cryptography => src/private}/hmacsha256.hpp (96%) rename sdk/tables/azure-data-tables/{inc/azure/data/tables/internal/cryptography => src/private}/url_encode.hpp (97%) diff --git a/sdk/tables/azure-data-tables/CMakeLists.txt b/sdk/tables/azure-data-tables/CMakeLists.txt index f3b5e679c..1a6be2ba5 100644 --- a/sdk/tables/azure-data-tables/CMakeLists.txt +++ b/sdk/tables/azure-data-tables/CMakeLists.txt @@ -46,8 +46,6 @@ set( inc/azure/data/tables/credentials/named_key_credential.hpp inc/azure/data/tables/dll_import_export.hpp inc/azure/data/tables/enum_operators.hpp - inc/azure/data/tables/internal/cryptography/hmacsha256.hpp - inc/azure/data/tables/internal/cryptography/url_encode.hpp inc/azure/data/tables/internal/policies/service_version_policy.hpp inc/azure/data/tables/internal/policies/shared_key_lite_policy.hpp inc/azure/data/tables/internal/policies/tenant_bearer_token_policy.hpp @@ -70,6 +68,8 @@ set( src/policies/shared_key_lite_policy.cpp src/policies/tenant_bearer_token_policy.cpp src/policies/timeout_policy.cpp + src/private/hmacsha256.hpp + src/private/url_encode.hpp src/private/package_version.hpp src/serializers.cpp src/tables_clients.cpp diff --git a/sdk/tables/azure-data-tables/src/account_sas_builder.cpp b/sdk/tables/azure-data-tables/src/account_sas_builder.cpp index b1e95c882..01d142732 100644 --- a/sdk/tables/azure-data-tables/src/account_sas_builder.cpp +++ b/sdk/tables/azure-data-tables/src/account_sas_builder.cpp @@ -3,8 +3,8 @@ #include "azure/data/tables/account_sas_builder.hpp" -#include "azure/data/tables/internal/cryptography/hmacsha256.hpp" -#include "azure/data/tables/internal/cryptography/url_encode.hpp" +#include "private/hmacsha256.hpp" +#include "private/url_encode.hpp" #include #include diff --git a/sdk/tables/azure-data-tables/src/cryptography/hmacsha256.cpp b/sdk/tables/azure-data-tables/src/cryptography/hmacsha256.cpp index 0d3aa3174..718784518 100644 --- a/sdk/tables/azure-data-tables/src/cryptography/hmacsha256.cpp +++ b/sdk/tables/azure-data-tables/src/cryptography/hmacsha256.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -#include "azure/data/tables/internal/cryptography/hmacsha256.hpp" +#include "../private/hmacsha256.hpp" #include #include diff --git a/sdk/tables/azure-data-tables/src/policies/shared_key_lite_policy.cpp b/sdk/tables/azure-data-tables/src/policies/shared_key_lite_policy.cpp index e15f51bce..78819fbc0 100644 --- a/sdk/tables/azure-data-tables/src/policies/shared_key_lite_policy.cpp +++ b/sdk/tables/azure-data-tables/src/policies/shared_key_lite_policy.cpp @@ -3,7 +3,7 @@ #include "azure/data/tables/internal/policies/shared_key_lite_policy.hpp" -#include "azure/data/tables/internal/cryptography/hmacsha256.hpp" +#include "../private/hmacsha256.hpp" #include #include diff --git a/sdk/tables/azure-data-tables/inc/azure/data/tables/internal/cryptography/hmacsha256.hpp b/sdk/tables/azure-data-tables/src/private/hmacsha256.hpp similarity index 96% rename from sdk/tables/azure-data-tables/inc/azure/data/tables/internal/cryptography/hmacsha256.hpp rename to sdk/tables/azure-data-tables/src/private/hmacsha256.hpp index e6e3fe509..f34cdd04b 100644 --- a/sdk/tables/azure-data-tables/inc/azure/data/tables/internal/cryptography/hmacsha256.hpp +++ b/sdk/tables/azure-data-tables/src/private/hmacsha256.hpp @@ -1,21 +1,21 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -#pragma once - -#include - -#include -#include -#include -#include -#include - -namespace Azure { namespace Data { namespace Tables { namespace _detail { namespace Cryptography { - class HmacSha256 final { - public: - static std::vector Compute( - const std::vector& data, - const std::vector& key); - }; -}}}}} // namespace Azure::Data::Tables::_detail::Cryptography +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#pragma once + +#include + +#include +#include +#include +#include +#include + +namespace Azure { namespace Data { namespace Tables { namespace _detail { namespace Cryptography { + class HmacSha256 final { + public: + static std::vector Compute( + const std::vector& data, + const std::vector& key); + }; +}}}}} // namespace Azure::Data::Tables::_detail::Cryptography diff --git a/sdk/tables/azure-data-tables/inc/azure/data/tables/internal/cryptography/url_encode.hpp b/sdk/tables/azure-data-tables/src/private/url_encode.hpp similarity index 97% rename from sdk/tables/azure-data-tables/inc/azure/data/tables/internal/cryptography/url_encode.hpp rename to sdk/tables/azure-data-tables/src/private/url_encode.hpp index 106079509..e1b780d09 100644 --- a/sdk/tables/azure-data-tables/inc/azure/data/tables/internal/cryptography/url_encode.hpp +++ b/sdk/tables/azure-data-tables/src/private/url_encode.hpp @@ -1,59 +1,59 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -#pragma once - -#include -#include -#include -#include -#include - -namespace Azure { namespace Data { namespace Tables { namespace _detail { namespace Cryptography { - - class UrlUtils final { - public: - static std::string UrlEncodeQueryParameter(const std::string& value) - { - const static std::string DoNotEncodeCharacters = []() { - // Core::Url::Encode won't encode unreserved characters. - std::string doNotEncodeCharacters = "!$&'()*+,;="; - doNotEncodeCharacters += "/:@?"; - doNotEncodeCharacters.erase( - std::remove_if( - doNotEncodeCharacters.begin(), - doNotEncodeCharacters.end(), - [](char x) { - // we also encode + and & - // Surprisingly, '=' also needs to be encoded because Azure Storage server side is - // so strict. We are applying this function to query key and value respectively, - // so this won't affect that = used to separate key and query. - return x == '+' || x == '=' || x == '&'; - }), - doNotEncodeCharacters.end()); - return doNotEncodeCharacters; - }(); - return Core::Url::Encode(value, DoNotEncodeCharacters); - } - - static std::string UrlEncodePath(const std::string& value) - { - const static std::string DoNotEncodeCharacters = []() { - // Core::Url::Encode won't encode unreserved characters. - std::string doNotEncodeCharacters = "!$&'()*+,;="; - doNotEncodeCharacters += "/:@"; - doNotEncodeCharacters.erase( - std::remove_if( - doNotEncodeCharacters.begin(), - doNotEncodeCharacters.end(), - [](char x) { - // we also encode + - return x == '+'; - }), - doNotEncodeCharacters.end()); - return doNotEncodeCharacters; - }(); - return Core::Url::Encode(value, DoNotEncodeCharacters); - } - }; -}}}}} // namespace Azure::Data::Tables::_detail::Cryptography +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#pragma once + +#include +#include +#include +#include +#include + +namespace Azure { namespace Data { namespace Tables { namespace _detail { namespace Cryptography { + + class UrlUtils final { + public: + static std::string UrlEncodeQueryParameter(const std::string& value) + { + const static std::string DoNotEncodeCharacters = []() { + // Core::Url::Encode won't encode unreserved characters. + std::string doNotEncodeCharacters = "!$&'()*+,;="; + doNotEncodeCharacters += "/:@?"; + doNotEncodeCharacters.erase( + std::remove_if( + doNotEncodeCharacters.begin(), + doNotEncodeCharacters.end(), + [](char x) { + // we also encode + and & + // Surprisingly, '=' also needs to be encoded because Azure Storage server side is + // so strict. We are applying this function to query key and value respectively, + // so this won't affect that = used to separate key and query. + return x == '+' || x == '=' || x == '&'; + }), + doNotEncodeCharacters.end()); + return doNotEncodeCharacters; + }(); + return Core::Url::Encode(value, DoNotEncodeCharacters); + } + + static std::string UrlEncodePath(const std::string& value) + { + const static std::string DoNotEncodeCharacters = []() { + // Core::Url::Encode won't encode unreserved characters. + std::string doNotEncodeCharacters = "!$&'()*+,;="; + doNotEncodeCharacters += "/:@"; + doNotEncodeCharacters.erase( + std::remove_if( + doNotEncodeCharacters.begin(), + doNotEncodeCharacters.end(), + [](char x) { + // we also encode + + return x == '+'; + }), + doNotEncodeCharacters.end()); + return doNotEncodeCharacters; + }(); + return Core::Url::Encode(value, DoNotEncodeCharacters); + } + }; +}}}}} // namespace Azure::Data::Tables::_detail::Cryptography diff --git a/sdk/tables/azure-data-tables/src/tables_sas_builder.cpp b/sdk/tables/azure-data-tables/src/tables_sas_builder.cpp index 3992a1c29..ec7ebe233 100644 --- a/sdk/tables/azure-data-tables/src/tables_sas_builder.cpp +++ b/sdk/tables/azure-data-tables/src/tables_sas_builder.cpp @@ -3,8 +3,8 @@ #include "azure/data/tables/tables_sas_builder.hpp" -#include "azure/data/tables/internal/cryptography/hmacsha256.hpp" -#include "azure/data/tables/internal/cryptography/url_encode.hpp" +#include "private/hmacsha256.hpp" +#include "private/url_encode.hpp" #include #include diff --git a/sdk/tables/azure-data-tables/test/ut/shared_key_lite_policy_test.cpp b/sdk/tables/azure-data-tables/test/ut/shared_key_lite_policy_test.cpp index 7df7c8d53..b74a93153 100644 --- a/sdk/tables/azure-data-tables/test/ut/shared_key_lite_policy_test.cpp +++ b/sdk/tables/azure-data-tables/test/ut/shared_key_lite_policy_test.cpp @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +#include "../src/private/hmacsha256.hpp" #include "azure/data/tables/credentials/named_key_credential.hpp" -#include "azure/data/tables/internal/cryptography/hmacsha256.hpp" #include "azure/data/tables/internal/policies/shared_key_lite_policy.hpp" #include