diff options
author | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
---|---|---|
committer | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
commit | 404aeae4545d2426c089a5f8d5e82dae56f5212b (patch) | |
tree | 2d84e00af272b39fc04f3795ae06bc48970e57b5 /vendor/github.com/google/uuid/dce.go | |
parent | 209d8b0187ed025dec9ac149ebcced3462877bff (diff) | |
download | gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.tar.gz gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.zip |
Make Nix builds work
Diffstat (limited to 'vendor/github.com/google/uuid/dce.go')
-rw-r--r-- | vendor/github.com/google/uuid/dce.go | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/vendor/github.com/google/uuid/dce.go b/vendor/github.com/google/uuid/dce.go new file mode 100644 index 0000000..fa820b9 --- /dev/null +++ b/vendor/github.com/google/uuid/dce.go | |||
@@ -0,0 +1,80 @@ | |||
1 | // Copyright 2016 Google Inc. All rights reserved. | ||
2 | // Use of this source code is governed by a BSD-style | ||
3 | // license that can be found in the LICENSE file. | ||
4 | |||
5 | package uuid | ||
6 | |||
7 | import ( | ||
8 | "encoding/binary" | ||
9 | "fmt" | ||
10 | "os" | ||
11 | ) | ||
12 | |||
13 | // A Domain represents a Version 2 domain | ||
14 | type Domain byte | ||
15 | |||
16 | // Domain constants for DCE Security (Version 2) UUIDs. | ||
17 | const ( | ||
18 | Person = Domain(0) | ||
19 | Group = Domain(1) | ||
20 | Org = Domain(2) | ||
21 | ) | ||
22 | |||
23 | // NewDCESecurity returns a DCE Security (Version 2) UUID. | ||
24 | // | ||
25 | // The domain should be one of Person, Group or Org. | ||
26 | // On a POSIX system the id should be the users UID for the Person | ||
27 | // domain and the users GID for the Group. The meaning of id for | ||
28 | // the domain Org or on non-POSIX systems is site defined. | ||
29 | // | ||
30 | // For a given domain/id pair the same token may be returned for up to | ||
31 | // 7 minutes and 10 seconds. | ||
32 | func NewDCESecurity(domain Domain, id uint32) (UUID, error) { | ||
33 | uuid, err := NewUUID() | ||
34 | if err == nil { | ||
35 | uuid[6] = (uuid[6] & 0x0f) | 0x20 // Version 2 | ||
36 | uuid[9] = byte(domain) | ||
37 | binary.BigEndian.PutUint32(uuid[0:], id) | ||
38 | } | ||
39 | return uuid, err | ||
40 | } | ||
41 | |||
42 | // NewDCEPerson returns a DCE Security (Version 2) UUID in the person | ||
43 | // domain with the id returned by os.Getuid. | ||
44 | // | ||
45 | // NewDCESecurity(Person, uint32(os.Getuid())) | ||
46 | func NewDCEPerson() (UUID, error) { | ||
47 | return NewDCESecurity(Person, uint32(os.Getuid())) | ||
48 | } | ||
49 | |||
50 | // NewDCEGroup returns a DCE Security (Version 2) UUID in the group | ||
51 | // domain with the id returned by os.Getgid. | ||
52 | // | ||
53 | // NewDCESecurity(Group, uint32(os.Getgid())) | ||
54 | func NewDCEGroup() (UUID, error) { | ||
55 | return NewDCESecurity(Group, uint32(os.Getgid())) | ||
56 | } | ||
57 | |||
58 | // Domain returns the domain for a Version 2 UUID. Domains are only defined | ||
59 | // for Version 2 UUIDs. | ||
60 | func (uuid UUID) Domain() Domain { | ||
61 | return Domain(uuid[9]) | ||
62 | } | ||
63 | |||
64 | // ID returns the id for a Version 2 UUID. IDs are only defined for Version 2 | ||
65 | // UUIDs. | ||
66 | func (uuid UUID) ID() uint32 { | ||
67 | return binary.BigEndian.Uint32(uuid[0:4]) | ||
68 | } | ||
69 | |||
70 | func (d Domain) String() string { | ||
71 | switch d { | ||
72 | case Person: | ||
73 | return "Person" | ||
74 | case Group: | ||
75 | return "Group" | ||
76 | case Org: | ||
77 | return "Org" | ||
78 | } | ||
79 | return fmt.Sprintf("Domain%d", int(d)) | ||
80 | } | ||