Stephen McQuay 2 years ago
commit
5becb68015
Signed by: Stephen McQuay (smcquay) <stephen@mcquay.me> GPG Key ID: 4E4B72F479BA3CE5

+ 15
- 0
Gopkg.lock View File

@@ -0,0 +1,15 @@
1
+# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
2
+
3
+
4
+[[projects]]
5
+  name = "github.com/pborman/uuid"
6
+  packages = ["."]
7
+  revision = "e790cca94e6cc75c7064b1332e63811d4aae1a53"
8
+  version = "v1.1"
9
+
10
+[solve-meta]
11
+  analyzer-name = "dep"
12
+  analyzer-version = 1
13
+  inputs-digest = "fbe0d2bde8a8c1659d0e965328bda4e05f246c471267358b9dfe9c95fd1025ff"
14
+  solver-name = "gps-cdcl"
15
+  solver-version = 1

+ 26
- 0
Gopkg.toml View File

@@ -0,0 +1,26 @@
1
+
2
+# Gopkg.toml example
3
+#
4
+# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
5
+# for detailed Gopkg.toml documentation.
6
+#
7
+# required = ["github.com/user/thing/cmd/thing"]
8
+# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
9
+#
10
+# [[constraint]]
11
+#   name = "github.com/user/project"
12
+#   version = "1.0.0"
13
+#
14
+# [[constraint]]
15
+#   name = "github.com/user/project2"
16
+#   branch = "dev"
17
+#   source = "github.com/myfork/project2"
18
+#
19
+# [[override]]
20
+#  name = "github.com/x/y"
21
+#  version = "2.4.0"
22
+
23
+
24
+[[constraint]]
25
+  name = "github.com/pborman/uuid"
26
+  version = "1.1.0"

+ 20
- 0
LICENSE View File

@@ -0,0 +1,20 @@
1
+MIT License
2
+Copyright (c) 2017 Stephen McQuay
3
+
4
+Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+this software and associated documentation files (the "Software"), to deal in
6
+the Software without restriction, including without limitation the rights to
7
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
+of the Software, and to permit persons to whom the Software is furnished to do
9
+so, subject to the following conditions:
10
+
11
+The above copyright notice and this permission notice shall be included in all
12
+copies or substantial portions of the Software.
13
+
14
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+SOFTWARE.

+ 8
- 0
README.md View File

@@ -0,0 +1,8 @@
1
+# uuid
2
+
3
+Print a uuid. The world's most silly program yet.
4
+
5
+## usage
6
+
7
+    $ uuid
8
+    5779fd1b-6151-4d8e-81f5-73d71b8f7576

+ 11
- 0
main.go View File

@@ -0,0 +1,11 @@
1
+package main
2
+
3
+import (
4
+	"fmt"
5
+
6
+	"github.com/pborman/uuid"
7
+)
8
+
9
+func main() {
10
+	fmt.Println(uuid.New())
11
+}

+ 9
- 0
vendor/github.com/pborman/uuid/.travis.yml View File

@@ -0,0 +1,9 @@
1
+language: go
2
+
3
+go:
4
+  - 1.4.3
5
+  - 1.5.3
6
+  - tip
7
+
8
+script:
9
+  - go test -v ./...

+ 10
- 0
vendor/github.com/pborman/uuid/CONTRIBUTING.md View File

