UUID generator and parser.
More...
#include <uuid.hpp>
UUID generator and parser.
See RFC 4122 for more details (http://www.ietf.org/rfc/rfc4122.txt)
This class needs anch-crypto and anch-device libraries.
- Since
- 0.1
- Author
- Vincent Lachenal
◆ Version
The UUID versions
- Since
- 0.1
- Author
- Vincent Lachenal
| Enumerator |
|---|
| NOT_SET | Undefined
|
| MAC_ADDRESS | MAC address based algorithm
|
| DCE_SECURITY | DCE security (Windows) base algorithm
|
| MD5_HASH | MD5 hash based algorithm
|
| RANDOM | Random based algorithm
|
| SHA1_HASH | SHA1 hash based algorithm
|
| MAC_ADDRESS_R | MAC address based algorithm ; all time bits are in reserve order compared to MAC_ADDRESS
|
| RANDOM_TIME | Random and time based algorithm
|
| EXP | Random and time based algorithm
|
◆ UUID() [1/5]
UUID default constructor: nil UUID ( 00000000-0000-0000-0000-000000000000 )
◆ UUID() [2/5]
| anch::UUID::UUID |
( |
const UUID & | uuid | ) |
|
|
default |
UUID copy constructor
- Parameters
-
◆ UUID() [3/5]
| anch::UUID::UUID |
( |
UUID && | uuid | ) |
|
|
default |
UUID move constructor
- Parameters
-
◆ UUID() [4/5]
| anch::UUID::UUID |
( |
const std::string & | uuid | ) |
|
UUID from std::string constructor
- Parameters
-
| uuid | the std::string to parse |
- Exceptions
-
| std::invalid_argument | invalid UUID: length is not 36, '-' is not at positions 8, 13, 18 and 23, or other characters are not hexadecimal digits |
◆ UUID() [5/5]
| anch::UUID::UUID |
( |
uint32_t | lowTime, |
|
|
uint16_t | midTime, |
|
|
uint16_t | highTime, |
|
|
uint16_t | clockSeqLow, |
|
|
uint16_t | clockSeqHighRes, |
|
|
uint64_t | node, |
|
|
UUID::Version | version ) |
UUID constructor.
Each part is truncated to its width (32 bits for lowTime , 16 for midTime , 12 for highTime , 8 for clockSeqLow and clockSeqHighRes , 48 for node and 4 for version ).
- Parameters
-
| lowTime | the low time part |
| midTime | the mid time part |
| highTime | the high time part |
| clockSeqLow | the clock sequence low part |
| clockSeqHighRes | the clock sequence high resolution part |
| node | the node part |
| version | the UUID version |
◆ ~UUID()
UUID destructor (not virtual: UUID is a value type)
◆ fromBytes()
| UUID anch::UUID::fromBytes |
( |
const std::array< uint8_t, 16 > & | bytes | ) |
|
|
static |
Build UUID from its 16 bytes binary representation (RFC 9562, big-endian).
Version is read from the 4 high bits of byte 6 ; bytes are not checked (variant is not forced).
- Parameters
-
- Returns
- the UUID
◆ generateUUID() [1/2]
Generate a new UUID
- Parameters
-
| version | The UUID algorithm version to use (default to MAC based algorithm) |
| data | The data to process (used to SHA1 and MD5 algorithms) |
- Returns
- the new UUID
- Exceptions
-
| std::runtime_error | no provider for specified UUID version |
◆ generateUUID() [2/2]
Generate a new name based UUID (version 3 or 5) according to RFC 9562: the provider hashes the namespace UUID (16 bytes, see toBytes) followed by the name.
For other versions, namespace and name are given to the provider in the same way (random providers ignore them).
- Parameters
-
| version | The UUID algorithm version to use (MD5_HASH or SHA1_HASH) |
| nameSpace | the namespace (for example namespaceDNS ) |
| name | the name in the namespace |
- Returns
- the new UUID
- Exceptions
-
| std::runtime_error | no provider for specified UUID version |
◆ getClockSeqHighRes()
| uint16_t anch::UUID::getClockSeqHighRes |
( |
| ) |
const |
The clock sequence high value and reserved value getter
- Returns
- The clock sequence high value and reserved value
◆ getClockSeqLow()
| uint16_t anch::UUID::getClockSeqLow |
( |
| ) |
const |
The clock sequence low value getter
- Returns
- The clock sequence low value
◆ getHighTime()
| uint16_t anch::UUID::getHighTime |
( |
| ) |
const |
The timestamp high value getter
- Returns
- The timestamp high value
◆ getLowTime()
| uint32_t anch::UUID::getLowTime |
( |
| ) |
const |
The timestamp low value getter
- Returns
- The timestamp low value
◆ getMidTime()
| uint16_t anch::UUID::getMidTime |
( |
| ) |
const |
The timestamp mid value getter
- Returns
- The timestamp mid value
◆ getNode()
| uint64_t anch::UUID::getNode |
( |
| ) |
const |
The node getter
- Returns
- The node
◆ getUtcTimestamp()
| uint64_t anch::UUID::getUtcTimestamp |
( |
| ) |
|
|
static |
Get UUID version 1 / 6 timestamp: number of 100 ns intervals since 1582-10-15 00:00:00 UTC (Gregorian calendar reform, RFC 9562), from system clock
- Returns
- The timestamp
◆ getVersion()
◆ namespaceDNS()
| const UUID & anch::UUID::namespaceDNS |
( |
| ) |
|
|
static |
DNS namespace (6ba7b810-9dad-11d1-80b4-00c04fd430c8 ) for name based UUID (RFC 9562)
- Returns
- the namespace
◆ namespaceOID()
| const UUID & anch::UUID::namespaceOID |
( |
| ) |
|
|
static |
ISO OID namespace (6ba7b812-9dad-11d1-80b4-00c04fd430c8 ) for name based UUID (RFC 9562)
- Returns
- the namespace
◆ namespaceURL()
| const UUID & anch::UUID::namespaceURL |
( |
| ) |
|
|
static |
URL namespace (6ba7b811-9dad-11d1-80b4-00c04fd430c8 ) for name based UUID (RFC 9562)
- Returns
- the namespace
◆ namespaceX500()
| const UUID & anch::UUID::namespaceX500 |
( |
| ) |
|
|
static |
X.500 DN namespace (6ba7b814-9dad-11d1-80b4-00c04fd430c8 ) for name based UUID (RFC 9562)
- Returns
- the namespace
◆ operator std::string()
| anch::UUID::operator std::string |
( |
| ) |
const |
|
explicit |
◆ operator<=>()
| std::strong_ordering anch::UUID::operator<=> |
( |
const UUID & | uuid | ) |
const |
|
default |
Three-way comparison: binary order (RFC 9562), which is also string representation order.
== , != , < , <= , > and >= are generated from it.
- Parameters
-
| uuid | the UUID to compare with |
- Returns
- the comparison result
◆ operator=() [1/2]
| UUID & anch::UUID::operator= |
( |
const UUID & | uuid | ) |
|
|
default |
= operator definition
- Parameters
-
- Returns
this
◆ operator=() [2/2]
| UUID & anch::UUID::operator= |
( |
UUID && | uuid | ) |
|
|
default |
Move = operator definition
- Parameters
-
- Returns
this
◆ operator==()
| bool anch::UUID::operator== |
( |
const UUID & | uuid | ) |
const |
|
default |
== operator definition
- Parameters
-
| uuid | the UUID to compare with |
- Returns
true when the two UUID are equals, false otherwise
◆ parse()
| void anch::UUID::parse |
( |
const std::string & | uuid | ) |
|
Parse UUID for this value (usefull with default constructor).
Uppercase and lowercase hexadecimal digits are accepted. The value is not modified when uuid is invalid.
- Parameters
-
- Exceptions
-
| std::invalid_argument | invalid UUID: length is not 36, '-' is not at positions 8, 13, 18 and 23, or other characters are not hexadecimal digits |
◆ parseUUID()
| UUID anch::UUID::parseUUID |
( |
const std::string & | uuid | ) |
|
|
static |
Parse UUID
- Parameters
-
- Returns
- the parsed UUID
- Exceptions
-
| std::invalid_argument | invalid UUID: length is not 36, '-' is not at positions 8, 13, 18 and 23, or other characters are not hexadecimal digits |
◆ random()
| UUID anch::UUID::random |
( |
| ) |
|
|
static |
Generate a new UUID with version 4 (random) algorithm
- Returns
- the new UUID
◆ randomTime()
| UUID anch::UUID::randomTime |
( |
| ) |
|
|
static |
Generate a new UUID with version 7 (random + time) algorithm.
A 16 bits counter (RFC 9562 section 6.2, method 1) is written in the 12 rand_a bits and in the 4 first rand_b bits: UUID generated by this process are strictly increasing (string and binary order), including between threads. It is initialized randomly on each new millisecond (at least 32768 UUID per millisecond before timestamp is incremented). The 58 last bits are random.
- Returns
- the new UUID
◆ registerProvider()
| void anch::UUID::registerProvider |
( |
UUID::Version | version, |
|
|
std::function< UUID(const std::string &)> | provider ) |
|
static |
Register UUID provider
- Parameters
-
| version | the UUID version which can be handled by provider |
| provider | the provider |
◆ toBytes()
| std::array< uint8_t, 16 > anch::UUID::toBytes |
( |
| ) |
const |
Get UUID 16 bytes binary representation (RFC 9562, big-endian)
- Returns
- the 16 bytes
◆ toChars()
| char * anch::UUID::toChars |
( |
char * | first | ) |
const |
Write UUID string representation without allocation.
Exactly STRING_SIZE lowercase hexadecimal characters and '-' are written (no '\0' ). Each part is written with its fixed width: higher bits of a part which does not fit (which can only be set with the parts constructor) are ignored.
- Parameters
-
| first | the first character to write (at least STRING_SIZE characters available) |
- Returns
- the pointer after the last written character
◆ toString()
| std::string anch::UUID::toString |
( |
| ) |
const |
Convert UUID to std::string
- Returns
- The string representation of UUID
◆ SEQ_HIGH_MASK
| const uint32_t anch::UUID::SEQ_HIGH_MASK = 0x3F00 |
|
static |
Sequence high part time mask
◆ SEQ_LOW_MASK
| const uint32_t anch::UUID::SEQ_LOW_MASK = 0x00FF |
|
static |
Sequence low part time mask
◆ STRING_SIZE
| std::size_t anch::UUID::STRING_SIZE = 36 |
|
staticconstexpr |
UUID string representation size (without '\0' )
◆ TIME_HIGH_MASK
| const uint64_t anch::UUID::TIME_HIGH_MASK = 0x0000000000000FFF |
|
static |
◆ TIME_LOW_MASK
| const uint64_t anch::UUID::TIME_LOW_MASK = 0x00000000FFFFFFFF |
|
static |
◆ TIME_MID_MASK
| const uint64_t anch::UUID::TIME_MID_MASK = 0x000000000000FFFF |
|
static |
Time middle part time mask
◆ VERSION_MASK
| const uint64_t anch::UUID::VERSION_MASK = 0x000000000000F000 |
|
static |
The documentation for this class was generated from the following file: