8 #include "mbedtls/md5.h"
23 switch (a_StringUUID.size())
28 std::memcpy(UUID.
Data, a_StringUUID.data(), 32);
36 (a_StringUUID[ 8] !=
'-') ||
37 (a_StringUUID[13] !=
'-') ||
38 (a_StringUUID[18] !=
'-') ||
39 (a_StringUUID[23] !=
'-')
46 std::memcpy(UUID.
Data, a_StringUUID.data(), 8);
47 std::memcpy(UUID.
Data + 8, a_StringUUID.data() + 9, 4);
48 std::memcpy(UUID.
Data + 12, a_StringUUID.data() + 14, 4);
49 std::memcpy(UUID.
Data + 16, a_StringUUID.data() + 19, 4);
50 std::memcpy(UUID.
Data + 20, a_StringUUID.data() + 24, 12);
65 if ((
'0' <= a_Hex) && (a_Hex <=
'9'))
67 return static_cast<Byte>(a_Hex -
'0');
69 if ((
'a' <= a_Hex) && (a_Hex <=
'f'))
71 return static_cast<Byte>(10 + (a_Hex -
'a'));
73 if ((
'A' <= a_Hex) && (a_Hex <=
'F'))
75 return static_cast<Byte>(10 + (a_Hex -
'A'));
87 ASSERT((a_Nibble & 0xf0) == 0);
88 return static_cast<char>(
91 (
'a' + (a_Nibble - 10))
110 std::array<Byte, 16> ParsedUUID{{0}};
111 for (
size_t i = 0; i !=
m_UUID.size(); ++i)
115 if ((HighNibble > 0x0f) || (LowNibble > 0x0f))
121 ParsedUUID[i] =
static_cast<Byte>((HighNibble << 4) | LowNibble);
136 for (
size_t i = 0; i !=
m_UUID.size(); ++i)
142 ShortString[2 * i + 1] =
ToHexDigit(LowNibble);
154 LongString.reserve(36);
157 auto First = LongString.begin();
158 LongString.insert(First + 8,
'-');
159 LongString.insert(First + 13,
'-');
160 LongString.insert(First + 18,
'-');
161 LongString.insert(First + 23,
'-');
172 return static_cast<UInt8>((
m_UUID[6] >> 4) & 0x0f);
181 const Byte VariantBits =
static_cast<Byte>((
m_UUID[8] >> 5) & 0x07);
192 if ((VariantBits & 0x04) == 0)
196 else if ((VariantBits & 0x02) == 0)
200 else if ((VariantBits & 0x01) == 0)
216 std::array<Byte, 16> Raw(
m_UUID);
221 auto First =
reinterpret_cast<UInt32 *
>(Raw.data());
222 *First = ntohl(*First);
224 auto Second =
reinterpret_cast<UInt16 *
>(&Raw[4]);
225 *Second = ntohs(*Second);
227 auto Third = Second + 1;
228 *Third = ntohs(*Third);
250 *First = htonl(*First);
253 *Second = htons(*Second);
255 auto Third = Second + 1;
256 *Third = htons(*Third);
267 const Byte * ByteString =
reinterpret_cast<const Byte *
>(a_Name.data());
268 mbedtls_md5(ByteString, a_Name.length(), UUID.
m_UUID.data());
static sShortUUID ShortenUUID(const AString &a_StringUUID)
Returns the given UUID in shortened form with IsValid indicating success.
static char ToHexDigit(UInt8 a_Nibble)
From a number in the range [0, 16), returns the corresponding hex digit in lowercase.
static Byte FromHexDigit(char a_Hex)
Returns the integer value of the hex digit or 0xff if invalid.
UUID normalised in textual form.
AString ToShortString() const
Converts the UUID to a short form string (i.e without dashes).
bool FromString(const AString &a_StringUUID)
Tries to interpret the string as a short or long form UUID and assign from it.
static cUUID GenerateVersion3(const AString &a_Name)
Generates a version 3, variant 1 UUID based on the md5 hash of a_Name.
std::array< Byte, 16 > m_UUID
Binary UUID stored big-endian.
UInt8 Variant() const
Returns the variant number of the UUID.
UInt8 Version() const
Returns the version number of the UUID.
AString ToLongString() const
Converts the UUID to a long form string (i.e.
void FromRaw(const std::array< Byte, 16 > &a_Raw)
Assigns from raw memory representation, respecting UUID variant.
std::array< Byte, 16 > ToRaw() const
Converts UUID to raw memory representation, respecting UUID variant.