@@ -0,0 +1,10 @@
1
+# How to contribute
2
+
3
+We definitely welcome patches and contribution to this project!
4
+
5
+### Legal requirements
6
+
7
+In order to protect both you and ourselves, you will need to sign the
8
+[Contributor License Agreement](https://cla.developers.google.com/clas).
9
+
10
+You may have already signed it for other Google projects.

+ 1
- 0
vendor/github.com/pborman/uuid/CONTRIBUTORS View File

@@ -0,0 +1 @@
1
+Paul Borman <borman@google.com>

+ 27
- 0
vendor/github.com/pborman/uuid/LICENSE View File

@@ -0,0 +1,27 @@
1
+Copyright (c) 2009,2014 Google Inc. All rights reserved.
2
+
3
+Redistribution and use in source and binary forms, with or without
4
+modification, are permitted provided that the following conditions are
5
+met:
6
+
7
+   * Redistributions of source code must retain the above copyright
8
+notice, this list of conditions and the following disclaimer.
9
+   * Redistributions in binary form must reproduce the above
10
+copyright notice, this list of conditions and the following disclaimer
11
+in the documentation and/or other materials provided with the
12
+distribution.
13
+   * Neither the name of Google Inc. nor the names of its
14
+contributors may be used to endorse or promote products derived from
15
+this software without specific prior written permission.
16
+
17
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 13
- 0
vendor/github.com/pborman/uuid/README.md View File

@@ -0,0 +1,13 @@
1
+This project was automatically exported from code.google.com/p/go-uuid
2
+
3
+# uuid ![build status](https://travis-ci.org/pborman/uuid.svg?branch=master)
4
+The uuid package generates and inspects UUIDs based on [RFC 4122](http://tools.ietf.org/html/rfc4122) and DCE 1.1: Authentication and Security Services. 
5
+
6
+###### Install
7
+`go get github.com/pborman/uuid`
8
+
9
+###### Documentation 
10
+[![GoDoc](https://godoc.org/github.com/pborman/uuid?status.svg)](http://godoc.org/github.com/pborman/uuid)
11
+
12
+Full `go doc` style documentation for the package can be viewed online without installing this package by using the GoDoc site here: 
13
+http://godoc.org/github.com/pborman/uuid

+ 84
- 0
vendor/github.com/pborman/uuid/dce.go View File

@@ -0,0 +1,84 @@
1
+// Copyright 2011 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 {
33
+	uuid := NewUUID()
34
+	if uuid != 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
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
+//  NewDCEPerson(Person, uint32(os.Getuid()))
46
+func NewDCEPerson() UUID {
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
+//  NewDCEGroup(Group, uint32(os.Getgid()))
54
+func NewDCEGroup() UUID {
55
+	return NewDCESecurity(Group, uint32(os.Getgid()))
56
+}
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
64
+}
65
+
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
72
+}
73
+
74
+func (d Domain) String() string {
75
+	switch d {
76
+	case Person:
77
+		return "Person"
78
+	case Group:
79
+		return "Group"
80
+	case Org:
81
+		return "Org"
82
+	}
83
+	return fmt.Sprintf("Domain%d", int(d))
84
+}

+ 8
- 0
vendor/github.com/pborman/uuid/doc.go View File

@@ -0,0 +1,8 @@
1
+// Copyright 2011 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
+// The uuid package generates and inspects UUIDs.
6
+//
7
+// UUIDs are based on RFC 4122 and DCE 1.1: Authentication and Security Services.
8
+package uuid

+ 53
- 0
vendor/github.com/pborman/uuid/hash.go View File

@@ -0,0 +1,53 @@
1
+// Copyright 2011 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
+	"crypto/md5"
9
+	"crypto/sha1"
10
+	"hash"
11
+)
12
+
13
+// Well known Name Space IDs and UUIDs
14
+var (
15
+	NameSpace_DNS  = Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
16
+	NameSpace_URL  = Parse("6ba7b811-9dad-11d1-80b4-00c04fd430c8")
17
+	NameSpace_OID  = Parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8")
18
+	NameSpace_X500 = Parse("6ba7b814-9dad-11d1-80b4-00c04fd430c8")
19
+	NIL            = Parse("00000000-0000-0000-0000-000000000000")
20
+)
21
+
22
+// NewHash returns a new UUID derived from the hash of space concatenated with
23
+// data generated by h.  The hash should be at least 16 byte in length.  The
24
+// first 16 bytes of the hash are used to form the UUID.  The version of the
25
+// UUID will be the lower 4 bits of version.  NewHash is used to implement
26
+// NewMD5 and NewSHA1.
27
+func NewHash(h hash.Hash, space UUID, data []byte, version int) UUID {
28
+	h.Reset()
29
+	h.Write(space)
30
+	h.Write([]byte(data))
31
+	s := h.Sum(nil)
32
+	uuid := make([]byte, 16)
33
+	copy(uuid, s)
34
+	uuid[6] = (uuid[6] & 0x0f) | uint8((version&0xf)<<4)
35
+	uuid[8] = (uuid[8] & 0x3f) | 0x80 // RFC 4122 variant
36
+	return uuid
37
+}
38
+
39
+// NewMD5 returns a new MD5 (Version 3) UUID based on the
40
+// supplied name space and data.
41
+//
42
+//  NewHash(md5.New(), space, data, 3)
43
+func NewMD5(space UUID, data []byte) UUID {
44
+	return NewHash(md5.New(), space, data, 3)
45
+}
46
+
47
+// NewSHA1 returns a new SHA1 (Version 5) UUID based on the
48
+// supplied name space and data.
49
+//
50
+//  NewHash(sha1.New(), space, data, 5)
51
+func NewSHA1(space UUID, data []byte) UUID {
52
+	return NewHash(sha1.New(), space, data, 5)
53
+}

+ 83
- 0
vendor/github.com/pborman/uuid/marshal.go View File

@@ -0,0 +1,83 @@
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
+	"errors"
9
+	"fmt"
10
+)
11
+
12
+// MarshalText implements encoding.TextMarshaler.
13
+func (u UUID) MarshalText() ([]byte, error) {
14
+	if len(u) != 16 {
15
+		return nil, nil
16
+	}
17
+	var js [36]byte
18
+	encodeHex(js[:], u)
19
+	return js[:], nil
20
+}
21
+
22
+// UnmarshalText implements encoding.TextUnmarshaler.
23
+func (u *UUID) UnmarshalText(data []byte) error {
24
+	if len(data) == 0 {
25
+		return nil
26
+	}
27
+	id := Parse(string(data))
28
+	if id == nil {
29
+		return errors.New("invalid UUID")
30
+	}
31
+	*u = id
32
+	return nil
33
+}
34
+
35
+// MarshalBinary implements encoding.BinaryMarshaler.
36
+func (u UUID) MarshalBinary() ([]byte, error) {
37
+	return u[:], nil
38
+}
39
+
40
+// UnmarshalBinary implements encoding.BinaryUnmarshaler.
41
+func (u *UUID) UnmarshalBinary(data []byte) error {
42
+	if len(data) == 0 {
43
+		return nil
44
+	}
45
+	if len(data) != 16 {
46
+		return fmt.Errorf("invalid UUID (got %d bytes)", len(data))
47
+	}
48
+	var id [16]byte
49
+	copy(id[:], data)
50
+	*u = id[:]
51
+	return nil
52
+}
53
+
54
+// MarshalText implements encoding.TextMarshaler.
55
+func (u Array) MarshalText() ([]byte, error) {
56
+	var js [36]byte
57
+	encodeHex(js[:], u[:])
58
+	return js[:], nil
59
+}
60
+
61
+// UnmarshalText implements encoding.TextUnmarshaler.
62
+func (u *Array) UnmarshalText(data []byte) error {
63
+	id := Parse(string(data))
64
+	if id == nil {
65
+		return errors.New("invalid UUID")
66
+	}
67
+	*u = id.Array()
68
+	return nil
69
+}
70
+
71
+// MarshalBinary implements encoding.BinaryMarshaler.
72
+func (u Array) MarshalBinary() ([]byte, error) {
73
+	return u[:], nil
74
+}
75
+
76
+// UnmarshalBinary implements encoding.BinaryUnmarshaler.
77
+func (u *Array) UnmarshalBinary(data []byte) error {
78
+	if len(data) != 16 {
79
+		return fmt.Errorf("invalid UUID (got %d bytes)", len(data))
80
+	}
81
+	copy(u[:], data)
82
+	return nil
83
+}

+ 124
- 0
vendor/github.com/pborman/uuid/marshal_test.go View File

@@ -0,0 +1,124 @@
1
+// Copyright 2014 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
+	"bytes"
9
+	"encoding/json"
10
+	"reflect"
11
+	"testing"
12
+)
13
+
14
+var testUUID = Parse("f47ac10b-58cc-0372-8567-0e02b2c3d479")
15
+var testArray = testUUID.Array()
16
+
17
+func TestJSON(t *testing.T) {
18
+	type S struct {
19
+		ID1 UUID
20
+		ID2 UUID
21
+	}
22
+	s1 := S{ID1: testUUID}
23
+	data, err := json.Marshal(&s1)
24
+	if err != nil {
25
+		t.Fatal(err)
26
+	}
27
+	var s2 S
28
+	if err := json.Unmarshal(data, &s2); err != nil {
29
+		t.Fatal(err)
30
+	}
31
+	if !reflect.DeepEqual(&s1, &s2) {
32
+		t.Errorf("got %#v, want %#v", s2, s1)
33
+	}
34
+}
35
+
36
+func TestJSONArray(t *testing.T) {
37
+	type S struct {
38
+		ID1 Array
39
+		ID2 Array
40
+	}
41
+	s1 := S{ID1: testArray}
42
+	data, err := json.Marshal(&s1)
43
+	if err != nil {
44
+		t.Fatal(err)
45
+	}
46
+	var s2 S
47
+	if err := json.Unmarshal(data, &s2); err != nil {
48
+		t.Fatal(err)
49
+	}
50
+	if !reflect.DeepEqual(&s1, &s2) {
51
+		t.Errorf("got %#v, want %#v", s2, s1)
52
+	}
53
+}
54
+
55
+func TestMarshal(t *testing.T) {
56
+	data, err := testUUID.MarshalBinary()
57
+	if err != nil {
58
+		t.Fatalf("MarhsalBinary returned unexpected error %v", err)
59
+	}
60
+	if !bytes.Equal(data, testUUID) {
61
+		t.Fatalf("MarhsalBinary returns %x, want %x", data, testUUID)
62
+	}
63
+	var u UUID
64
+	u.UnmarshalBinary(data)
65
+	if !Equal(data, u) {
66
+		t.Fatalf("UnmarhsalBinary returns %v, want %v", u, testUUID)
67
+	}
68
+}
69
+
70
+func TestMarshalArray(t *testing.T) {
71
+	data, err := testArray.MarshalBinary()
72
+	if err != nil {
73
+		t.Fatalf("MarhsalBinary returned unexpected error %v", err)
74
+	}
75
+	if !bytes.Equal(data, testUUID) {
76
+		t.Fatalf("MarhsalBinary returns %x, want %x", data, testUUID)
77
+	}
78
+	var a Array
79
+	a.UnmarshalBinary(data)
80
+	if a != testArray {
81
+		t.Fatalf("UnmarhsalBinary returns %v, want %v", a, testArray)
82
+	}
83
+}
84
+
85
+func TestMarshalTextArray(t *testing.T) {
86
+	data, err := testArray.MarshalText()
87
+	if err != nil {
88
+		t.Fatalf("MarhsalText returned unexpected error %v", err)
89
+	}
90
+	var a Array
91
+	a.UnmarshalText(data)
92
+	if a != testArray {
93
+		t.Fatalf("UnmarhsalText returns %v, want %v", a, testArray)
94
+	}
95
+}
96
+
97
+func BenchmarkUUID_MarshalJSON(b *testing.B) {
98
+	x := &struct {
99
+		UUID UUID `json:"uuid"`
100
+	}{}
101
+	x.UUID = Parse("f47ac10b-58cc-0372-8567-0e02b2c3d479")
102
+	if x.UUID == nil {
103
+		b.Fatal("invalid uuid")
104
+	}
105
+	for i := 0; i < b.N; i++ {
106
+		js, err := json.Marshal(x)
107
+		if err != nil {
108
+			b.Fatalf("marshal json: %#v (%v)", js, err)
109
+		}
110
+	}
111
+}
112
+
113
+func BenchmarkUUID_UnmarshalJSON(b *testing.B) {
114
+	js := []byte(`{"uuid":"f47ac10b-58cc-0372-8567-0e02b2c3d479"}`)
115
+	var x *struct {
116
+		UUID UUID `json:"uuid"`
117
+	}
118
+	for i := 0; i < b.N; i++ {
119
+		err := json.Unmarshal(js, &x)
120
+		if err != nil {
121
+			b.Fatalf("marshal json: %#v (%v)", js, err)
122
+		}
123
+	}
124
+}

+ 117
- 0
vendor/github.com/pborman/uuid/node.go View File

