aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils/uuid/uuid.h
blob: 8f95f4d672edb81240e34addddea4791b6496b6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* UUID type
* (C) 2015,2018 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/

#ifndef BOTAN_UUID_H_
#define BOTAN_UUID_H_

#include <botan/types.h>
#include <vector>
#include <string>

BOTAN_FUTURE_INTERNAL_HEADER(uuid.h)

namespace Botan {

class RandomNumberGenerator;

class BOTAN_UNSTABLE_API UUID final
   {
   public:
      /**
      * Create an uninitialized UUID object
      */
      UUID() : m_uuid() {}

      /**
      * Create a random UUID
      */
      UUID(RandomNumberGenerator& rng);

      /**
      * Load a UUID from a 16 byte vector
      */
      UUID(const std::vector<uint8_t>& blob);

      UUID& operator=(const UUID& other) = default;
      UUID(const UUID& other) = default;

      /**
      * Decode a UUID string
      */
      UUID(const std::string& uuid_str);

      /**
      * Convert the UUID to a string
      */
      std::string to_string() const;

      const std::vector<uint8_t>& binary_value() const { return m_uuid; }

      bool operator==(const UUID& other) const
         {
         return m_uuid == other.m_uuid;
         }

      bool operator!=(const UUID& other) const { return !(*this == other); }

      bool is_valid() const { return m_uuid.size() == 16; }

   private:
      std::vector<uint8_t> m_uuid;
   };

}

#endif