|
1 | | -// Copyright 2011 Google Inc. All rights reserved. |
| 1 | +// Copyright 2016 Google Inc. All rights reserved. |
2 | 2 | // Use of this source code is governed by a BSD-style |
3 | 3 | // license that can be found in the LICENSE file. |
4 | 4 |
|
@@ -29,46 +29,42 @@ const ( |
29 | 29 | // |
30 | 30 | // For a given domain/id pair the same token may be returned for up to |
31 | 31 | // 7 minutes and 10 seconds. |
32 | | -func NewDCESecurity(domain Domain, id uint32) UUID { |
33 | | - uuid := NewUUID() |
34 | | - if uuid != nil { |
| 32 | +func NewDCESecurity(domain Domain, id uint32) (UUID, error) { |
| 33 | + uuid, err := NewUUID() |
| 34 | + if err == nil { |
35 | 35 | uuid[6] = (uuid[6] & 0x0f) | 0x20 // Version 2 |
36 | 36 | uuid[9] = byte(domain) |
37 | 37 | binary.BigEndian.PutUint32(uuid[0:], id) |
38 | 38 | } |
39 | | - return uuid |
| 39 | + return uuid, err |
40 | 40 | } |
41 | 41 |
|
42 | 42 | // NewDCEPerson returns a DCE Security (Version 2) UUID in the person |
43 | 43 | // domain with the id returned by os.Getuid. |
44 | 44 | // |
45 | 45 | // NewDCEPerson(Person, uint32(os.Getuid())) |
46 | | -func NewDCEPerson() UUID { |
| 46 | +func NewDCEPerson() (UUID, error) { |
47 | 47 | return NewDCESecurity(Person, uint32(os.Getuid())) |
48 | 48 | } |
49 | 49 |
|
50 | 50 | // NewDCEGroup returns a DCE Security (Version 2) UUID in the group |
51 | 51 | // domain with the id returned by os.Getgid. |
52 | 52 | // |
53 | 53 | // NewDCEGroup(Group, uint32(os.Getgid())) |
54 | | -func NewDCEGroup() UUID { |
| 54 | +func NewDCEGroup() (UUID, error) { |
55 | 55 | return NewDCESecurity(Group, uint32(os.Getgid())) |
56 | 56 | } |
57 | 57 |
|
58 | | -// Domain returns the domain for a Version 2 UUID or false. |
59 | | -func (uuid UUID) Domain() (Domain, bool) { |
60 | | - if v, _ := uuid.Version(); v != 2 { |
61 | | - return 0, false |
62 | | - } |
63 | | - return Domain(uuid[9]), true |
| 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]) |
64 | 62 | } |
65 | 63 |
|
66 | | -// Id returns the id for a Version 2 UUID or false. |
67 | | -func (uuid UUID) Id() (uint32, bool) { |
68 | | - if v, _ := uuid.Version(); v != 2 { |
69 | | - return 0, false |
70 | | - } |
71 | | - return binary.BigEndian.Uint32(uuid[0:4]), true |
| 64 | +// Id returns the id for a Version 2 UUID. Ids are only defined for Vrsion 2 |
| 65 | +// UUIDs. |
| 66 | +func (uuid UUID) Id() uint32 { |
| 67 | + return binary.BigEndian.Uint32(uuid[0:4]) |
72 | 68 | } |
73 | 69 |
|
74 | 70 | func (d Domain) String() string { |
|
0 commit comments