@@ -0,0 +1,117 @@
1
+// Copyright 2011 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
+	"net"
9
+	"sync"
10
+)
11
+
12
+var (
13
+	nodeMu     sync.Mutex
14
+	interfaces []net.Interface // cached list of interfaces
15
+	ifname     string          // name of interface being used
16
+	nodeID     []byte          // hardware for version 1 UUIDs
17
+)
18
+
19
+// NodeInterface returns the name of the interface from which the NodeID was
20
+// derived.  The interface "user" is returned if the NodeID was set by
21
+// SetNodeID.
22
+func NodeInterface() string {
23
+	defer nodeMu.Unlock()
24
+	nodeMu.Lock()
25
+	return ifname
26
+}
27
+
28
+// SetNodeInterface selects the hardware address to be used for Version 1 UUIDs.
29
+// If name is "" then the first usable interface found will be used or a random
30
+// Node ID will be generated.  If a named interface cannot be found then false
31
+// is returned.
32
+//
33
+// SetNodeInterface never fails when name is "".
34
+func SetNodeInterface(name string) bool {
35
+	defer nodeMu.Unlock()
36
+	nodeMu.Lock()
37
+	return setNodeInterface(name)
38
+}
39
+
40
+func setNodeInterface(name string) bool {
41
+	if interfaces == nil {
42
+		var err error
43
+		interfaces, err = net.Interfaces()
44
+		if err != nil && name != "" {
45
+			return false
46
+		}
47
+	}
48
+
49
+	for _, ifs := range interfaces {
50
+		if len(ifs.HardwareAddr) >= 6 && (name == "" || name == ifs.Name) {
51
+			if setNodeID(ifs.HardwareAddr) {
52
+				ifname = ifs.Name
53
+				return true
54
+			}
55
+		}
56
+	}
57
+
58
+	// We found no interfaces with a valid hardware address.  If name
59
+	// does not specify a specific interface generate a random Node ID
60
+	// (section 4.1.6)
61
+	if name == "" {
62
+		if nodeID == nil {
63
+			nodeID = make([]byte, 6)
64
+		}
65
+		randomBits(nodeID)
66
+		return true
67
+	}
68
+	return false
69
+}
70
+
71
+// NodeID returns a slice of a copy of the current Node ID, setting the Node ID
72
+// if not already set.
73
+func NodeID() []byte {
74
+	defer nodeMu.Unlock()
75
+	nodeMu.Lock()
76
+	if nodeID == nil {
77
+		setNodeInterface("")
78
+	}
79
+	nid := make([]byte, 6)
80
+	copy(nid, nodeID)
81
+	return nid
82
+}
83
+
84
+// SetNodeID sets the Node ID to be used for Version 1 UUIDs.  The first 6 bytes
85
+// of id are used.  If id is less than 6 bytes then false is returned and the
86
+// Node ID is not set.
87
+func SetNodeID(id []byte) bool {
88
+	defer nodeMu.Unlock()
89
+	nodeMu.Lock()
90
+	if setNodeID(id) {
91
+		ifname = "user"
92
+		return true
93
+	}
94
+	return false
95
+}
96
+
97
+func setNodeID(id []byte) bool {
98
+	if len(id) < 6 {
99
+		return false
100
+	}
101
+	if nodeID == nil {
102
+		nodeID = make([]byte, 6)
103
+	}
104
+	copy(nodeID, id)
105
+	return true
106
+}
107
+
108
+// NodeID returns the 6 byte node id encoded in uuid.  It returns nil if uuid is
109
+// not valid.  The NodeID is only well defined for version 1 and 2 UUIDs.
110
+func (uuid UUID) NodeID() []byte {
111
+	if len(uuid) != 16 {
112
+		return nil
113
+	}
114
+	node := make([]byte, 6)
115
+	copy(node, uuid[10:])
116
+	return node
117
+}

+ 66
- 0
vendor/github.com/pborman/uuid/seq_test.go View File

@@ -0,0 +1,66 @@
1
+// Copyright 2014 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
+	"flag"
9
+	"runtime"
10
+	"testing"
11
+	"time"
12
+)
13
+
14
+// This test is only run when --regressions is passed on the go test line.
15
+var regressions = flag.Bool("regressions", false, "run uuid regression tests")
16
+
17
+// TestClockSeqRace tests for a particular race condition of returning two
18
+// identical Version1 UUIDs.  The duration of 1 minute was chosen as the race
19
+// condition, before being fixed, nearly always occured in under 30 seconds.
20
+func TestClockSeqRace(t *testing.T) {
21
+	if !*regressions {
22
+		t.Skip("skipping regression tests")
23
+	}
24
+	duration := time.Minute
25
+
26
+	done := make(chan struct{})
27
+	defer close(done)
28
+
29
+	ch := make(chan UUID, 10000)
30
+	ncpu := runtime.NumCPU()
31
+	switch ncpu {
32
+	case 0, 1:
33
+		// We can't run the test effectively.
34
+		t.Skip("skipping race test, only one CPU detected")
35
+		return
36
+	default:
37
+		runtime.GOMAXPROCS(ncpu)
38
+	}
39
+	for i := 0; i < ncpu; i++ {
40
+		go func() {
41
+			for {
42
+				select {
43
+				case <-done:
44
+					return
45
+				case ch <- NewUUID():
46
+				}
47
+			}
48
+		}()
49
+	}
50
+
51
+	uuids := make(map[string]bool)
52
+	cnt := 0
53
+	start := time.Now()
54
+	for u := range ch {
55
+		s := u.String()
56
+		if uuids[s] {
57
+			t.Errorf("duplicate uuid after %d in %v: %s", cnt, time.Since(start), s)
58
+			return
59
+		}
60
+		uuids[s] = true
61
+		if time.Since(start) > duration {
62
+			return
63
+		}
64
+		cnt++
65
+	}
66
+}

+ 66
- 0
vendor/github.com/pborman/uuid/sql.go View File

@@ -0,0 +1,66 @@
1
+// Copyright 2015 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
+	"database/sql/driver"
9
+	"errors"
10
+	"fmt"
11
+)
12
+
13
+// Scan implements sql.Scanner so UUIDs can be read from databases transparently
14
+// Currently, database types that map to string and []byte are supported. Please
15
+// consult database-specific driver documentation for matching types.
16
+func (uuid *UUID) Scan(src interface{}) error {
17
+	switch src.(type) {
18
+	case string:
19
+		// if an empty UUID comes from a table, we return a null UUID
20
+		if src.(string) == "" {
21
+			return nil
22
+		}
23
+
24
+		// see uuid.Parse for required string format
25
+		parsed := Parse(src.(string))
26
+
27
+		if parsed == nil {
28
+			return errors.New("Scan: invalid UUID format")
29
+		}
30
+
31
+		*uuid = parsed
32
+	case []byte:
33
+		b := src.([]byte)
34
+
35
+		// if an empty UUID comes from a table, we return a null UUID
36
+		if len(b) == 0 {
37
+			return nil
38
+		}
39
+
40
+		// assumes a simple slice of bytes if 16 bytes
41
+		// otherwise attempts to parse
42
+		if len(b) == 16 {
43
+			*uuid = UUID(b)
44
+		} else {
45
+			u := Parse(string(b))
46
+
47
+			if u == nil {
48
+				return errors.New("Scan: invalid UUID format")
49
+			}
50
+
51
+			*uuid = u
52
+		}
53
+
54
+	default:
55
+		return fmt.Errorf("Scan: unable to scan type %T into UUID", src)
56
+	}
57
+
58
+	return nil
59
+}
60
+
61
+// Value implements sql.Valuer so that UUIDs can be written to databases
62
+// transparently. Currently, UUIDs map to strings. Please consult
63
+// database-specific driver documentation for matching types.
64
+func (uuid UUID) Value() (driver.Value, error) {
65
+	return uuid.String(), nil
66
+}

+ 96
- 0
vendor/github.com/pborman/uuid/sql_test.go View File

