Botan 3.13.0
Crypto and TLS for C&
uuid.h
Go to the documentation of this file.
1/*
2* UUID type
3* (C) 2015,2018 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_UUID_H_
9#define BOTAN_UUID_H_
10
11#include <botan/types.h>
12#include <string>
13#include <vector>
14
16
17namespace Botan {
18
19class RandomNumberGenerator;
20
21/**
22* A universally unique identifier (UUID)
23*/
25 public:
26 /**
27 * Create an uninitialized UUID object
28 */
29 UUID() = default;
30
31 /**
32 * Create a random UUID
33 */
35
36 /**
37 * Load a UUID from a 16 byte vector
38 */
39 BOTAN_FUTURE_EXPLICIT UUID(const std::vector<uint8_t>& blob);
40
41 /**
42 * Decode a UUID string
43 */
44 BOTAN_FUTURE_EXPLICIT UUID(std::string_view uuid_str);
45
46 /**
47 * Convert the UUID to a string
48 */
49 std::string to_string() const;
50
51 /**
52 * Access the raw bytes of the UUID
53 * @return the 16 byte binary value, or an empty vector if uninitialized
54 */
55 const std::vector<uint8_t>& binary_value() const { return m_uuid; }
56
57 /**
58 * Compare two UUIDs for equality
59 * @param other the UUID to compare against
60 * @return true if the two UUIDs are equal
61 */
62 bool operator==(const UUID& other) const { return m_uuid == other.m_uuid; }
63
64 /**
65 * Compare two UUIDs for inequality
66 * @param other the UUID to compare against
67 * @return true if the two UUIDs are not equal
68 */
69 bool operator!=(const UUID& other) const { return !(*this == other); }
70
71 /**
72 * Test whether this UUID was initialized
73 * @return true if this object holds a 16 byte UUID
74 */
75 bool is_valid() const { return m_uuid.size() == 16; }
76
77 private:
78 std::vector<uint8_t> m_uuid;
79};
80
81} // namespace Botan
82
83#endif
#define BOTAN_DEPRECATED_HEADER(hdr)
Definition api.h:100
#define BOTAN_UNSTABLE_API
Definition api.h:34
#define BOTAN_FUTURE_EXPLICIT
Definition api.h:52
bool operator!=(const UUID &other) const
Definition uuid.h:69
bool is_valid() const
Definition uuid.h:75
const std::vector< uint8_t > & binary_value() const
Definition uuid.h:55
std::string to_string() const
Definition uuid.cpp:59
bool operator==(const UUID &other) const
Definition uuid.h:62
UUID()=default