Remove Base64 encode and decode methods from Azure::Storage and move the string-based helper to Internal. Update storage call sites. (#1298)
Follow up from https://github.com/Azure/azure-sdk-for-cpp/pull/1297 as the second step to fix #1020
This commit is contained in:
parent
1efbfb3056
commit
fb33402844
@ -93,4 +93,4 @@ namespace Azure { namespace Core {
|
||||
|
||||
#endif
|
||||
|
||||
}} // namespace Azure::Core
|
||||
}} // namespace Azure::Core
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
#include <azure/core/base64.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -61,3 +62,52 @@ TEST(Base64, Basic)
|
||||
[](std::string expect, std::string actual) { return expect == actual; }, result, "AQIDBAUG");
|
||||
EXPECT_TRUE(std::equal(subsection.begin(), subsection.end(), Base64Decode(result).begin()));
|
||||
}
|
||||
|
||||
static thread_local std::mt19937_64 random_generator(std::random_device{}());
|
||||
|
||||
static char RandomChar()
|
||||
{
|
||||
const char charset[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
std::uniform_int_distribution<std::size_t> distribution(0, sizeof(charset) - 2);
|
||||
return charset[distribution(random_generator)];
|
||||
}
|
||||
|
||||
void RandomBuffer(char* buffer, std::size_t length)
|
||||
{
|
||||
char* start_addr = buffer;
|
||||
char* end_addr = buffer + length;
|
||||
|
||||
const std::size_t rand_int_size = sizeof(uint64_t);
|
||||
|
||||
while (uintptr_t(start_addr) % rand_int_size != 0 && start_addr < end_addr)
|
||||
{
|
||||
*(start_addr++) = RandomChar();
|
||||
}
|
||||
|
||||
std::uniform_int_distribution<uint64_t> distribution(0ULL, std::numeric_limits<uint64_t>::max());
|
||||
while (start_addr + rand_int_size <= end_addr)
|
||||
{
|
||||
*reinterpret_cast<uint64_t*>(start_addr) = distribution(random_generator);
|
||||
start_addr += rand_int_size;
|
||||
}
|
||||
while (start_addr < end_addr)
|
||||
{
|
||||
*(start_addr++) = RandomChar();
|
||||
}
|
||||
}
|
||||
|
||||
inline void RandomBuffer(uint8_t* buffer, std::size_t length)
|
||||
{
|
||||
RandomBuffer(reinterpret_cast<char*>(buffer), length);
|
||||
}
|
||||
|
||||
TEST(Base64, Roundtrip)
|
||||
{
|
||||
for (std::size_t len : {0, 10, 100, 1000, 10000})
|
||||
{
|
||||
std::vector<uint8_t> data;
|
||||
data.resize(len);
|
||||
RandomBuffer(data.data(), data.size());
|
||||
EXPECT_EQ(Base64Decode(Base64Encode(data)), data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4343,7 +4343,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
path.size() == 2 && path[0] == XmlTagName::k_Properties
|
||||
&& path[1] == XmlTagName::k_ContentMD5)
|
||||
{
|
||||
ret.HttpHeaders.ContentHash.Value = Base64Decode(node.Value);
|
||||
ret.HttpHeaders.ContentHash.Value = Azure::Core::Base64Decode(node.Value);
|
||||
}
|
||||
else if (
|
||||
path.size() == 2 && path[0] == XmlTagName::k_Properties
|
||||
@ -4443,7 +4443,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
path.size() == 2 && path[0] == XmlTagName::k_Properties
|
||||
&& path[1] == XmlTagName::k_EncryptionKeySHA256)
|
||||
{
|
||||
ret.EncryptionKeySha256 = Base64Decode(node.Value);
|
||||
ret.EncryptionKeySha256 = Azure::Core::Base64Decode(node.Value);
|
||||
}
|
||||
else if (
|
||||
path.size() == 2 && path[0] == XmlTagName::k_Properties
|
||||
@ -4788,7 +4788,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (options.EncryptionKeySha256.HasValue())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-encryption-key-sha256", Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
"x-ms-encryption-key-sha256", Azure::Core::Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
}
|
||||
if (options.EncryptionAlgorithm.HasValue())
|
||||
{
|
||||
@ -4847,7 +4847,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
ContentHash hash;
|
||||
hash.Algorithm = HashAlgorithm::Md5;
|
||||
hash.Value = Base64Decode(content_md5_iterator->second);
|
||||
hash.Value = Azure::Core::Base64Decode(content_md5_iterator->second);
|
||||
response.TransactionalContentHash = std::move(hash);
|
||||
}
|
||||
auto x_ms_content_crc64_iterator = headers.find("x-ms-content-crc64");
|
||||
@ -4855,7 +4855,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
ContentHash hash;
|
||||
hash.Algorithm = HashAlgorithm::Crc64;
|
||||
hash.Value = Base64Decode(x_ms_content_crc64_iterator->second);
|
||||
hash.Value = Azure::Core::Base64Decode(x_ms_content_crc64_iterator->second);
|
||||
response.TransactionalContentHash = std::move(hash);
|
||||
}
|
||||
}
|
||||
@ -4882,14 +4882,14 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
auto content_md5__iterator = httpResponse.GetHeaders().find("content-md5");
|
||||
if (content_md5__iterator != httpResponse.GetHeaders().end())
|
||||
{
|
||||
response.HttpHeaders.ContentHash.Value = Base64Decode(content_md5__iterator->second);
|
||||
response.HttpHeaders.ContentHash.Value = Azure::Core::Base64Decode(content_md5__iterator->second);
|
||||
}
|
||||
auto x_ms_blob_content_md5__iterator
|
||||
= httpResponse.GetHeaders().find("x-ms-blob-content-md5");
|
||||
if (x_ms_blob_content_md5__iterator != httpResponse.GetHeaders().end())
|
||||
{
|
||||
response.HttpHeaders.ContentHash.Value
|
||||
= Base64Decode(x_ms_blob_content_md5__iterator->second);
|
||||
= Azure::Core::Base64Decode(x_ms_blob_content_md5__iterator->second);
|
||||
}
|
||||
auto content_disposition__iterator
|
||||
= httpResponse.GetHeaders().find("content-disposition");
|
||||
@ -4910,7 +4910,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (x_ms_encryption_key_sha256__iterator != httpResponse.GetHeaders().end())
|
||||
{
|
||||
response.EncryptionKeySha256
|
||||
= Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
= Azure::Core::Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
}
|
||||
auto x_ms_encryption_scope__iterator
|
||||
= httpResponse.GetHeaders().find("x-ms-encryption-scope");
|
||||
@ -5220,7 +5220,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (options.EncryptionKeySha256.HasValue())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-encryption-key-sha256", Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
"x-ms-encryption-key-sha256", Azure::Core::Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
}
|
||||
if (options.EncryptionAlgorithm.HasValue())
|
||||
{
|
||||
@ -5335,14 +5335,14 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
auto content_md5__iterator = httpResponse.GetHeaders().find("content-md5");
|
||||
if (content_md5__iterator != httpResponse.GetHeaders().end())
|
||||
{
|
||||
response.HttpHeaders.ContentHash.Value = Base64Decode(content_md5__iterator->second);
|
||||
response.HttpHeaders.ContentHash.Value = Azure::Core::Base64Decode(content_md5__iterator->second);
|
||||
}
|
||||
auto x_ms_blob_content_md5__iterator
|
||||
= httpResponse.GetHeaders().find("x-ms-blob-content-md5");
|
||||
if (x_ms_blob_content_md5__iterator != httpResponse.GetHeaders().end())
|
||||
{
|
||||
response.HttpHeaders.ContentHash.Value
|
||||
= Base64Decode(x_ms_blob_content_md5__iterator->second);
|
||||
= Azure::Core::Base64Decode(x_ms_blob_content_md5__iterator->second);
|
||||
}
|
||||
auto content_disposition__iterator
|
||||
= httpResponse.GetHeaders().find("content-disposition");
|
||||
@ -5375,7 +5375,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (x_ms_encryption_key_sha256__iterator != httpResponse.GetHeaders().end())
|
||||
{
|
||||
response.EncryptionKeySha256
|
||||
= Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
= Azure::Core::Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
}
|
||||
auto x_ms_encryption_scope__iterator
|
||||
= httpResponse.GetHeaders().find("x-ms-encryption-scope");
|
||||
@ -5523,10 +5523,10 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
request.AddHeader("x-ms-blob-cache-control", options.HttpHeaders.CacheControl);
|
||||
}
|
||||
if (!Base64Encode(options.HttpHeaders.ContentHash.Value).empty())
|
||||
if (!Azure::Core::Base64Encode(options.HttpHeaders.ContentHash.Value).empty())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-blob-content-md5", Base64Encode(options.HttpHeaders.ContentHash.Value));
|
||||
"x-ms-blob-content-md5", Azure::Core::Base64Encode(options.HttpHeaders.ContentHash.Value));
|
||||
}
|
||||
if (!options.HttpHeaders.ContentDisposition.empty())
|
||||
{
|
||||
@ -5630,7 +5630,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (options.EncryptionKeySha256.HasValue())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-encryption-key-sha256", Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
"x-ms-encryption-key-sha256", Azure::Core::Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
}
|
||||
if (options.EncryptionAlgorithm.HasValue())
|
||||
{
|
||||
@ -5977,7 +5977,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (options.EncryptionKeySha256.HasValue())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-encryption-key-sha256", Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
"x-ms-encryption-key-sha256", Azure::Core::Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
}
|
||||
if (options.EncryptionAlgorithm.HasValue())
|
||||
{
|
||||
@ -6043,7 +6043,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (x_ms_encryption_key_sha256__iterator != httpResponse.GetHeaders().end())
|
||||
{
|
||||
response.EncryptionKeySha256
|
||||
= Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
= Azure::Core::Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
}
|
||||
auto x_ms_encryption_scope__iterator
|
||||
= httpResponse.GetHeaders().find("x-ms-encryption-scope");
|
||||
@ -6723,7 +6723,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (options.EncryptionKeySha256.HasValue())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-encryption-key-sha256", Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
"x-ms-encryption-key-sha256", Azure::Core::Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
}
|
||||
if (options.EncryptionAlgorithm.HasValue())
|
||||
{
|
||||
@ -6739,13 +6739,13 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (options.TransactionalContentHash.GetValue().Algorithm == HashAlgorithm::Md5)
|
||||
{
|
||||
request.AddHeader(
|
||||
"Content-MD5", Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
"Content-MD5", Azure::Core::Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
}
|
||||
else if (options.TransactionalContentHash.GetValue().Algorithm == HashAlgorithm::Crc64)
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-content-crc64",
|
||||
Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
Azure::Core::Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
}
|
||||
}
|
||||
if (!options.HttpHeaders.ContentType.empty())
|
||||
@ -6764,10 +6764,10 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
request.AddHeader("x-ms-blob-cache-control", options.HttpHeaders.CacheControl);
|
||||
}
|
||||
if (!Base64Encode(options.HttpHeaders.ContentHash.Value).empty())
|
||||
if (!Azure::Core::Base64Encode(options.HttpHeaders.ContentHash.Value).empty())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-blob-content-md5", Base64Encode(options.HttpHeaders.ContentHash.Value));
|
||||
"x-ms-blob-content-md5", Azure::Core::Base64Encode(options.HttpHeaders.ContentHash.Value));
|
||||
}
|
||||
if (!options.HttpHeaders.ContentDisposition.empty())
|
||||
{
|
||||
@ -6834,7 +6834,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
ContentHash hash;
|
||||
hash.Algorithm = HashAlgorithm::Md5;
|
||||
hash.Value = Base64Decode(content_md5_iterator->second);
|
||||
hash.Value = Azure::Core::Base64Decode(content_md5_iterator->second);
|
||||
response.TransactionalContentHash = std::move(hash);
|
||||
}
|
||||
auto x_ms_content_crc64_iterator = headers.find("x-ms-content-crc64");
|
||||
@ -6842,7 +6842,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
ContentHash hash;
|
||||
hash.Algorithm = HashAlgorithm::Crc64;
|
||||
hash.Value = Base64Decode(x_ms_content_crc64_iterator->second);
|
||||
hash.Value = Azure::Core::Base64Decode(x_ms_content_crc64_iterator->second);
|
||||
response.TransactionalContentHash = std::move(hash);
|
||||
}
|
||||
}
|
||||
@ -6858,7 +6858,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (x_ms_encryption_key_sha256__iterator != httpResponse.GetHeaders().end())
|
||||
{
|
||||
response.EncryptionKeySha256
|
||||
= Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
= Azure::Core::Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
}
|
||||
auto x_ms_encryption_scope__iterator
|
||||
= httpResponse.GetHeaders().find("x-ms-encryption-scope");
|
||||
@ -6907,13 +6907,13 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (options.TransactionalContentHash.GetValue().Algorithm == HashAlgorithm::Md5)
|
||||
{
|
||||
request.AddHeader(
|
||||
"Content-MD5", Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
"Content-MD5", Azure::Core::Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
}
|
||||
else if (options.TransactionalContentHash.GetValue().Algorithm == HashAlgorithm::Crc64)
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-content-crc64",
|
||||
Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
Azure::Core::Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
}
|
||||
}
|
||||
if (options.LeaseId.HasValue())
|
||||
@ -6927,7 +6927,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (options.EncryptionKeySha256.HasValue())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-encryption-key-sha256", Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
"x-ms-encryption-key-sha256", Azure::Core::Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
}
|
||||
if (options.EncryptionAlgorithm.HasValue())
|
||||
{
|
||||
@ -6955,7 +6955,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
ContentHash hash;
|
||||
hash.Algorithm = HashAlgorithm::Md5;
|
||||
hash.Value = Base64Decode(content_md5_iterator->second);
|
||||
hash.Value = Azure::Core::Base64Decode(content_md5_iterator->second);
|
||||
response.TransactionalContentHash = std::move(hash);
|
||||
}
|
||||
auto x_ms_content_crc64_iterator = headers.find("x-ms-content-crc64");
|
||||
@ -6963,7 +6963,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
ContentHash hash;
|
||||
hash.Algorithm = HashAlgorithm::Crc64;
|
||||
hash.Value = Base64Decode(x_ms_content_crc64_iterator->second);
|
||||
hash.Value = Azure::Core::Base64Decode(x_ms_content_crc64_iterator->second);
|
||||
response.TransactionalContentHash = std::move(hash);
|
||||
}
|
||||
}
|
||||
@ -6974,7 +6974,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (x_ms_encryption_key_sha256__iterator != httpResponse.GetHeaders().end())
|
||||
{
|
||||
response.EncryptionKeySha256
|
||||
= Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
= Azure::Core::Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
}
|
||||
auto x_ms_encryption_scope__iterator
|
||||
= httpResponse.GetHeaders().find("x-ms-encryption-scope");
|
||||
@ -7041,13 +7041,13 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-source-content-md5",
|
||||
Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
Azure::Core::Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
}
|
||||
else if (options.TransactionalContentHash.GetValue().Algorithm == HashAlgorithm::Crc64)
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-source-content-crc64",
|
||||
Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
Azure::Core::Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
}
|
||||
}
|
||||
if (options.LeaseId.HasValue())
|
||||
@ -7061,7 +7061,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (options.EncryptionKeySha256.HasValue())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-encryption-key-sha256", Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
"x-ms-encryption-key-sha256", Azure::Core::Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
}
|
||||
if (options.EncryptionAlgorithm.HasValue())
|
||||
{
|
||||
@ -7111,7 +7111,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
ContentHash hash;
|
||||
hash.Algorithm = HashAlgorithm::Md5;
|
||||
hash.Value = Base64Decode(content_md5_iterator->second);
|
||||
hash.Value = Azure::Core::Base64Decode(content_md5_iterator->second);
|
||||
response.TransactionalContentHash = std::move(hash);
|
||||
}
|
||||
auto x_ms_content_crc64_iterator = headers.find("x-ms-content-crc64");
|
||||
@ -7119,7 +7119,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
ContentHash hash;
|
||||
hash.Algorithm = HashAlgorithm::Crc64;
|
||||
hash.Value = Base64Decode(x_ms_content_crc64_iterator->second);
|
||||
hash.Value = Azure::Core::Base64Decode(x_ms_content_crc64_iterator->second);
|
||||
response.TransactionalContentHash = std::move(hash);
|
||||
}
|
||||
}
|
||||
@ -7130,7 +7130,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (x_ms_encryption_key_sha256__iterator != httpResponse.GetHeaders().end())
|
||||
{
|
||||
response.EncryptionKeySha256
|
||||
= Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
= Azure::Core::Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
}
|
||||
auto x_ms_encryption_scope__iterator
|
||||
= httpResponse.GetHeaders().find("x-ms-encryption-scope");
|
||||
@ -7203,10 +7203,10 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
request.AddHeader("x-ms-blob-cache-control", options.HttpHeaders.CacheControl);
|
||||
}
|
||||
if (!Base64Encode(options.HttpHeaders.ContentHash.Value).empty())
|
||||
if (!Azure::Core::Base64Encode(options.HttpHeaders.ContentHash.Value).empty())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-blob-content-md5", Base64Encode(options.HttpHeaders.ContentHash.Value));
|
||||
"x-ms-blob-content-md5", Azure::Core::Base64Encode(options.HttpHeaders.ContentHash.Value));
|
||||
}
|
||||
if (!options.HttpHeaders.ContentDisposition.empty())
|
||||
{
|
||||
@ -7228,7 +7228,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (options.EncryptionKeySha256.HasValue())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-encryption-key-sha256", Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
"x-ms-encryption-key-sha256", Azure::Core::Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
}
|
||||
if (options.EncryptionAlgorithm.HasValue())
|
||||
{
|
||||
@ -7295,7 +7295,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (x_ms_encryption_key_sha256__iterator != httpResponse.GetHeaders().end())
|
||||
{
|
||||
response.EncryptionKeySha256
|
||||
= Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
= Azure::Core::Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
}
|
||||
auto x_ms_encryption_scope__iterator
|
||||
= httpResponse.GetHeaders().find("x-ms-encryption-scope");
|
||||
@ -7572,10 +7572,10 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
request.AddHeader("x-ms-blob-cache-control", options.HttpHeaders.CacheControl);
|
||||
}
|
||||
if (!Base64Encode(options.HttpHeaders.ContentHash.Value).empty())
|
||||
if (!Azure::Core::Base64Encode(options.HttpHeaders.ContentHash.Value).empty())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-blob-content-md5", Base64Encode(options.HttpHeaders.ContentHash.Value));
|
||||
"x-ms-blob-content-md5", Azure::Core::Base64Encode(options.HttpHeaders.ContentHash.Value));
|
||||
}
|
||||
if (!options.HttpHeaders.ContentDisposition.empty())
|
||||
{
|
||||
@ -7608,7 +7608,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (options.EncryptionKeySha256.HasValue())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-encryption-key-sha256", Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
"x-ms-encryption-key-sha256", Azure::Core::Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
}
|
||||
if (options.EncryptionAlgorithm.HasValue())
|
||||
{
|
||||
@ -7671,7 +7671,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (x_ms_encryption_key_sha256__iterator != httpResponse.GetHeaders().end())
|
||||
{
|
||||
response.EncryptionKeySha256
|
||||
= Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
= Azure::Core::Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
}
|
||||
auto x_ms_encryption_scope__iterator
|
||||
= httpResponse.GetHeaders().find("x-ms-encryption-scope");
|
||||
@ -7735,13 +7735,13 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (options.TransactionalContentHash.GetValue().Algorithm == HashAlgorithm::Md5)
|
||||
{
|
||||
request.AddHeader(
|
||||
"Content-MD5", Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
"Content-MD5", Azure::Core::Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
}
|
||||
else if (options.TransactionalContentHash.GetValue().Algorithm == HashAlgorithm::Crc64)
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-content-crc64",
|
||||
Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
Azure::Core::Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
}
|
||||
}
|
||||
request.AddHeader("x-ms-page-write", "update");
|
||||
@ -7774,7 +7774,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (options.EncryptionKeySha256.HasValue())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-encryption-key-sha256", Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
"x-ms-encryption-key-sha256", Azure::Core::Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
}
|
||||
if (options.EncryptionAlgorithm.HasValue())
|
||||
{
|
||||
@ -7832,7 +7832,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
ContentHash hash;
|
||||
hash.Algorithm = HashAlgorithm::Md5;
|
||||
hash.Value = Base64Decode(content_md5_iterator->second);
|
||||
hash.Value = Azure::Core::Base64Decode(content_md5_iterator->second);
|
||||
response.TransactionalContentHash = std::move(hash);
|
||||
}
|
||||
auto x_ms_content_crc64_iterator = headers.find("x-ms-content-crc64");
|
||||
@ -7840,7 +7840,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
ContentHash hash;
|
||||
hash.Algorithm = HashAlgorithm::Crc64;
|
||||
hash.Value = Base64Decode(x_ms_content_crc64_iterator->second);
|
||||
hash.Value = Azure::Core::Base64Decode(x_ms_content_crc64_iterator->second);
|
||||
response.TransactionalContentHash = std::move(hash);
|
||||
}
|
||||
}
|
||||
@ -7853,7 +7853,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (x_ms_encryption_key_sha256__iterator != httpResponse.GetHeaders().end())
|
||||
{
|
||||
response.EncryptionKeySha256
|
||||
= Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
= Azure::Core::Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
}
|
||||
auto x_ms_encryption_scope__iterator
|
||||
= httpResponse.GetHeaders().find("x-ms-encryption-scope");
|
||||
@ -7928,13 +7928,13 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-source-content-md5",
|
||||
Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
Azure::Core::Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
}
|
||||
else if (options.TransactionalContentHash.GetValue().Algorithm == HashAlgorithm::Crc64)
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-source-content-crc64",
|
||||
Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
Azure::Core::Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
}
|
||||
}
|
||||
request.AddHeader("x-ms-page-write", "update");
|
||||
@ -7967,7 +7967,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (options.EncryptionKeySha256.HasValue())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-encryption-key-sha256", Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
"x-ms-encryption-key-sha256", Azure::Core::Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
}
|
||||
if (options.EncryptionAlgorithm.HasValue())
|
||||
{
|
||||
@ -8025,7 +8025,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
ContentHash hash;
|
||||
hash.Algorithm = HashAlgorithm::Md5;
|
||||
hash.Value = Base64Decode(content_md5_iterator->second);
|
||||
hash.Value = Azure::Core::Base64Decode(content_md5_iterator->second);
|
||||
response.TransactionalContentHash = std::move(hash);
|
||||
}
|
||||
auto x_ms_content_crc64_iterator = headers.find("x-ms-content-crc64");
|
||||
@ -8033,7 +8033,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
ContentHash hash;
|
||||
hash.Algorithm = HashAlgorithm::Crc64;
|
||||
hash.Value = Base64Decode(x_ms_content_crc64_iterator->second);
|
||||
hash.Value = Azure::Core::Base64Decode(x_ms_content_crc64_iterator->second);
|
||||
response.TransactionalContentHash = std::move(hash);
|
||||
}
|
||||
}
|
||||
@ -8046,7 +8046,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (x_ms_encryption_key_sha256__iterator != httpResponse.GetHeaders().end())
|
||||
{
|
||||
response.EncryptionKeySha256
|
||||
= Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
= Azure::Core::Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
}
|
||||
auto x_ms_encryption_scope__iterator
|
||||
= httpResponse.GetHeaders().find("x-ms-encryption-scope");
|
||||
@ -8132,7 +8132,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (options.EncryptionKeySha256.HasValue())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-encryption-key-sha256", Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
"x-ms-encryption-key-sha256", Azure::Core::Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
}
|
||||
if (options.EncryptionAlgorithm.HasValue())
|
||||
{
|
||||
@ -8254,7 +8254,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (options.EncryptionKeySha256.HasValue())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-encryption-key-sha256", Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
"x-ms-encryption-key-sha256", Azure::Core::Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
}
|
||||
if (options.EncryptionAlgorithm.HasValue())
|
||||
{
|
||||
@ -8728,10 +8728,10 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
request.AddHeader("x-ms-blob-cache-control", options.HttpHeaders.CacheControl);
|
||||
}
|
||||
if (!Base64Encode(options.HttpHeaders.ContentHash.Value).empty())
|
||||
if (!Azure::Core::Base64Encode(options.HttpHeaders.ContentHash.Value).empty())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-blob-content-md5", Base64Encode(options.HttpHeaders.ContentHash.Value));
|
||||
"x-ms-blob-content-md5", Azure::Core::Base64Encode(options.HttpHeaders.ContentHash.Value));
|
||||
}
|
||||
if (!options.HttpHeaders.ContentDisposition.empty())
|
||||
{
|
||||
@ -8754,7 +8754,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (options.EncryptionKeySha256.HasValue())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-encryption-key-sha256", Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
"x-ms-encryption-key-sha256", Azure::Core::Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
}
|
||||
if (options.EncryptionAlgorithm.HasValue())
|
||||
{
|
||||
@ -8817,7 +8817,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (x_ms_encryption_key_sha256__iterator != httpResponse.GetHeaders().end())
|
||||
{
|
||||
response.EncryptionKeySha256
|
||||
= Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
= Azure::Core::Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
}
|
||||
auto x_ms_encryption_scope__iterator
|
||||
= httpResponse.GetHeaders().find("x-ms-encryption-scope");
|
||||
@ -8870,13 +8870,13 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (options.TransactionalContentHash.GetValue().Algorithm == HashAlgorithm::Md5)
|
||||
{
|
||||
request.AddHeader(
|
||||
"Content-MD5", Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
"Content-MD5", Azure::Core::Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
}
|
||||
else if (options.TransactionalContentHash.GetValue().Algorithm == HashAlgorithm::Crc64)
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-content-crc64",
|
||||
Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
Azure::Core::Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
}
|
||||
}
|
||||
if (options.LeaseId.HasValue())
|
||||
@ -8900,7 +8900,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (options.EncryptionKeySha256.HasValue())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-encryption-key-sha256", Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
"x-ms-encryption-key-sha256", Azure::Core::Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
}
|
||||
if (options.EncryptionAlgorithm.HasValue())
|
||||
{
|
||||
@ -8958,7 +8958,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
ContentHash hash;
|
||||
hash.Algorithm = HashAlgorithm::Md5;
|
||||
hash.Value = Base64Decode(content_md5_iterator->second);
|
||||
hash.Value = Azure::Core::Base64Decode(content_md5_iterator->second);
|
||||
response.TransactionalContentHash = std::move(hash);
|
||||
}
|
||||
auto x_ms_content_crc64_iterator = headers.find("x-ms-content-crc64");
|
||||
@ -8966,7 +8966,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
ContentHash hash;
|
||||
hash.Algorithm = HashAlgorithm::Crc64;
|
||||
hash.Value = Base64Decode(x_ms_content_crc64_iterator->second);
|
||||
hash.Value = Azure::Core::Base64Decode(x_ms_content_crc64_iterator->second);
|
||||
response.TransactionalContentHash = std::move(hash);
|
||||
}
|
||||
}
|
||||
@ -8981,7 +8981,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (x_ms_encryption_key_sha256__iterator != httpResponse.GetHeaders().end())
|
||||
{
|
||||
response.EncryptionKeySha256
|
||||
= Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
= Azure::Core::Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
}
|
||||
auto x_ms_encryption_scope__iterator
|
||||
= httpResponse.GetHeaders().find("x-ms-encryption-scope");
|
||||
@ -9048,13 +9048,13 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-source-content-md5",
|
||||
Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
Azure::Core::Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
}
|
||||
else if (options.TransactionalContentHash.GetValue().Algorithm == HashAlgorithm::Crc64)
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-source-content-crc64",
|
||||
Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
Azure::Core::Base64Encode(options.TransactionalContentHash.GetValue().Value));
|
||||
}
|
||||
}
|
||||
if (options.LeaseId.HasValue())
|
||||
@ -9078,7 +9078,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (options.EncryptionKeySha256.HasValue())
|
||||
{
|
||||
request.AddHeader(
|
||||
"x-ms-encryption-key-sha256", Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
"x-ms-encryption-key-sha256", Azure::Core::Base64Encode(options.EncryptionKeySha256.GetValue()));
|
||||
}
|
||||
if (options.EncryptionAlgorithm.HasValue())
|
||||
{
|
||||
@ -9136,7 +9136,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
ContentHash hash;
|
||||
hash.Algorithm = HashAlgorithm::Md5;
|
||||
hash.Value = Base64Decode(content_md5_iterator->second);
|
||||
hash.Value = Azure::Core::Base64Decode(content_md5_iterator->second);
|
||||
response.TransactionalContentHash = std::move(hash);
|
||||
}
|
||||
auto x_ms_content_crc64_iterator = headers.find("x-ms-content-crc64");
|
||||
@ -9144,7 +9144,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
{
|
||||
ContentHash hash;
|
||||
hash.Algorithm = HashAlgorithm::Crc64;
|
||||
hash.Value = Base64Decode(x_ms_content_crc64_iterator->second);
|
||||
hash.Value = Azure::Core::Base64Decode(x_ms_content_crc64_iterator->second);
|
||||
response.TransactionalContentHash = std::move(hash);
|
||||
}
|
||||
}
|
||||
@ -9159,7 +9159,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
if (x_ms_encryption_key_sha256__iterator != httpResponse.GetHeaders().end())
|
||||
{
|
||||
response.EncryptionKeySha256
|
||||
= Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
= Azure::Core::Base64Decode(x_ms_encryption_key_sha256__iterator->second);
|
||||
}
|
||||
auto x_ms_encryption_scope__iterator
|
||||
= httpResponse.GetHeaders().find("x-ms-encryption-scope");
|
||||
|
||||
@ -141,9 +141,9 @@ namespace Azure { namespace Storage { namespace Sas {
|
||||
+ snapshotVersion + "\n" + CacheControl + "\n" + ContentDisposition + "\n" + ContentEncoding
|
||||
+ "\n" + ContentLanguage + "\n" + ContentType;
|
||||
|
||||
std::string signature = Base64Encode(Storage::Details::HmacSha256(
|
||||
std::string signature = Azure::Core::Base64Encode(Storage::Details::HmacSha256(
|
||||
std::vector<uint8_t>(stringToSign.begin(), stringToSign.end()),
|
||||
Base64Decode(credential.GetAccountKey())));
|
||||
Azure::Core::Base64Decode(credential.GetAccountKey())));
|
||||
|
||||
Azure::Core::Http::Url builder;
|
||||
builder.AppendQueryParameter(
|
||||
@ -241,9 +241,9 @@ namespace Azure { namespace Storage { namespace Sas {
|
||||
+ CacheControl + "\n" + ContentDisposition + "\n" + ContentEncoding + "\n" + ContentLanguage
|
||||
+ "\n" + ContentType;
|
||||
|
||||
std::string signature = Base64Encode(Storage::Details::HmacSha256(
|
||||
std::string signature = Azure::Core::Base64Encode(Storage::Details::HmacSha256(
|
||||
std::vector<uint8_t>(stringToSign.begin(), stringToSign.end()),
|
||||
Base64Decode(userDelegationKey.Value)));
|
||||
Azure::Core::Base64Decode(userDelegationKey.Value)));
|
||||
|
||||
Azure::Core::Http::Url builder;
|
||||
builder.AppendQueryParameter(
|
||||
|
||||
@ -139,7 +139,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
constexpr std::size_t BlockIdLength = 64;
|
||||
std::string blockId = std::to_string(id);
|
||||
blockId = std::string(BlockIdLength - blockId.length(), '0') + blockId;
|
||||
return Base64Encode(blockId);
|
||||
return Internal::Base64EncodeText(blockId);
|
||||
};
|
||||
|
||||
auto uploadBlockFunc = [&](int64_t offset, int64_t length, int64_t chunkId, int64_t numChunks) {
|
||||
@ -220,7 +220,7 @@ namespace Azure { namespace Storage { namespace Blobs {
|
||||
constexpr std::size_t BlockIdLength = 64;
|
||||
std::string blockId = std::to_string(id);
|
||||
blockId = std::string(BlockIdLength - blockId.length(), '0') + blockId;
|
||||
return Base64Encode(blockId);
|
||||
return Internal::Base64EncodeText(blockId);
|
||||
};
|
||||
|
||||
auto uploadBlockFunc = [&](int64_t offset, int64_t length, int64_t chunkId, int64_t numChunks) {
|
||||
|
||||
@ -523,7 +523,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
std::vector<uint8_t> aes256Key;
|
||||
aes256Key.resize(32);
|
||||
RandomBuffer(&aes256Key[0], aes256Key.size());
|
||||
key.Key = Base64Encode(aes256Key);
|
||||
key.Key = Azure::Core::Base64Encode(aes256Key);
|
||||
key.KeyHash = Details::Sha256(aes256Key);
|
||||
key.Algorithm = Blobs::Models::EncryptionAlgorithmType::Aes256;
|
||||
return key;
|
||||
@ -544,8 +544,8 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
auto blockBlob = containerClient.GetBlockBlobClient(blockBlobName);
|
||||
bodyStream.Rewind();
|
||||
EXPECT_NO_THROW(blockBlob.Upload(&bodyStream));
|
||||
std::string blockId1 = Base64Encode("1");
|
||||
std::string blockId2 = Base64Encode("2");
|
||||
std::string blockId1 = Internal::Base64EncodeText("1");
|
||||
std::string blockId2 = Internal::Base64EncodeText("2");
|
||||
bodyStream.Rewind();
|
||||
EXPECT_NO_THROW(blockBlob.StageBlock(blockId1, &bodyStream));
|
||||
EXPECT_NO_THROW(blockBlob.StageBlockFromUri(blockId2, copySourceBlob.GetUrl() + GetSas()));
|
||||
@ -1045,7 +1045,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
}
|
||||
|
||||
{
|
||||
std::string blockId = Base64Encode("1");
|
||||
std::string blockId = Internal::Base64EncodeText("1");
|
||||
std::vector<std::string> blockIds = {blockId};
|
||||
content.Rewind();
|
||||
blockBlobClient.StageBlock(blockId, &content);
|
||||
|
||||
@ -97,7 +97,8 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
std::vector<uint8_t>(
|
||||
m_blobContent.begin() + static_cast<std::size_t>(options.Range.GetValue().Offset),
|
||||
m_blobContent.begin()
|
||||
+ static_cast<std::size_t>(options.Range.GetValue().Offset + options.Range.GetValue().Length.GetValue())));
|
||||
+ static_cast<std::size_t>(
|
||||
options.Range.GetValue().Offset + options.Range.GetValue().Length.GetValue())));
|
||||
EXPECT_FALSE(res->ContentRange.GetValue().empty());
|
||||
}
|
||||
|
||||
@ -268,8 +269,8 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
|
||||
TEST_F(BlockBlobClientTest, StageBlock)
|
||||
{
|
||||
const std::string blockId1 = Azure::Storage::Base64Encode("0");
|
||||
const std::string blockId2 = Azure::Storage::Base64Encode("1");
|
||||
const std::string blockId1 = Azure::Storage::Internal::Base64EncodeText("0");
|
||||
const std::string blockId2 = Azure::Storage::Internal::Base64EncodeText("1");
|
||||
auto blockBlobClient = Azure::Storage::Blobs::BlockBlobClient::CreateFromConnectionString(
|
||||
StandardStorageConnectionString(), m_containerName, RandomString());
|
||||
std::vector<uint8_t> block1Content;
|
||||
|
||||
@ -227,7 +227,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
EXPECT_NO_THROW(pageBlobClient.UploadPages(0, &pageContent, options));
|
||||
|
||||
pageContent.Rewind();
|
||||
hash.Value = Base64Decode(DummyMd5);
|
||||
hash.Value = Azure::Core::Base64Decode(DummyMd5);
|
||||
options.TransactionalContentHash = hash;
|
||||
EXPECT_THROW(pageBlobClient.UploadPages(0, &pageContent, options), StorageException);
|
||||
}
|
||||
@ -251,7 +251,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
EXPECT_NO_THROW(pageBlobClient.UploadPages(0, &pageContent, options));
|
||||
|
||||
pageContent.Rewind();
|
||||
hash.Value = Base64Decode(DummyCrc64);
|
||||
hash.Value = Azure::Core::Base64Decode(DummyCrc64);
|
||||
options.TransactionalContentHash = hash;
|
||||
EXPECT_THROW(pageBlobClient.UploadPages(0, &pageContent, options), StorageException);
|
||||
}
|
||||
|
||||
@ -15,6 +15,8 @@
|
||||
- Move Account SAS into `Azure::Storage::Sas` namespace.
|
||||
- All date time related strings are now changed to `Azure::Core::DateTime` type.
|
||||
- Move version strings into `Details` namespace.
|
||||
- Move `Base64Encode` and `Base64Decode` from the `Azure::Storage` namespace to `Azure::Core`.
|
||||
- Rename the string accepting overload of `Base64Encode` to `Base64EncodeText` and make it internal by moving it to the `Azure::Storage::Internal` namespace.
|
||||
|
||||
## 12.0.0-beta.5 (2020-11-13)
|
||||
|
||||
|
||||
@ -7,14 +7,16 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <azure/core/base64.hpp>
|
||||
|
||||
namespace Azure { namespace Storage {
|
||||
|
||||
std::string Base64Encode(const std::vector<uint8_t>& data);
|
||||
inline std::string Base64Encode(const std::string& text)
|
||||
{
|
||||
return Base64Encode(std::vector<uint8_t>(text.begin(), text.end()));
|
||||
}
|
||||
std::vector<uint8_t> Base64Decode(const std::string& text);
|
||||
namespace Internal {
|
||||
inline std::string Base64EncodeText(const std::string& text)
|
||||
{
|
||||
return Azure::Core::Base64Encode(std::vector<uint8_t>(text.begin(), text.end()));
|
||||
}
|
||||
} // namespace Internal
|
||||
|
||||
class Md5 {
|
||||
public:
|
||||
|
||||
@ -102,9 +102,9 @@ namespace Azure { namespace Storage { namespace Sas {
|
||||
+ (IPRange.HasValue() ? IPRange.GetValue() : "") + "\n" + protocol + "\n"
|
||||
+ Storage::Details::DefaultSasVersion + "\n";
|
||||
|
||||
std::string signature = Base64Encode(Storage::Details::HmacSha256(
|
||||
std::string signature = Azure::Core::Base64Encode(Storage::Details::HmacSha256(
|
||||
std::vector<uint8_t>(stringToSign.begin(), stringToSign.end()),
|
||||
Base64Decode(credential.GetAccountKey())));
|
||||
Azure::Core::Base64Decode(credential.GetAccountKey())));
|
||||
|
||||
Azure::Core::Http::Url builder;
|
||||
builder.AppendQueryParameter(
|
||||
|
||||
@ -318,43 +318,6 @@ namespace Azure { namespace Storage {
|
||||
return hash;
|
||||
}
|
||||
|
||||
std::string Base64Encode(const std::vector<uint8_t>& data)
|
||||
{
|
||||
std::string encoded;
|
||||
// According to RFC 4648, the encoded length should be ceiling(n / 3) * 4
|
||||
DWORD encodedLength = static_cast<DWORD>((data.size() + 2) / 3 * 4);
|
||||
encoded.resize(encodedLength);
|
||||
|
||||
CryptBinaryToStringA(
|
||||
reinterpret_cast<const BYTE*>(data.data()),
|
||||
static_cast<DWORD>(data.size()),
|
||||
CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF,
|
||||
static_cast<LPSTR>(&encoded[0]),
|
||||
&encodedLength);
|
||||
|
||||
return encoded;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Base64Decode(const std::string& text)
|
||||
{
|
||||
std::vector<uint8_t> decoded;
|
||||
// According to RFC 4648, the encoded length should be ceiling(n / 3) * 4, so we can infer an
|
||||
// upper bound here
|
||||
DWORD decodedLength = DWORD(text.length() / 4 * 3);
|
||||
decoded.resize(decodedLength);
|
||||
|
||||
CryptStringToBinaryA(
|
||||
text.data(),
|
||||
static_cast<DWORD>(text.length()),
|
||||
CRYPT_STRING_BASE64 | CRYPT_STRING_STRICT,
|
||||
reinterpret_cast<BYTE*>(decoded.data()),
|
||||
&decodedLength,
|
||||
nullptr,
|
||||
nullptr);
|
||||
decoded.resize(decodedLength);
|
||||
return decoded;
|
||||
}
|
||||
|
||||
#elif defined(AZ_PLATFORM_POSIX)
|
||||
|
||||
namespace Details {
|
||||
@ -416,39 +379,6 @@ namespace Azure { namespace Storage {
|
||||
return std::vector<uint8_t>(std::begin(hash), std::end(hash));
|
||||
}
|
||||
|
||||
std::string Base64Encode(const std::vector<uint8_t>& data)
|
||||
{
|
||||
BIO* bio = BIO_new(BIO_s_mem());
|
||||
bio = BIO_push(BIO_new(BIO_f_base64()), bio);
|
||||
BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL);
|
||||
BIO_write(bio, data.data(), static_cast<int>(data.size()));
|
||||
BIO_flush(bio);
|
||||
BUF_MEM* bufferPtr;
|
||||
BIO_get_mem_ptr(bio, &bufferPtr);
|
||||
BIO_set_close(bio, BIO_NOCLOSE);
|
||||
BIO_free_all(bio);
|
||||
|
||||
return std::string(bufferPtr->data, bufferPtr->length);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Base64Decode(const std::string& text)
|
||||
{
|
||||
std::vector<uint8_t> decoded;
|
||||
// According to RFC 4648, the encoded length should be ceiling(n / 3) * 4, so we can infer an
|
||||
// upper bound here
|
||||
std::size_t maxDecodedLength = text.length() / 4 * 3;
|
||||
decoded.resize(maxDecodedLength);
|
||||
|
||||
BIO* bio = BIO_new_mem_buf(text.data(), -1);
|
||||
bio = BIO_push(BIO_new(BIO_f_base64()), bio);
|
||||
BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL);
|
||||
int decodedLength = BIO_read(bio, &decoded[0], static_cast<int>(text.length()));
|
||||
BIO_free_all(bio);
|
||||
|
||||
decoded.resize(decodedLength);
|
||||
return decoded;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static constexpr uint64_t Crc64Poly = 0x9A6C9329AC4BC9B5ULL;
|
||||
|
||||
@ -81,8 +81,8 @@ namespace Azure { namespace Storage { namespace Details {
|
||||
// remove last linebreak
|
||||
string_to_sign.pop_back();
|
||||
|
||||
return Base64Encode(Details::HmacSha256(
|
||||
return Azure::Core::Base64Encode(Details::HmacSha256(
|
||||
std::vector<uint8_t>(string_to_sign.begin(), string_to_sign.end()),
|
||||
Base64Decode(m_credential->GetAccountKey())));
|
||||
Azure::Core::Base64Decode(m_credential->GetAccountKey())));
|
||||
}
|
||||
}}} // namespace Azure::Storage::Details
|
||||
|
||||
@ -19,12 +19,15 @@ namespace Azure { namespace Storage {
|
||||
ContentHash FromBase64String(const std::string& base64String, HashAlgorithm algorithm)
|
||||
{
|
||||
ContentHash hash;
|
||||
hash.Value = Base64Decode(base64String);
|
||||
hash.Value = Azure::Core::Base64Decode(base64String);
|
||||
hash.Algorithm = algorithm;
|
||||
return hash;
|
||||
}
|
||||
|
||||
std::string ToBase64String(const ContentHash& hash) { return Base64Encode(hash.Value); }
|
||||
std::string ToBase64String(const ContentHash& hash)
|
||||
{
|
||||
return Azure::Core::Base64Encode(hash.Value);
|
||||
}
|
||||
} // namespace Details
|
||||
|
||||
}} // namespace Azure::Storage
|
||||
|
||||
@ -15,24 +15,13 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
return std::vector<uint8_t>(start, start + strlen(text));
|
||||
}
|
||||
|
||||
TEST(CryptFunctionsTest, Base64)
|
||||
{
|
||||
for (std::size_t len : {0, 10, 100, 1000, 10000})
|
||||
{
|
||||
std::vector<uint8_t> data;
|
||||
data.resize(len);
|
||||
RandomBuffer(data.data(), data.size());
|
||||
EXPECT_EQ(Base64Decode(Base64Encode(data)), data);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(CryptFunctionsTest, Sha256)
|
||||
{
|
||||
EXPECT_EQ(
|
||||
Base64Encode(Details::Sha256(ToBinaryVector(""))),
|
||||
Azure::Core::Base64Encode(Details::Sha256(ToBinaryVector(""))),
|
||||
"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=");
|
||||
EXPECT_EQ(
|
||||
Base64Encode(Details::Sha256(ToBinaryVector("Hello Azure!"))),
|
||||
Azure::Core::Base64Encode(Details::Sha256(ToBinaryVector("Hello Azure!"))),
|
||||
"Mjzwx2mqGHb9FSgjm33ShNmXYndkgvwA6tQmEiskOHg=");
|
||||
}
|
||||
|
||||
@ -41,17 +30,17 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
std::string key = "8CwtGFF1mGR4bPEP9eZ0x1fxKiQ3Ca5N";
|
||||
std::vector<uint8_t> binaryKey(key.begin(), key.end());
|
||||
EXPECT_EQ(
|
||||
Base64Encode(Details::HmacSha256(ToBinaryVector(""), binaryKey)),
|
||||
Azure::Core::Base64Encode(Details::HmacSha256(ToBinaryVector(""), binaryKey)),
|
||||
"fFy2T+EuCvAgouw/vB/RAJ75z7jwTj+uiURebkFKF5M=");
|
||||
EXPECT_EQ(
|
||||
Base64Encode(Details::HmacSha256(ToBinaryVector("Hello Azure!"), binaryKey)),
|
||||
Azure::Core::Base64Encode(Details::HmacSha256(ToBinaryVector("Hello Azure!"), binaryKey)),
|
||||
"+SBESxQVhI53mSEdZJcCBpdBkaqwzfPaVYZMAf5LP3c=");
|
||||
}
|
||||
|
||||
TEST(CryptFunctionsTest, Md5)
|
||||
{
|
||||
EXPECT_EQ(Base64Encode(Md5::Hash("")), "1B2M2Y8AsgTpgAmY7PhCfg==");
|
||||
EXPECT_EQ(Base64Encode(Md5::Hash("Hello Azure!")), "Pz8543xut4RVSbb2g52Mww==");
|
||||
EXPECT_EQ(Azure::Core::Base64Encode(Md5::Hash("")), "1B2M2Y8AsgTpgAmY7PhCfg==");
|
||||
EXPECT_EQ(Azure::Core::Base64Encode(Md5::Hash("Hello Azure!")), "Pz8543xut4RVSbb2g52Mww==");
|
||||
|
||||
auto data = RandomBuffer(static_cast<std::size_t>(16_MB));
|
||||
Md5 md5Instance;
|
||||
@ -70,8 +59,8 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
|
||||
TEST(CryptFunctionsTest, Crc64)
|
||||
{
|
||||
EXPECT_EQ(Base64Encode(Crc64::Hash("")), "AAAAAAAAAAA=");
|
||||
EXPECT_EQ(Base64Encode(Crc64::Hash("Hello Azure!")), "DtjZpL9/o8c=");
|
||||
EXPECT_EQ(Azure::Core::Base64Encode(Crc64::Hash("")), "AAAAAAAAAAA=");
|
||||
EXPECT_EQ(Azure::Core::Base64Encode(Crc64::Hash("Hello Azure!")), "DtjZpL9/o8c=");
|
||||
|
||||
auto data = RandomBuffer(static_cast<std::size_t>(16_MB));
|
||||
Crc64 crc64Instance;
|
||||
|
||||
@ -136,9 +136,9 @@ namespace Azure { namespace Storage { namespace Sas {
|
||||
+ "\n" + CacheControl + "\n" + ContentDisposition + "\n" + ContentEncoding + "\n"
|
||||
+ ContentLanguage + "\n" + ContentType;
|
||||
|
||||
std::string signature = Base64Encode(Storage::Details::HmacSha256(
|
||||
std::string signature = Azure::Core::Base64Encode(Storage::Details::HmacSha256(
|
||||
std::vector<uint8_t>(stringToSign.begin(), stringToSign.end()),
|
||||
Base64Decode(credential.GetAccountKey())));
|
||||
Azure::Core::Base64Decode(credential.GetAccountKey())));
|
||||
|
||||
Azure::Core::Http::Url builder;
|
||||
builder.AppendQueryParameter(
|
||||
@ -225,9 +225,9 @@ namespace Azure { namespace Storage { namespace Sas {
|
||||
+ Storage::Details::DefaultSasVersion + "\n" + resource + "\n" + "\n" + CacheControl + "\n"
|
||||
+ ContentDisposition + "\n" + ContentEncoding + "\n" + ContentLanguage + "\n" + ContentType;
|
||||
|
||||
std::string signature = Base64Encode(Storage::Details::HmacSha256(
|
||||
std::string signature = Azure::Core::Base64Encode(Storage::Details::HmacSha256(
|
||||
std::vector<uint8_t>(stringToSign.begin(), stringToSign.end()),
|
||||
Base64Decode(userDelegationKey.Value)));
|
||||
Azure::Core::Base64Decode(userDelegationKey.Value)));
|
||||
|
||||
Azure::Core::Http::Url builder;
|
||||
builder.AppendQueryParameter(
|
||||
|
||||
@ -39,7 +39,7 @@ namespace Azure { namespace Storage { namespace Files { namespace DataLake { nam
|
||||
std::string result;
|
||||
for (const auto& pair : dataLakePropertiesMap)
|
||||
{
|
||||
result.append(pair.first + "=" + Base64Encode(pair.second) + ",");
|
||||
result.append(pair.first + "=" + Internal::Base64EncodeText(pair.second) + ",");
|
||||
}
|
||||
if (!result.empty())
|
||||
{
|
||||
|
||||
@ -96,9 +96,9 @@ namespace Azure { namespace Storage { namespace Sas {
|
||||
+ "\n" + protocol + "\n" + Storage::Details::DefaultSasVersion + "\n" + CacheControl + "\n"
|
||||
+ ContentDisposition + "\n" + ContentEncoding + "\n" + ContentLanguage + "\n" + ContentType;
|
||||
|
||||
std::string signature = Base64Encode(Storage::Details::HmacSha256(
|
||||
std::string signature = Azure::Core::Base64Encode(Storage::Details::HmacSha256(
|
||||
std::vector<uint8_t>(stringToSign.begin(), stringToSign.end()),
|
||||
Base64Decode(credential.GetAccountKey())));
|
||||
Azure::Core::Base64Decode(credential.GetAccountKey())));
|
||||
|
||||
Azure::Core::Http::Url builder;
|
||||
builder.AppendQueryParameter(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user