@@ -0,0 +1,96 @@
1
+// Copyright 2015 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
+	"strings"
9
+	"testing"
10
+)
11
+
12
+func TestScan(t *testing.T) {
13
+	var stringTest string = "f47ac10b-58cc-0372-8567-0e02b2c3d479"
14
+	var byteTest []byte = Parse(stringTest)
15
+	var badTypeTest int = 6
16
+	var invalidTest string = "f47ac10b-58cc-0372-8567-0e02b2c3d4"
17
+
18
+	// sunny day tests
19
+
20
+	var uuid UUID
21
+	err := (&uuid).Scan(stringTest)
22
+	if err != nil {
23
+		t.Fatal(err)
24
+	}
25
+
26
+	err = (&uuid).Scan([]byte(stringTest))
27
+	if err != nil {
28
+		t.Fatal(err)
29
+	}
30
+
31
+	err = (&uuid).Scan(byteTest)
32
+	if err != nil {
33
+		t.Fatal(err)
34
+	}
35
+
36
+	// bad type tests
37
+
38
+	err = (&uuid).Scan(badTypeTest)
39
+	if err == nil {
40
+		t.Error("int correctly parsed and shouldn't have")
41
+	}
42
+	if !strings.Contains(err.Error(), "unable to scan type") {
43
+		t.Error("attempting to parse an int returned an incorrect error message")
44
+	}
45
+
46
+	// invalid/incomplete uuids
47
+
48
+	err = (&uuid).Scan(invalidTest)
49
+	if err == nil {
50
+		t.Error("invalid uuid was parsed without error")
51
+	}
52
+	if !strings.Contains(err.Error(), "invalid UUID") {
53
+		t.Error("attempting to parse an invalid UUID returned an incorrect error message")
54
+	}
55
+
56
+	err = (&uuid).Scan(byteTest[:len(byteTest)-2])
57
+	if err == nil {
58
+		t.Error("invalid byte uuid was parsed without error")
59
+	}
60
+	if !strings.Contains(err.Error(), "invalid UUID") {
61
+		t.Error("attempting to parse an invalid byte UUID returned an incorrect error message")
62
+	}
63
+
64
+	// empty tests
65
+
66
+	uuid = nil
67
+	var emptySlice []byte
68
+	err = (&uuid).Scan(emptySlice)
69
+	if err != nil {
70
+		t.Fatal(err)
71
+	}
72
+
73
+	if uuid != nil {
74
+		t.Error("UUID was not nil after scanning empty byte slice")
75
+	}
76
+
77
+	uuid = nil
78
+	var emptyString string
79
+	err = (&uuid).Scan(emptyString)
80
+	if err != nil {
81
+		t.Fatal(err)
82
+	}
83
+
84
+	if uuid != nil {
85
+		t.Error("UUID was not nil after scanning empty string")
86
+	}
87
+}
88
+
89
+func TestValue(t *testing.T) {
90
+	stringTest := "f47ac10b-58cc-0372-8567-0e02b2c3d479"
91
+	uuid := Parse(stringTest)
92
+	val, _ := uuid.Value()
93
+	if val != stringTest {
94
+		t.Error("Value() did not return expected string")
95
+	}
96
+}

+ 132
- 0
vendor/github.com/pborman/uuid/time.go View File

@@ -0,0 +1,132 @@
1
+// Copyright 2014 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
+	"sync"
10
+	"time"
11
+)
12
+
13
+// A Time represents a time as the number of 100's of nanoseconds since 15 Oct
14
+// 1582.
15
+type Time int64
16
+
17
+const (
18
+	lillian    = 2299160          // Julian day of 15 Oct 1582
19
+	unix       = 2440587          // Julian day of 1 Jan 1970
20
+	epoch      = unix - lillian   // Days between epochs
21
+	g1582      = epoch * 86400    // seconds between epochs
22
+	g1582ns100 = g1582 * 10000000 // 100s of a nanoseconds between epochs
23
+)
24
+
25
+var (
26
+	timeMu    sync.Mutex
27
+	lasttime  uint64 // last time we returned
28
+	clock_seq uint16 // clock sequence for this run
29
+
30
+	timeNow = time.Now // for testing
31
+)
32
+
33
+// UnixTime converts t the number of seconds and nanoseconds using the Unix
34
+// epoch of 1 Jan 1970.
35
+func (t Time) UnixTime() (sec, nsec int64) {
36
+	sec = int64(t - g1582ns100)
37
+	nsec = (sec % 10000000) * 100
38
+	sec /= 10000000
39
+	return sec, nsec
40
+}
41
+
42
+// GetTime returns the current Time (100s of nanoseconds since 15 Oct 1582) and
43
+// clock sequence as well as adjusting the clock sequence as needed.  An error
44
+// is returned if the current time cannot be determined.
45
+func GetTime() (Time, uint16, error) {
46
+	defer timeMu.Unlock()
47
+	timeMu.Lock()
48
+	return getTime()
49
+}
50
+
51
+func getTime() (Time, uint16, error) {
52
+	t := timeNow()
53
+
54
+	// If we don't have a clock sequence already, set one.
55
+	if clock_seq == 0 {
56
+		setClockSequence(-1)
57
+	}
58
+	now := uint64(t.UnixNano()/100) + g1582ns100
59
+
60
+	// If time has gone backwards with this clock sequence then we
61
+	// increment the clock sequence
62
+	if now <= lasttime {
63
+		clock_seq = ((clock_seq + 1) & 0x3fff) | 0x8000
64
+	}
65
+	lasttime = now
66
+	return Time(now), clock_seq, nil
67
+}
68
+
69
+// ClockSequence returns the current clock sequence, generating one if not
70
+// already set.  The clock sequence is only used for Version 1 UUIDs.
71
+//
72
+// The uuid package does not use global static storage for the clock sequence or
73
+// the last time a UUID was generated.  Unless SetClockSequence a new random
74
+// clock sequence is generated the first time a clock sequence is requested by
75
+// ClockSequence, GetTime, or NewUUID.  (section 4.2.1.1) sequence is generated
76
+// for
77
+func ClockSequence() int {
78
+	defer timeMu.Unlock()
79
+	timeMu.Lock()
80
+	return clockSequence()
81
+}
82
+
83
+func clockSequence() int {
84
+	if clock_seq == 0 {
85
+		setClockSequence(-1)
86
+	}
87
+	return int(clock_seq & 0x3fff)
88
+}
89
+
90
+// SetClockSeq sets the clock sequence to the lower 14 bits of seq.  Setting to
91
+// -1 causes a new sequence to be generated.
92
+func SetClockSequence(seq int) {
93
+	defer timeMu.Unlock()
94
+	timeMu.Lock()
95
+	setClockSequence(seq)
96
+}
97
+
98
+func setClockSequence(seq int) {
99
+	if seq == -1 {
100
+		var b [2]byte
101
+		randomBits(b[:]) // clock sequence
102
+		seq = int(b[0])<<8 | int(b[1])
103
+	}
104
+	old_seq := clock_seq
105
+	clock_seq = uint16(seq&0x3fff) | 0x8000 // Set our variant
106
+	if old_seq != clock_seq {
107
+		lasttime = 0
108
+	}
109
+}
110
+
111
+// Time returns the time in 100s of nanoseconds since 15 Oct 1582 encoded in
112
+// uuid.  It returns false if uuid is not valid.  The time is only well defined
113
+// for version 1 and 2 UUIDs.
114
+func (uuid UUID) Time() (Time, bool) {
115
+	if len(uuid) != 16 {
116
+		return 0, false
117
+	}
118
+	time := int64(binary.BigEndian.Uint32(uuid[0:4]))
119
+	time |= int64(binary.BigEndian.Uint16(uuid[4:6])) << 32
120
+	time |= int64(binary.BigEndian.Uint16(uuid[6:8])&0xfff) << 48
121
+	return Time(time), true
122
+}
123
+
124
+// ClockSequence returns the clock sequence encoded in uuid.  It returns false
125
+// if uuid is not valid.  The clock sequence is only well defined for version 1
126
+// and 2 UUIDs.
127
+func (uuid UUID) ClockSequence() (int, bool) {
128
+	if len(uuid) != 16 {
129
+		return 0, false
130
+	}
131
+	return int(binary.BigEndian.Uint16(uuid[8:10])) & 0x3fff, true
132
+}

+ 43
- 0
vendor/github.com/pborman/uuid/util.go View File

@@ -0,0 +1,43 @@
1
+// Copyright 2011 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
+	"io"
9
+)
10
+
11
+// randomBits completely fills slice b with random data.
12
+func randomBits(b []byte) {
13
+	if _, err := io.ReadFull(rander, b); err != nil {
14
+		panic(err.Error()) // rand should never fail
15
+	}
16
+}
17
+
18
+// xvalues returns the value of a byte as a hexadecimal digit or 255.
19
+var xvalues = [256]byte{
20
+	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
21
+	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
22
+	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
23
+	0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255, 255,
24
+	255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255,
25
+	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
26
+	255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255,
27
+	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
28
+	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
29
+	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
30
+	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
31
+	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
32
+	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
33
+	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
34
+	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
35
+	255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
36
+}
37
+
38
+// xtob converts the the first two hex bytes of x into a byte.
39
+func xtob(x string) (byte, bool) {
40
+	b1 := xvalues[x[0]]
41
+	b2 := xvalues[x[1]]
42
+	return (b1 << 4) | b2, b1 != 255 && b2 != 255
43
+}

