Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
Botan::UUID Class Referencefinal

`#include <uuid.h>`

## Public Member Functions
const std::vector< uint8_t > & | binary_value () const
bool | is_valid () const
bool | operator!= (const UUID &other) const
UUID & | operator= (const UUID &other)=default
bool | operator== (const UUID &other) const
std::string | to_string () const
| UUID ()
| UUID (RandomNumberGenerator &rng)
| UUID (const std::vector< uint8_t > &blob)
| UUID (const UUID &other)=default
| UUID (const std::string &uuid_str)

## Detailed Description

Definition at line 21 of file uuid.h.

## Constructor & Destructor Documentation

Botan::UUID::UUID | ( |  | ) |
| inline

Create an uninitialized UUID object

Definition at line 27 of file uuid.h.

27 : m_uuid() {}

Botan::UUID::UUID | ( | RandomNumberGenerator & | rng | ) |

Create a random UUID

Definition at line 15 of file uuid.cpp.

References Botan::RandomNumberGenerator::randomize().

16 {
17 m_uuid.resize(16);
18 rng.randomize(m_uuid.data(), m_uuid.size());
19
20 // Mark as a random v4 UUID (RFC 4122 sec 4.4)
21 m_uuid[6] = 0x40 | (m_uuid[6] & 0x0F);
22
23 // Set reserved bits
24 m_uuid[8] = 0x80 | (m_uuid[8] & 0x3F);
25 }

Botan::UUID::UUID | ( | const std::vector< uint8_t > & | blob | ) |

Load a UUID from a 16 byte vector

Definition at line 27 of file uuid.cpp.

References Botan::hex_encode().

28 {
29 if(blob.size() != 16)
30 {
31 throw Invalid_Argument("Bad UUID blob " + hex_encode(blob));
32 }
33
34 m_uuid = blob;
35 }
Botan::hex_encode
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
Definition: hex.cpp:14

Botan::UUID::UUID | ( | const UUID & | other | ) |
| default

Botan::UUID::UUID | ( | const std::string & | uuid_str | ) |

Decode a UUID string

Definition at line 37 of file uuid.cpp.

References Botan::hex_decode().

38 {
39 if(uuid_str.size() != 36 ||
40 uuid_str[8] != '-' ||
41 uuid_str[13] != '-' ||
42 uuid_str[18] != '-' ||
43 uuid_str[23] != '-')
44 {
45 throw Invalid_Argument("Bad UUID '" + uuid_str + "'");
46 }
47
48 std::string just_hex;
49 for(size_t i = 0; i != uuid_str.size(); ++i)
50 {
51 char c = uuid_str[i];
52
53 if(c == '-')
54 continue;
55
56 just_hex += c;
57 }
58
59 m_uuid = hex_decode(just_hex);
60
61 if(m_uuid.size() != 16)
62 {
63 throw Invalid_Argument("Bad UUID '" + uuid_str + "'");
64 }
65 }
Botan::hex_decode
size_t hex_decode(uint8_t output[], const char input[], size_t input_length, size_t &input_consumed, bool ignore_ws)
Definition: hex.cpp:49

## Member Function Documentation

const std::vector<uint8_t>& Botan::UUID::binary_value | ( |  | ) | const
| inline

Definition at line 52 of file uuid.h.

52 { return m_uuid; }

bool Botan::UUID::is_valid | ( |  | ) | const
| inline

Definition at line 61 of file uuid.h.

Referenced by Botan::TPM_PrivateKey::register_key(), and to_string().

61 { return m_uuid.size() == 16; }

bool Botan::UUID::operator!= | ( | const UUID & | other | ) | const
| inline

Definition at line 59 of file uuid.h.

59 { return !(*this == other); }

UUID& Botan::UUID::operator= | ( | const UUID & | other | ) |
| default

bool Botan::UUID::operator== | ( | const UUID & | other | ) | const
| inline

Definition at line 54 of file uuid.h.

55 {
56 return m_uuid == other.m_uuid;
57 }

std::string Botan::UUID::to_string | ( |  | ) | const

Convert the UUID to a string

Definition at line 67 of file uuid.cpp.

References Botan::hex_encode(), and is_valid().

Referenced by Botan::TPM_PrivateKey::register_key().

68 {
69 if(is_valid() == false)
70 throw Invalid_State("UUID object is empty cannot convert to string");
71
72 std::string h = hex_encode(m_uuid);
73
74 h.insert(8, "-");
75 h.insert(13, "-");
76 h.insert(18, "-");
77 h.insert(23, "-");
78
79 return h;
80 }
Botan::hex_encode
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
Definition: hex.cpp:14
Botan::UUID::is_valid
bool is_valid() const
Definition: uuid.h:61

The documentation for this class was generated from the following files:

- src/lib/utils/uuid/uuid.h
- src/lib/utils/uuid/uuid.cpp