diff --git a/sdk/core/azure-core/inc/http/policy.hpp b/sdk/core/azure-core/inc/http/policy.hpp index 10d1280b9..c6d1f95aa 100644 --- a/sdk/core/azure-core/inc/http/policy.hpp +++ b/sdk/core/azure-core/inc/http/policy.hpp @@ -123,7 +123,7 @@ namespace Azure { namespace Core { namespace Http { Request& request, NextHttpPolicy nextHttpPolicy) const override { - auto uuid = UUID::CreateUUID().GetUUIDString(); + auto uuid = Uuid::CreateUuid().GetUuidString(); request.AddHeader(RequestIdHeader, uuid); return nextHttpPolicy.Send(ctx, request); diff --git a/sdk/core/azure-core/inc/uuid.hpp b/sdk/core/azure-core/inc/uuid.hpp index 7988814d3..848e7ec50 100644 --- a/sdk/core/azure-core/inc/uuid.hpp +++ b/sdk/core/azure-core/inc/uuid.hpp @@ -3,6 +3,7 @@ #pragma once +#include #include // for placement new #include #include @@ -10,12 +11,12 @@ namespace Azure { namespace Core { - class UUID { + class Uuid { private: - static const int UUIDSize = 16; + static const int UuidSize = 16; - uint8_t m_uuid[UUIDSize]; + uint8_t m_uuid[UuidSize]; // The UUID reserved variants. static constexpr uint8_t ReservedNCS = 0x80; static constexpr uint8_t ReservedRFC4122 = 0x40; @@ -23,14 +24,14 @@ namespace Azure { namespace Core { static constexpr uint8_t ReservedFuture = 0x00; private: - UUID(uint8_t const uuid[UUIDSize]) - { - memcpy(m_uuid, uuid, UUIDSize); + Uuid(uint8_t const uuid[UuidSize]) + { + std::memcpy(m_uuid, uuid, UuidSize); } public: - std::string GetUUIDString() + std::string GetUuidString() { // Guid is 36 characters // Add one byte for the \0 @@ -60,13 +61,13 @@ namespace Azure { namespace Core { return std::string(s); } - static UUID CreateUUID() { + static Uuid CreateUuid() { std::random_device rd; std::mt19937 gen(rd()); - uint8_t uuid[UUIDSize] = {}; + uint8_t uuid[UuidSize] = {}; - for (int i = 0; i < UUIDSize; i += 4) + for (int i = 0; i < UuidSize; i += 4) *reinterpret_cast(uuid + i) = gen(); // SetVariant to ReservedRFC4122 @@ -76,7 +77,7 @@ namespace Azure { namespace Core { uuid[6] = (uuid[6] & 0xF) | (version << 4); - return UUID(uuid); + return Uuid(uuid); } }; }} // namespace Azure::Core diff --git a/sdk/storage/src/common/storage_common.cpp b/sdk/storage/src/common/storage_common.cpp index aba978dba..4d9aac614 100644 --- a/sdk/storage/src/common/storage_common.cpp +++ b/sdk/storage/src/common/storage_common.cpp @@ -3,33 +3,14 @@ #include "common/storage_common.hpp" -#include +#include namespace Azure { namespace Storage { std::string CreateUniqueLeaseId() { - // TODO: return UUID provided by Azure Core once they provide one. - - static thread_local std::mt19937_64 random_generator(std::random_device{}()); - - auto getRandomChar = []() { - const char charset[] = "0123456789abcdef"; - std::uniform_int_distribution distribution(0, sizeof(charset) - 2); - return charset[distribution(random_generator)]; - }; - - std::string result; - result.reserve(37); - for (int i : {8, 4, 4, 4, 12}) - { - for (int j = 0; j < i; ++j) - result += getRandomChar(); - result += '-'; - } - result.pop_back(); - - return result; + auto uuid = Azure::Core::Uuid::CreateUuid(); + return uuid.GetUuidString(); } }} // namespace Azure::Storage