+ 201
- 0
vendor/github.com/pborman/uuid/uuid.go View File

@@ -0,0 +1,201 @@
1
+// Copyright 2011 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
+	"bytes"
9
+	"crypto/rand"
10
+	"encoding/hex"
11
+	"fmt"
12
+	"io"
13
+	"strings"
14
+)
15
+
16
+// Array is a pass-by-value UUID that can be used as an effecient key in a map.
17
+type Array [16]byte
18
+
19
+// UUID converts uuid into a slice.
20
+func (uuid Array) UUID() UUID {
21
+	return uuid[:]
22
+}
23
+
24
+// String returns the string representation of uuid,
25
+// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
26
+func (uuid Array) String() string {
27
+	return uuid.UUID().String()
28
+}
29
+
30
+// A UUID is a 128 bit (16 byte) Universal Unique IDentifier as defined in RFC
31
+// 4122.
32
+type UUID []byte
33
+
34
+// A Version represents a UUIDs version.
35
+type Version byte
36
+
37
+// A Variant represents a UUIDs variant.
38
+type Variant byte
39
+
40
+// Constants returned by Variant.
41
+const (
42
+	Invalid   = Variant(iota) // Invalid UUID
43
+	RFC4122                   // The variant specified in RFC4122
44
+	Reserved                  // Reserved, NCS backward compatibility.
45
+	Microsoft                 // Reserved, Microsoft Corporation backward compatibility.
46
+	Future                    // Reserved for future definition.
47
+)
48
+
49
+var rander = rand.Reader // random function
50
+
51
+// New returns a new random (version 4) UUID as a string.  It is a convenience
52
+// function for NewRandom().String().
53
+func New() string {
54
+	return NewRandom().String()
55
+}
56
+
57
+// Parse decodes s into a UUID or returns nil.  Both the UUID form of
58
+// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx and
59
+// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx are decoded.
60
+func Parse(s string) UUID {
61
+	if len(s) == 36+9 {
62
+		if strings.ToLower(s[:9]) != "urn:uuid:" {
63
+			return nil
64
+		}
65
+		s = s[9:]
66
+	} else if len(s) != 36 {
67
+		return nil
68
+	}
69
+	if s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-' {
70
+		return nil
71
+	}
72
+	var uuid [16]byte
73
+	for i, x := range [16]int{
74
+		0, 2, 4, 6,
75
+		9, 11,
76
+		14, 16,
77
+		19, 21,
78
+		24, 26, 28, 30, 32, 34} {
79
+		if v, ok := xtob(s[x:]); !ok {
80
+			return nil
81
+		} else {
82
+			uuid[i] = v
83
+		}
84
+	}
85
+	return uuid[:]
86
+}
87
+
88
+// Equal returns true if uuid1 and uuid2 are equal.
89
+func Equal(uuid1, uuid2 UUID) bool {
90
+	return bytes.Equal(uuid1, uuid2)
91
+}
92
+
93
+// Array returns an array representation of uuid that can be used as a map key.
94
+// Array panics if uuid is not valid.
95
+func (uuid UUID) Array() Array {
96
+	if len(uuid) != 16 {
97
+		panic("invalid uuid")
98
+	}
99
+	var a Array
100
+	copy(a[:], uuid)
101
+	return a
102
+}
103
+
104
+// String returns the string form of uuid, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
105
+// , or "" if uuid is invalid.
106
+func (uuid UUID) String() string {
107
+	if len(uuid) != 16 {
108
+		return ""
109
+	}
110
+	var buf [36]byte
111
+	encodeHex(buf[:], uuid)
112
+	return string(buf[:])
113
+}
114
+
115
+// URN returns the RFC 2141 URN form of uuid,
116
+// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,  or "" if uuid is invalid.
117
+func (uuid UUID) URN() string {
118
+	if len(uuid) != 16 {
119
+		return ""
120
+	}
121
+	var buf [36 + 9]byte
122
+	copy(buf[:], "urn:uuid:")
123
+	encodeHex(buf[9:], uuid)
124
+	return string(buf[:])
125
+}
126
+
127
+func encodeHex(dst []byte, uuid UUID) {
128
+	hex.Encode(dst[:], uuid[:4])
129
+	dst[8] = '-'
130
+	hex.Encode(dst[9:13], uuid[4:6])
131
+	dst[13] = '-'
132
+	hex.Encode(dst[14:18], uuid[6:8])
133
+	dst[18] = '-'
134
+	hex.Encode(dst[19:23], uuid[8:10])
135
+	dst[23] = '-'
136
+	hex.Encode(dst[24:], uuid[10:])
137
+}
138
+
139
+// Variant returns the variant encoded in uuid.  It returns Invalid if
140
+// uuid is invalid.
141
+func (uuid UUID) Variant() Variant {
142
+	if len(uuid) != 16 {
143
+		return Invalid
144
+	}
145
+	switch {
146
+	case (uuid[8] & 0xc0) == 0x80:
147
+		return RFC4122
148
+	case (uuid[8] & 0xe0) == 0xc0:
149
+		return Microsoft
150
+	case (uuid[8] & 0xe0) == 0xe0:
151
+		return Future
152
+	default:
153
+		return Reserved
154
+	}
155
+}
156
+
157
+// Version returns the version of uuid.  It returns false if uuid is not
158
+// valid.
159
+func (uuid UUID) Version() (Version, bool) {
160
+	if len(uuid) != 16 {
161
+		return 0, false
162
+	}
163
+	return Version(uuid[6] >> 4), true
164
+}
165
+
166
+func (v Version) String() string {
167
+	if v > 15 {
168
+		return fmt.Sprintf("BAD_VERSION_%d", v)
169
+	}
170
+	return fmt.Sprintf("VERSION_%d", v)
171
+}
172
+
173
+func (v Variant) String() string {
174
+	switch v {
175
+	case RFC4122:
176
+		return "RFC4122"
177
+	case Reserved:
178
+		return "Reserved"
179
+	case Microsoft:
180
+		return "Microsoft"
181
+	case Future:
182
+		return "Future"
183
+	case Invalid:
184
+		return "Invalid"
185
+	}
186
+	return fmt.Sprintf("BadVariant%d", int(v))
187
+}
188
+
189
+// SetRand sets the random number generator to r, which implements io.Reader.
190
+// If r.Read returns an error when the package requests random data then
191
+// a panic will be issued.
192
+//
193
+// Calling SetRand with nil sets the random number generator to the default
194
+// generator.
195
+func SetRand(r io.Reader) {
196
+	if r == nil {
197
+		rander = rand.Reader
198
+		return
199
+	}
200
+	rander = r
201
+}

+ 543
- 0
vendor/github.com/pborman/uuid/uuid_test.go View File

