Botan  2.4.0
Crypto and TLS for C++11
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
 
bool operator== (const UUID &other) const
 
std::string to_string () const
 
 UUID ()
 
 UUID (RandomNumberGenerator &rng)
 
 UUID (const std::vector< uint8_t > &blob)
 
 UUID (const std::string &uuid_str)
 

Detailed Description

Definition at line 18 of file uuid.h.

Constructor & Destructor Documentation

◆ UUID() [1/4]

Botan::UUID::UUID ( )
inline

Definition at line 22 of file uuid.h.

22 : m_uuid(0) {}

◆ UUID() [2/4]

Botan::UUID::UUID ( RandomNumberGenerator rng)
inline

Definition at line 24 of file uuid.h.

References Botan::RandomNumberGenerator::randomize().

25  {
26  m_uuid.resize(16);
27  rng.randomize(m_uuid.data(), m_uuid.size());
28 
29  // Mark as a random UUID (RFC 4122 sec 4.4)
30  m_uuid[6] = 0x40 | (m_uuid[6] & 0x0F);
31 
32  // Set two reserved bits
33  m_uuid[8] = 0xC0 | (m_uuid[8] & 0x3F);
34  }

◆ UUID() [3/4]

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

Definition at line 36 of file uuid.h.

References Botan::hex_encode().

37  {
38  if(blob.size() != 16)
39  {
40  throw Invalid_Argument("Bad UUID blob " + hex_encode(blob));
41  }
42 
43  m_uuid = blob;
44  }
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
Definition: hex.cpp:14

◆ UUID() [4/4]

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

Definition at line 46 of file uuid.h.

References Botan::hex_decode().

47  {
48  if(uuid_str.size() != 36 ||
49  uuid_str[8] != '-' ||
50  uuid_str[14] != '-' ||
51  uuid_str[19] != '-' ||
52  uuid_str[24] != '-')
53  {
54  throw Invalid_Argument("Bad UUID '" + uuid_str + "'");
55  }
56 
57  std::string just_hex;
58  for(size_t i = 0; i != uuid_str.size(); ++i)
59  {
60  char c = uuid_str[i];
61 
62  if(c == '-')
63  continue;
64 
65  just_hex += c;
66  }
67 
68  m_uuid = hex_decode(just_hex);
69 
70  if(m_uuid.size() != 16)
71  {
72  throw Invalid_Argument("Bad UUID '" + uuid_str + "'");
73  }
74  }
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

◆ binary_value()

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

Definition at line 89 of file uuid.h.

89 { return m_uuid; }

◆ is_valid()

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

Definition at line 98 of file uuid.h.

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

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

◆ operator!=()

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

Definition at line 96 of file uuid.h.

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

◆ operator==()

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

Definition at line 91 of file uuid.h.

92  {
93  return m_uuid == other.m_uuid;
94  }

◆ to_string()

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

Definition at line 77 of file uuid.h.

References Botan::hex_encode().

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

78  {
79  std::string h = hex_encode(m_uuid);
80 
81  h.insert(8, "-");
82  h.insert(14, "-");
83  h.insert(19, "-");
84  h.insert(24, "-");
85 
86  return h;
87  }
void hex_encode(char output[], const uint8_t input[], size_t input_length, bool uppercase)
Definition: hex.cpp:14

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