Debian Codegraph @

version.go

raw
1 package uuid
2
3 // Version represents the type of UUID.
4 type Version uint8
5
6 const (
7 VariantNCS uint8 = 0x00
8 VariantRFC4122 uint8 = 0x80 // or and A0 if masked with 1F
9 VariantMicrosoft uint8 = 0xC0
10 VariantFuture uint8 = 0xE0
11 )
12
13 const (
14 Unknown Version = iota // Unknown
15 One // Time based
16 Two // DCE security via POSIX UIDs
17 Three // Namespace hash uses MD5
18 Four // Crypto random
19 Five // Namespace hash uses SHA-1
20 )
21
22 const (
23 // 3f used by RFC4122 although 1f works for all
24 variantSet = 0x3f
25
26 // rather than using 0xc0 we use 0xe0 to retrieve the variant
27 // The result is the same for all other variants
28 // 0x80 and 0xa0 are used to identify RFC4122 compliance
29 variantGet = 0xe0
30 )
31
32 // String returns English description of version.
33 func (o Version) String() string {
34 switch o {
35 case One:
36 return "Version 1: Based on a 60 Bit Timestamp"
37 case Two:
38 return "Version 2: Based on DCE security domain and 60 bit timestamp"
39 case Three:
40 return "Version 3: Namespace UUID and unique names hashed by MD5"
41 case Four:
42 return "Version 4: Crypto-random"
43 case Five:
44 return "Version 5: Namespace UUID and unique names hashed by SHA-1"
45 default:
46 return "Unknown: Not supported"
47 }
48 }
49
50 func resolveVersion(pVersion uint8) Version {
51 switch Version(pVersion) {
52 case One, Two, Three, Four, Five:
53 return Version(pVersion)
54 default:
55 return Unknown
56 }
57 }
58
59 func variant(pVariant uint8) uint8 {
60 switch pVariant & variantGet {
61 case VariantRFC4122, 0xA0:
62 return VariantRFC4122
63 case VariantMicrosoft:
64 return VariantMicrosoft
65 case VariantFuture:
66 return VariantFuture
67 }
68 return VariantNCS
69 }