|
| 1 | +package uuid |
| 2 | + |
| 3 | +// A RFC 4122 Universally Unique Identifier |
| 4 | +Identifier :: distinct [16]u8 |
| 5 | + |
| 6 | +EXPECTED_LENGTH :: 8 + 4 + 4 + 4 + 12 + 4 |
| 7 | + |
| 8 | +VERSION_BYTE_INDEX :: 6 |
| 9 | +VARIANT_BYTE_INDEX :: 8 |
| 10 | + |
| 11 | +// The number of 100-nanosecond intervals between 1582-10-15 and 1970-01-01. |
| 12 | +HNS_INTERVALS_BETWEEN_GREG_AND_UNIX :: 141427 * 24 * 60 * 60 * 1000 * 1000 * 10 |
| 13 | + |
| 14 | +VERSION_7_TIME_MASK :: 0xffffffff_ffff0000_00000000_00000000 |
| 15 | +VERSION_7_TIME_SHIFT :: 80 |
| 16 | +VERSION_7_COUNTER_MASK :: 0x00000000_00000fff_00000000_00000000 |
| 17 | +VERSION_7_COUNTER_SHIFT :: 64 |
| 18 | + |
| 19 | +@(private) |
| 20 | +NO_CSPRNG_ERROR :: "The context random generator is not cryptographic. See the documentation for an example of how to set one up." |
| 21 | +@(private) |
| 22 | +BIG_CLOCK_ERROR :: "The clock sequence can only hold 14 bits of data, therefore no number greater than 16,383 (0x3FFF)." |
| 23 | +@(private) |
| 24 | +VERSION_7_BIG_COUNTER_ERROR :: "This implementation of the version 7 UUID counter can only hold 12 bits of data, therefore no number greater than 4,095 (0xFFF)." |
| 25 | + |
| 26 | +Read_Error :: enum { |
| 27 | + None, |
| 28 | + Invalid_Length, |
| 29 | + Invalid_Hexadecimal, |
| 30 | + Invalid_Separator, |
| 31 | +} |
| 32 | + |
| 33 | +Variant_Type :: enum { |
| 34 | + Unknown, |
| 35 | + Reserved_Apollo_NCS, // 0b0xx |
| 36 | + RFC_4122, // 0b10x |
| 37 | + Reserved_Microsoft_COM, // 0b110 |
| 38 | + Reserved_Future, // 0b111 |
| 39 | +} |
| 40 | + |
| 41 | +// Name string is a fully-qualified domain name. |
| 42 | +@(rodata) |
| 43 | +Namespace_DNS := Identifier { |
| 44 | + 0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, |
| 45 | + 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8, |
| 46 | +} |
| 47 | + |
| 48 | +// Name string is a URL. |
| 49 | +@(rodata) |
| 50 | +Namespace_URL := Identifier { |
| 51 | + 0x6b, 0xa7, 0xb8, 0x11, 0x9d, 0xad, 0x11, 0xd1, |
| 52 | + 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8, |
| 53 | +} |
| 54 | + |
| 55 | +// Name string is an ISO OID. |
| 56 | +@(rodata) |
| 57 | +Namespace_OID := Identifier { |
| 58 | + 0x6b, 0xa7, 0xb8, 0x12, 0x9d, 0xad, 0x11, 0xd1, |
| 59 | + 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8, |
| 60 | +} |
| 61 | + |
| 62 | +// Name string is an X.500 DN (in DER or a text output format). |
| 63 | +@(rodata) |
| 64 | +Namespace_X500 := Identifier { |
| 65 | + 0x6b, 0xa7, 0xb8, 0x14, 0x9d, 0xad, 0x11, 0xd1, |
| 66 | + 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8, |
| 67 | +} |
0 commit comments