@@ -0,0 +1,543 @@
1
+// Copyright 2011 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
+	"bytes"
9
+	"fmt"
10
+	"os"
11
+	"strings"
12
+	"testing"
13
+	"time"
14
+)
15
+
16
+type test struct {
17
+	in      string
18
+	version Version
19
+	variant Variant
20
+	isuuid  bool
21
+}
22
+
23
+var tests = []test{
24
+	{"f47ac10b-58cc-0372-8567-0e02b2c3d479", 0, RFC4122, true},
25
+	{"f47ac10b-58cc-1372-8567-0e02b2c3d479", 1, RFC4122, true},
26
+	{"f47ac10b-58cc-2372-8567-0e02b2c3d479", 2, RFC4122, true},
27
+	{"f47ac10b-58cc-3372-8567-0e02b2c3d479", 3, RFC4122, true},
28
+	{"f47ac10b-58cc-4372-8567-0e02b2c3d479", 4, RFC4122, true},
29
+	{"f47ac10b-58cc-5372-8567-0e02b2c3d479", 5, RFC4122, true},
30
+	{"f47ac10b-58cc-6372-8567-0e02b2c3d479", 6, RFC4122, true},
31
+	{"f47ac10b-58cc-7372-8567-0e02b2c3d479", 7, RFC4122, true},
32
+	{"f47ac10b-58cc-8372-8567-0e02b2c3d479", 8, RFC4122, true},
33
+	{"f47ac10b-58cc-9372-8567-0e02b2c3d479", 9, RFC4122, true},
34
+	{"f47ac10b-58cc-a372-8567-0e02b2c3d479", 10, RFC4122, true},
35
+	{"f47ac10b-58cc-b372-8567-0e02b2c3d479", 11, RFC4122, true},
36
+	{"f47ac10b-58cc-c372-8567-0e02b2c3d479", 12, RFC4122, true},
37
+	{"f47ac10b-58cc-d372-8567-0e02b2c3d479", 13, RFC4122, true},
38
+	{"f47ac10b-58cc-e372-8567-0e02b2c3d479", 14, RFC4122, true},
39
+	{"f47ac10b-58cc-f372-8567-0e02b2c3d479", 15, RFC4122, true},
40
+
41
+	{"urn:uuid:f47ac10b-58cc-4372-0567-0e02b2c3d479", 4, Reserved, true},
42
+	{"URN:UUID:f47ac10b-58cc-4372-0567-0e02b2c3d479", 4, Reserved, true},
43
+	{"f47ac10b-58cc-4372-0567-0e02b2c3d479", 4, Reserved, true},
44
+	{"f47ac10b-58cc-4372-1567-0e02b2c3d479", 4, Reserved, true},
45
+	{"f47ac10b-58cc-4372-2567-0e02b2c3d479", 4, Reserved, true},
46
+	{"f47ac10b-58cc-4372-3567-0e02b2c3d479", 4, Reserved, true},
47
+	{"f47ac10b-58cc-4372-4567-0e02b2c3d479", 4, Reserved, true},
48
+	{"f47ac10b-58cc-4372-5567-0e02b2c3d479", 4, Reserved, true},
49
+	{"f47ac10b-58cc-4372-6567-0e02b2c3d479", 4, Reserved, true},
50
+	{"f47ac10b-58cc-4372-7567-0e02b2c3d479", 4, Reserved, true},
51
+	{"f47ac10b-58cc-4372-8567-0e02b2c3d479", 4, RFC4122, true},
52
+	{"f47ac10b-58cc-4372-9567-0e02b2c3d479", 4, RFC4122, true},
53
+	{"f47ac10b-58cc-4372-a567-0e02b2c3d479", 4, RFC4122, true},
54
+	{"f47ac10b-58cc-4372-b567-0e02b2c3d479", 4, RFC4122, true},
55
+	{"f47ac10b-58cc-4372-c567-0e02b2c3d479", 4, Microsoft, true},
56
+	{"f47ac10b-58cc-4372-d567-0e02b2c3d479", 4, Microsoft, true},
57
+	{"f47ac10b-58cc-4372-e567-0e02b2c3d479", 4, Future, true},
58
+	{"f47ac10b-58cc-4372-f567-0e02b2c3d479", 4, Future, true},
59
+
60
+	{"f47ac10b158cc-5372-a567-0e02b2c3d479", 0, Invalid, false},
61
+	{"f47ac10b-58cc25372-a567-0e02b2c3d479", 0, Invalid, false},
62
+	{"f47ac10b-58cc-53723a567-0e02b2c3d479", 0, Invalid, false},
63
+	{"f47ac10b-58cc-5372-a56740e02b2c3d479", 0, Invalid, false},
64
+	{"f47ac10b-58cc-5372-a567-0e02-2c3d479", 0, Invalid, false},
65
+	{"g47ac10b-58cc-4372-a567-0e02b2c3d479", 0, Invalid, false},
66
+}
67
+
68
+var constants = []struct {
69
+	c    interface{}
70
+	name string
71
+}{
72
+	{Person, "Person"},
73
+	{Group, "Group"},
74
+	{Org, "Org"},
75
+	{Invalid, "Invalid"},
76
+	{RFC4122, "RFC4122"},
77
+	{Reserved, "Reserved"},
78
+	{Microsoft, "Microsoft"},
79
+	{Future, "Future"},
80
+	{Domain(17), "Domain17"},
81
+	{Variant(42), "BadVariant42"},
82
+}
83
+
84
+func testTest(t *testing.T, in string, tt test) {
85
+	uuid := Parse(in)
86
+	if ok := (uuid != nil); ok != tt.isuuid {
87
+		t.Errorf("Parse(%s) got %v expected %v\b", in, ok, tt.isuuid)
88
+	}
89
+	if uuid == nil {
90
+		return
91
+	}
92
+
93
+	if v := uuid.Variant(); v != tt.variant {
94
+		t.Errorf("Variant(%s) got %d expected %d\b", in, v, tt.variant)
95
+	}
96
+	if v, _ := uuid.Version(); v != tt.version {
97
+		t.Errorf("Version(%s) got %d expected %d\b", in, v, tt.version)
98
+	}
99
+}
100
+
101
+func TestUUID(t *testing.T) {
102
+	for _, tt := range tests {
103
+		testTest(t, tt.in, tt)
104
+		testTest(t, strings.ToUpper(tt.in), tt)
105
+	}
106
+}
107
+
108
+func TestConstants(t *testing.T) {
109
+	for x, tt := range constants {
110
+		v, ok := tt.c.(fmt.Stringer)
111
+		if !ok {
112
+			t.Errorf("%x: %v: not a stringer", x, v)
113
+		} else if s := v.String(); s != tt.name {
114
+			v, _ := tt.c.(int)
115
+			t.Errorf("%x: Constant %T:%d gives %q, expected %q", x, tt.c, v, s, tt.name)
116
+		}
117
+	}
118
+}
119
+
120
+func TestRandomUUID(t *testing.T) {
121
+	m := make(map[string]bool)
122
+	for x := 1; x < 32; x++ {
123
+		uuid := NewRandom()
124
+		s := uuid.String()
125
+		if m[s] {
126
+			t.Errorf("NewRandom returned duplicated UUID %s", s)
127
+		}
128
+		m[s] = true
129
+		if v, _ := uuid.Version(); v != 4 {
130
+			t.Errorf("Random UUID of version %s", v)
131
+		}
132
+		if uuid.Variant() != RFC4122 {
133
+			t.Errorf("Random UUID is variant %d", uuid.Variant())
134
+		}
135
+	}
136
+}
137
+
138
+func TestNew(t *testing.T) {
139
+	m := make(map[string]bool)
140
+	for x := 1; x < 32; x++ {
141
+		s := New()
142
+		if m[s] {
143
+			t.Errorf("New returned duplicated UUID %s", s)
144
+		}
145
+		m[s] = true
146
+		uuid := Parse(s)
147
+		if uuid == nil {
148
+			t.Errorf("New returned %q which does not decode", s)
149
+			continue
150
+		}
151
+		if v, _ := uuid.Version(); v != 4 {
152
+			t.Errorf("Random UUID of version %s", v)
153
+		}
154
+		if uuid.Variant() != RFC4122 {
155
+			t.Errorf("Random UUID is variant %d", uuid.Variant())
156
+		}
157
+	}
158
+}
159
+
160
+func clockSeq(t *testing.T, uuid UUID) int {
161
+	seq, ok := uuid.ClockSequence()
162
+	if !ok {
163
+		t.Fatalf("%s: invalid clock sequence", uuid)
164
+	}
165
+	return seq
166
+}
167
+
168
+func TestClockSeq(t *testing.T) {
169
+	// Fake time.Now for this test to return a monotonically advancing time; restore it at end.
170
+	defer func(orig func() time.Time) { timeNow = orig }(timeNow)
171
+	monTime := time.Now()
172
+	timeNow = func() time.Time {
173
+		monTime = monTime.Add(1 * time.Second)
174
+		return monTime
175
+	}
176
+
177
+	SetClockSequence(-1)
178
+	uuid1 := NewUUID()
179
+	uuid2 := NewUUID()
180
+
181
+	if clockSeq(t, uuid1) != clockSeq(t, uuid2) {
182
+		t.Errorf("clock sequence %d != %d", clockSeq(t, uuid1), clockSeq(t, uuid2))
183
+	}
184
+
185
+	SetClockSequence(-1)
186
+	uuid2 = NewUUID()
187
+
188
+	// Just on the very off chance we generated the same sequence
189
+	// two times we try again.
190
+	if clockSeq(t, uuid1) == clockSeq(t, uuid2) {
191
+		SetClockSequence(-1)
192
+		uuid2 = NewUUID()
193
+	}
194
+	if clockSeq(t, uuid1) == clockSeq(t, uuid2) {
195
+		t.Errorf("Duplicate clock sequence %d", clockSeq(t, uuid1))
196
+	}
197
+
198
+	SetClockSequence(0x1234)
199
+	uuid1 = NewUUID()
200
+	if seq := clockSeq(t, uuid1); seq != 0x1234 {
201
+		t.Errorf("%s: expected seq 0x1234 got 0x%04x", uuid1, seq)
202
+	}
203
+}
204
+
205
+func TestCoding(t *testing.T) {
206
+	text := "7d444840-9dc0-11d1-b245-5ffdce74fad2"
207
+	urn := "urn:uuid:7d444840-9dc0-11d1-b245-5ffdce74fad2"
208
+	data := UUID{
209
+		0x7d, 0x44, 0x48, 0x40,
210
+		0x9d, 0xc0,
211
+		0x11, 0xd1,
212
+		0xb2, 0x45,
213
+		0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2,
214
+	}
215
+	if v := data.String(); v != text {
216
+		t.Errorf("%x: encoded to %s, expected %s", data, v, text)
217
+	}
218
+	if v := data.URN(); v != urn {
219
+		t.Errorf("%x: urn is %s, expected %s", data, v, urn)
220
+	}
221
+
222
+	uuid := Parse(text)
223
+	if !Equal(uuid, data) {
224
+		t.Errorf("%s: decoded to %s, expected %s", text, uuid, data)
225
+	}
226
+}
227
+
228
+func TestVersion1(t *testing.T) {
229
+	uuid1 := NewUUID()
230
+	uuid2 := NewUUID()
231
+
232
+	if Equal(uuid1, uuid2) {
233
+		t.Errorf("%s:duplicate uuid", uuid1)
234
+	}
235
+	if v, _ := uuid1.Version(); v != 1 {
236
+		t.Errorf("%s: version %s expected 1", uuid1, v)
237
+	}
238
+	if v, _ := uuid2.Version(); v != 1 {
239
+		t.Errorf("%s: version %s expected 1", uuid2, v)
240
+	}
241
+	n1 := uuid1.NodeID()
242
+	n2 := uuid2.NodeID()
243
+	if !bytes.Equal(n1, n2) {
244
+		t.Errorf("Different nodes %x != %x", n1, n2)
245
+	}
246
+	t1, ok := uuid1.Time()
247
+	if !ok {
248
+		t.Errorf("%s: invalid time", uuid1)
249
+	}
250
+	t2, ok := uuid2.Time()
251
+	if !ok {
252
+		t.Errorf("%s: invalid time", uuid2)
253
+	}
254
+	q1, ok := uuid1.ClockSequence()
255
+	if !ok {
256
+		t.Errorf("%s: invalid clock sequence", uuid1)
257
+	}
258
+	q2, ok := uuid2.ClockSequence()
259
+	if !ok {
260
+		t.Errorf("%s: invalid clock sequence", uuid2)
261
+	}
262
+
263
+	switch {
264
+	case t1 == t2 && q1 == q2:
265
+		t.Error("time stopped")
266
+	case t1 > t2 && q1 == q2:
267
+		t.Error("time reversed")
268
+	case t1 < t2 && q1 != q2:
269
+		t.Error("clock sequence chaned unexpectedly")
270
+	}
271
+}
272
+
273
+func TestNode(t *testing.T) {
274
+	// This test is mostly to make sure we don't leave nodeMu locked.
275
+	ifname = ""
276
+	if ni := NodeInterface(); ni != "" {
277
+		t.Errorf("NodeInterface got %q, want %q", ni, "")
278
+	}
279
+	if SetNodeInterface("xyzzy") {
280
+		t.Error("SetNodeInterface succeeded on a bad interface name")
281
+	}
282
+	if !SetNodeInterface("") {
283
+		t.Error("SetNodeInterface failed")
284
+	}
285
+	if ni := NodeInterface(); ni == "" {
286
+		t.Error("NodeInterface returned an empty string")
287
+	}
288
+
289
+	ni := NodeID()
290
+	if len(ni) != 6 {
291
+		t.Errorf("ni got %d bytes, want 6", len(ni))
292
+	}
293
+	hasData := false
294
+	for _, b := range ni {
295
+		if b != 0 {
296
+			hasData = true
297
+		}
298
+	}
299
+	if !hasData {
300
+		t.Error("nodeid is all zeros")
301
+	}
302
+
303
+	id := []byte{1, 2, 3, 4, 5, 6, 7, 8}
304
+	SetNodeID(id)
305
+	ni = NodeID()
306
+	if !bytes.Equal(ni, id[:6]) {
307
+		t.Errorf("got nodeid %v, want %v", ni, id[:6])
308
+	}
309
+
310
+	if ni := NodeInterface(); ni != "user" {
311
+		t.Errorf("got inteface %q, want %q", ni, "user")
312
+	}
313
+}
314
+
315
+func TestNodeAndTime(t *testing.T) {
316
+	// Time is February 5, 1998 12:30:23.136364800 AM GMT
317
+
318
+	uuid := Parse("7d444840-9dc0-11d1-b245-5ffdce74fad2")
319
+	node := []byte{0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2}
320
+
321
+	ts, ok := uuid.Time()
322
+	if ok {
323
+		c := time.Unix(ts.UnixTime())
324
+		want := time.Date(1998, 2, 5, 0, 30, 23, 136364800, time.UTC)
325
+		if !c.Equal(want) {
326
+			t.Errorf("Got time %v, want %v", c, want)
327
+		}
328
+	} else {
329
+		t.Errorf("%s: bad time", uuid)
330
+	}
331
+	if !bytes.Equal(node, uuid.NodeID()) {
332
+		t.Errorf("Expected node %v got %v", node, uuid.NodeID())
333
+	}
334
+}
335
+
336
+func TestMD5(t *testing.T) {
337
+	uuid := NewMD5(NameSpace_DNS, []byte("python.org")).String()
338
+	want := "6fa459ea-ee8a-3ca4-894e-db77e160355e"
339
+	if uuid != want {
340
+		t.Errorf("MD5: got %q expected %q", uuid, want)
341
+	}
342
+}
343
+
344
+func TestSHA1(t *testing.T) {
345
+	uuid := NewSHA1(NameSpace_DNS, []byte("python.org")).String()
346
+	want := "886313e1-3b8a-5372-9b90-0c9aee199e5d"
347
+	if uuid != want {
348
+		t.Errorf("SHA1: got %q expected %q", uuid, want)
349
+	}
350
+}
351
+
352
+func TestNodeID(t *testing.T) {
353
+	nid := []byte{1, 2, 3, 4, 5, 6}
354
+	SetNodeInterface("")
355
+	s := NodeInterface()
356
+	if s == "" || s == "user" {
357
+		t.Errorf("NodeInterface %q after SetInteface", s)
358
+	}
359
+	node1 := NodeID()
360
+	if node1 == nil {
361
+		t.Error("NodeID nil after SetNodeInterface", s)
362
+	}
363
+	SetNodeID(nid)
364
+	s = NodeInterface()
365
+	if s != "user" {
366
+		t.Errorf("Expected NodeInterface %q got %q", "user", s)
367
+	}
368
+	node2 := NodeID()
369
+	if node2 == nil {
370
+		t.Error("NodeID nil after SetNodeID", s)
371
+	}
372
+	if bytes.Equal(node1, node2) {
373
+		t.Error("NodeID not changed after SetNodeID", s)
374
+	} else if !bytes.Equal(nid, node2) {
375
+		t.Errorf("NodeID is %x, expected %x", node2, nid)
376
+	}
377
+}
378
+
379
+func testDCE(t *testing.T, name string, uuid UUID, domain Domain, id uint32) {
380
+	if uuid == nil {
381
+		t.Errorf("%s failed", name)
382
+		return
383
+	}
384
+	if v, _ := uuid.Version(); v != 2 {
385
+		t.Errorf("%s: %s: expected version 2, got %s", name, uuid, v)
386
+		return
387
+	}
388
+	if v, ok := uuid.Domain(); !ok || v != domain {
389
+		if !ok {
390
+			t.Errorf("%s: %d: Domain failed", name, uuid)
391
+		} else {
392
+			t.Errorf("%s: %s: expected domain %d, got %d", name, uuid, domain, v)
393
+		}
394
+	}
395
+	if v, ok := uuid.Id(); !ok || v != id {
396
+		if !ok {
397
+			t.Errorf("%s: %d: Id failed", name, uuid)
398
+		} else {
399
+			t.Errorf("%s: %s: expected id %d, got %d", name, uuid, id, v)
400
+		}
401
+	}
402
+}
403
+
404
+func TestDCE(t *testing.T) {
405
+	testDCE(t, "NewDCESecurity", NewDCESecurity(42, 12345678), 42, 12345678)
406
+	testDCE(t, "NewDCEPerson", NewDCEPerson(), Person, uint32(os.Getuid()))
407
+	testDCE(t, "NewDCEGroup", NewDCEGroup(), Group, uint32(os.Getgid()))
408
+}
409
+
410
+type badRand struct{}
411
+
412
+func (r badRand) Read(buf []byte) (int, error) {
413
+	for i, _ := range buf {
414
+		buf[i] = byte(i)
415
+	}
416
+	return len(buf), nil
417
+}
418
+
419
+func TestBadRand(t *testing.T) {
420
+	SetRand(badRand{})
421
+	uuid1 := New()
422
+	uuid2 := New()
423
+	if uuid1 != uuid2 {
424
+		t.Errorf("expected duplicates, got %q and %q", uuid1, uuid2)
425
+	}
426
+	SetRand(nil)
427
+	uuid1 = New()
428
+	uuid2 = New()
429
+	if uuid1 == uuid2 {
430
+		t.Errorf("unexpected duplicates, got %q", uuid1)
431
+	}
432
+}
433
+
434
+func TestUUID_Array(t *testing.T) {
435
+	expect := Array{
436
+		0xf4, 0x7a, 0xc1, 0x0b,
437
+		0x58, 0xcc,
438
+		0x03, 0x72,
439
+		0x85, 0x67,
440
+		0x0e, 0x02, 0xb2, 0xc3, 0xd4, 0x79,
441
+	}
442
+	uuid := Parse("f47ac10b-58cc-0372-8567-0e02b2c3d479")
443
+	if uuid == nil {
444
+		t.Fatal("invalid uuid")
445
+	}
446
+	if uuid.Array() != expect {
447
+		t.Fatal("invalid array")
448
+	}
449
+}
450
+
451
+func TestArray_UUID(t *testing.T) {
452
+	array := Array{
453
+		0xf4, 0x7a, 0xc1, 0x0b,
454
+		0x58, 0xcc,
455
+		0x03, 0x72,
456
+		0x85, 0x67,
457
+		0x0e, 0x02, 0xb2, 0xc3, 0xd4, 0x79,
458
+	}
459
+	expect := Parse("f47ac10b-58cc-0372-8567-0e02b2c3d479")
460
+	if expect == nil {
461
+		t.Fatal("invalid uuid")
462
+	}
463
+	if !bytes.Equal(array.UUID(), expect) {
464
+		t.Fatal("invalid uuid")
465
+	}
466
+}
467
+
468
+func BenchmarkParse(b *testing.B) {
469
+	for i := 0; i < b.N; i++ {
470
+		uuid := Parse("f47ac10b-58cc-0372-8567-0e02b2c3d479")
471
+		if uuid == nil {
472
+			b.Fatal("invalid uuid")
473
+		}
474
+	}
475
+}
476
+
477
+func BenchmarkNew(b *testing.B) {
478
+	for i := 0; i < b.N; i++ {
479
+		New()
480
+	}
481
+}
482
+
483
+func BenchmarkUUID_String(b *testing.B) {
484
+	uuid := Parse("f47ac10b-58cc-0372-8567-0e02b2c3d479")
485
+	if uuid == nil {
486
+		b.Fatal("invalid uuid")
487
+	}
488
+	for i := 0; i < b.N; i++ {
489
+		if uuid.String() == "" {
490
+			b.Fatal("invalid uuid")
491
+		}
492
+	}
493
+}
494
+
495
+func BenchmarkUUID_URN(b *testing.B) {
496
+	uuid := Parse("f47ac10b-58cc-0372-8567-0e02b2c3d479")
497
+	if uuid == nil {
498
+		b.Fatal("invalid uuid")
499
+	}
500
+	for i := 0; i < b.N; i++ {
501
+		if uuid.URN() == "" {
502
+			b.Fatal("invalid uuid")
503
+		}
504
+	}
505
+}
506
+
507
+func BenchmarkUUID_Array(b *testing.B) {
508
+	expect := Array{
509
+		0xf4, 0x7a, 0xc1, 0x0b,
510
+		0x58, 0xcc,
511
+		0x03, 0x72,
512
+		0x85, 0x67,
513
+		0x0e, 0x02, 0xb2, 0xc3, 0xd4, 0x79,
514
+	}
515
+	uuid := Parse("f47ac10b-58cc-0372-8567-0e02b2c3d479")
516
+	if uuid == nil {
517
+		b.Fatal("invalid uuid")
518
+	}
519
+	for i := 0; i < b.N; i++ {
520
+		if uuid.Array() != expect {
521
+			b.Fatal("invalid array")
522
+		}
523
+	}
524
+}
525
+
526
+func BenchmarkArray_UUID(b *testing.B) {
527
+	array := Array{
528
+		0xf4, 0x7a, 0xc1, 0x0b,
529
+		0x58, 0xcc,
530
+		0x03, 0x72,
531
+		0x85, 0x67,
532
+		0x0e, 0x02, 0xb2, 0xc3, 0xd4, 0x79,
533
+	}
534
+	expect := Parse("f47ac10b-58cc-0372-8567-0e02b2c3d479")
535
+	if expect == nil {
536
+		b.Fatal("invalid uuid")
537
+	}
538
+	for i := 0; i < b.N; i++ {
539
+		if !bytes.Equal(array.UUID(), expect) {
540
+			b.Fatal("invalid uuid")
541
+		}
542
+	}
543
+}

+ 41
- 0
vendor/github.com/pborman/uuid/version1.go View File

@@ -0,0 +1,41 @@
1
+// Copyright 2011 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
+)
10
+
11
+// NewUUID returns a Version 1 UUID based on the current NodeID and clock
12
+// sequence, and the current time.  If the NodeID has not been set by SetNodeID
13
+// or SetNodeInterface then it will be set automatically.  If the NodeID cannot
14
+// be set NewUUID returns nil.  If clock sequence has not been set by
15
+// SetClockSequence then it will be set automatically.  If GetTime fails to
16
+// return the current NewUUID returns nil.
17
+func NewUUID() UUID {
18
+	if nodeID == nil {
19
+		SetNodeInterface("")
20
+	}
21
+
22
+	now, seq, err := GetTime()
23
+	if err != nil {
24
+		return nil
25
+	}
26
+
27
+	uuid := make([]byte, 16)
28
+
29
+	time_low := uint32(now & 0xffffffff)
30
+	time_mid := uint16((now >> 32) & 0xffff)
31
+	time_hi := uint16((now >> 48) & 0x0fff)
32
+	time_hi |= 0x1000 // Version 1
33
+
34
+	binary.BigEndian.PutUint32(uuid[0:], time_low)
35
+	binary.BigEndian.PutUint16(uuid[4:], time_mid)
36
+	binary.BigEndian.PutUint16(uuid[6:], time_hi)
37
+	binary.BigEndian.PutUint16(uuid[8:], seq)
38
+	copy(uuid[10:], nodeID)
39
+
40
+	return uuid
41
+}

+ 25
- 0
vendor/github.com/pborman/uuid/version4.go View File

@@ -0,0 +1,25 @@
1
+// Copyright 2011 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
+// Random returns a Random (Version 4) UUID or panics.
8
+//
9
+// The strength of the UUIDs is based on the strength of the crypto/rand
10
+// package.
11
+//
12
+// A note about uniqueness derived from from the UUID Wikipedia entry:
13
+//
14
+//  Randomly generated UUIDs have 122 random bits.  One's annual risk of being
15
+//  hit by a meteorite is estimated to be one chance in 17 billion, that
16
+//  means the probability is about 0.00000000006 (6 × 10−11),
17
+//  equivalent to the odds of creating a few tens of trillions of UUIDs in a
18
+//  year and having one duplicate.
19
+func NewRandom() UUID {
20
+	uuid := make([]byte, 16)
21
+	randomBits([]byte(uuid))
22
+	uuid[6] = (uuid[6] & 0x0f) | 0x40 // Version 4
23
+	uuid[8] = (uuid[8] & 0x3f) | 0x80 // Variant is 10
24
+	return uuid
25
+}

Loading…
Cancel
Save