@cryptotaxi247 / kubo / commits / 46db9de2d

godeps: drop uuid from code.google.com

Henry committed May 30, 2015 at 02:54 UTC 46db9de2d9f425b2f007acbfc5a156a1c8a7be5c
24 files changed +1105 -1212
Godeps/Godeps.json
+5 -6
@@ -9,11 +9,6 @@
9 "ImportPath": "bazil.org/fuse",
10 "Rev": "e4fcc9a2c7567d1c42861deebeb483315d222262"
11 },
12 - {
13 - "ImportPath": "code.google.com/p/go-uuid/uuid",
14 - "Comment": "null-15",
15 - "Rev": "35bc42037350f0078e3c974c6ea690f1926603ab"
16 - },
12 {
13 "ImportPath": "github.com/ActiveState/tail",
14 "Rev": "068b72961a6bc5b4a82cf4fc14ccc724c0cfa73a"
@@ -131,7 +126,7 @@
126 },
127 {
128 "ImportPath": "github.com/jbenet/go-datastore",
134 - "Rev": "751a1b4ad40b27c3f0993ba5e2bcf22ad941991b"
129 + "Rev": "245a981af3750d7710db13dca731ba8461aa1095"
130 },
131 {
132 "ImportPath": "github.com/jbenet/go-detect-race",
@@ -215,6 +210,10 @@
210 "ImportPath": "github.com/rs/cors",
211 "Rev": "5e4ce6bc0ecd3472f6f943666d84876691be2ced"
212 },
213 + {
214 + "ImportPath": "github.com/satori/go.uuid",
215 + "Rev": "7c7f2020c4c9491594b85767967f4619c2fa75f9"
216 + },
217 {
218 "ImportPath": "github.com/steakknife/hamming",
219 "Comment": "0.0.10",
Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/LICENSE deleted
-27
@@ -1,27 +0,0 @@
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.
Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/dce.go deleted
-84
@@ -1,84 +0,0 @@
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 -}
Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/doc.go deleted
-8
@@ -1,8 +0,0 @@
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
Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/hash.go deleted
-53
@@ -1,53 +0,0 @@
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 dervied 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 -}
Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/json.go deleted
-30
@@ -1,30 +0,0 @@
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 "errors"
8 -
9 -func (u UUID) MarshalJSON() ([]byte, error) {
10 - if len(u) == 0 {
11 - return []byte(`""`), nil
12 - }
13 - return []byte(`"` + u.String() + `"`), nil
14 -}
15 -
16 -func (u *UUID) UnmarshalJSON(data []byte) error {
17 - if len(data) == 0 || string(data) == `""` {
18 - return nil
19 - }
20 - if len(data) < 2 || data[0] != '"' || data[len(data)-1] != '"' {
21 - return errors.New("invalid UUID format")
22 - }
23 - data = data[1 : len(data)-1]
24 - uu := Parse(string(data))
25 - if uu == nil {
26 - return errors.New("invalid UUID format")
27 - }
28 - *u = uu
29 - return nil
30 -}
Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/json_test.go deleted
-32
@@ -1,32 +0,0 @@
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/json"
9 - "reflect"
10 - "testing"
11 -)
12 -
13 -var testUUID = Parse("f47ac10b-58cc-0372-8567-0e02b2c3d479")
14 -
15 -func TestJSON(t *testing.T) {
16 - type S struct {
17 - ID1 UUID
18 - ID2 UUID
19 - }
20 - s1 := S{ID1: testUUID}
21 - data, err := json.Marshal(&s1)
22 - if err != nil {
23 - t.Fatal(err)
24 - }
25 - var s2 S
26 - if err := json.Unmarshal(data, &s2); err != nil {
27 - t.Fatal(err)
28 - }
29 - if !reflect.DeepEqual(&s1, &s2) {
30 - t.Errorf("got %#v, want %#v", s2, s1)
31 - }
32 -}
Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/node.go deleted
-101
@@ -1,101 +0,0 @@
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 "net"
8 -
9 -var (
10 - interfaces []net.Interface // cached list of interfaces
11 - ifname string // name of interface being used
12 - nodeID []byte // hardware for version 1 UUIDs
13 -)
14 -
15 -// NodeInterface returns the name of the interface from which the NodeID was
16 -// derived. The interface "user" is returned if the NodeID was set by
17 -// SetNodeID.
18 -func NodeInterface() string {
19 - return ifname
20 -}
21 -
22 -// SetNodeInterface selects the hardware address to be used for Version 1 UUIDs.
23 -// If name is "" then the first usable interface found will be used or a random
24 -// Node ID will be generated. If a named interface cannot be found then false
25 -// is returned.
26 -//
27 -// SetNodeInterface never fails when name is "".
28 -func SetNodeInterface(name string) bool {
29 - if interfaces == nil {
30 - var err error
31 - interfaces, err = net.Interfaces()
32 - if err != nil && name != "" {
33 - return false
34 - }
35 - }
36 -
37 - for _, ifs := range interfaces {
38 - if len(ifs.HardwareAddr) >= 6 && (name == "" || name == ifs.Name) {
39 - if setNodeID(ifs.HardwareAddr) {
40 - ifname = ifs.Name
41 - return true
42 - }
43 - }
44 - }
45 -
46 - // We found no interfaces with a valid hardware address. If name
47 - // does not specify a specific interface generate a random Node ID
48 - // (section 4.1.6)
49 - if name == "" {
50 - if nodeID == nil {
51 - nodeID = make([]byte, 6)
52 - }
53 - randomBits(nodeID)
54 - return true
55 - }
56 - return false
57 -}
58 -
59 -// NodeID returns a slice of a copy of the current Node ID, setting the Node ID
60 -// if not already set.
61 -func NodeID() []byte {
62 - if nodeID == nil {
63 - SetNodeInterface("")
64 - }
65 - nid := make([]byte, 6)
66 - copy(nid, nodeID)
67 - return nid
68 -}
69 -
70 -// SetNodeID sets the Node ID to be used for Version 1 UUIDs. The first 6 bytes
71 -// of id are used. If id is less than 6 bytes then false is returned and the
72 -// Node ID is not set.
73 -func SetNodeID(id []byte) bool {
74 - if setNodeID(id) {
75 - ifname = "user"
76 - return true
77 - }
78 - return false
79 -}
80 -
81 -func setNodeID(id []byte) bool {
82 - if len(id) < 6 {
83 - return false
84 - }
85 - if nodeID == nil {
86 - nodeID = make([]byte, 6)
87 - }
88 - copy(nodeID, id)
89 - return true
90 -}
91 -
92 -// NodeID returns the 6 byte node id encoded in uuid. It returns nil if uuid is
93 -// not valid. The NodeID is only well defined for version 1 and 2 UUIDs.
94 -func (uuid UUID) NodeID() []byte {
95 - if len(uuid) != 16 {
96 - return nil
97 - }
98 - node := make([]byte, 6)
99 - copy(node, uuid[10:])
100 - return node
101 -}
Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/seq_test.go deleted
-66
@@ -1,66 +0,0 @@
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 -}
Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/time.go deleted
-132
@@ -1,132 +0,0 @@
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 - mu 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 mu.Unlock()
47 - mu.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 mu.Unlock()
79 - mu.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 mu.Unlock()
94 - mu.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 -}
Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/util.go deleted
-43
@@ -1,43 +0,0 @@
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 = []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 -}
Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/uuid.go deleted
-163
@@ -1,163 +0,0 @@
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 - "fmt"
11 - "io"
12 - "strings"
13 -)
14 -
15 -// A UUID is a 128 bit (16 byte) Universal Unique IDentifier as defined in RFC
16 -// 4122.
17 -type UUID []byte
18 -
19 -// A Version represents a UUIDs version.
20 -type Version byte
21 -
22 -// A Variant represents a UUIDs variant.
23 -type Variant byte
24 -
25 -// Constants returned by Variant.
26 -const (
27 - Invalid = Variant(iota) // Invalid UUID
28 - RFC4122 // The variant specified in RFC4122
29 - Reserved // Reserved, NCS backward compatibility.
30 - Microsoft // Reserved, Microsoft Corporation backward compatibility.
31 - Future // Reserved for future definition.
32 -)
33 -
34 -var rander = rand.Reader // random function
35 -
36 -// New returns a new random (version 4) UUID as a string. It is a convenience
37 -// function for NewRandom().String().
38 -func New() string {
39 - return NewRandom().String()
40 -}
41 -
42 -// Parse decodes s into a UUID or returns nil. Both the UUID form of
43 -// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx and
44 -// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx are decoded.
45 -func Parse(s string) UUID {
46 - if len(s) == 36+9 {
47 - if strings.ToLower(s[:9]) != "urn:uuid:" {
48 - return nil
49 - }
50 - s = s[9:]
51 - } else if len(s) != 36 {
52 - return nil
53 - }
54 - if s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-' {
55 - return nil
56 - }
57 - uuid := make([]byte, 16)
58 - for i, x := range []int{
59 - 0, 2, 4, 6,
60 - 9, 11,
61 - 14, 16,
62 - 19, 21,
63 - 24, 26, 28, 30, 32, 34} {
64 - if v, ok := xtob(s[x:]); !ok {
65 - return nil
66 - } else {
67 - uuid[i] = v
68 - }
69 - }
70 - return uuid
71 -}
72 -
73 -// Equal returns true if uuid1 and uuid2 are equal.
74 -func Equal(uuid1, uuid2 UUID) bool {
75 - return bytes.Equal(uuid1, uuid2)
76 -}
77 -
78 -// String returns the string form of uuid, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
79 -// , or "" if uuid is invalid.
80 -func (uuid UUID) String() string {
81 - if uuid == nil || len(uuid) != 16 {
82 - return ""
83 - }
84 - b := []byte(uuid)
85 - return fmt.Sprintf("%08x-%04x-%04x-%04x-%012x",
86 - b[:4], b[4:6], b[6:8], b[8:10], b[10:])
87 -}
88 -
89 -// URN returns the RFC 2141 URN form of uuid,
90 -// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, or "" if uuid is invalid.
91 -func (uuid UUID) URN() string {
92 - if uuid == nil || len(uuid) != 16 {
93 - return ""
94 - }
95 - b := []byte(uuid)
96 - return fmt.Sprintf("urn:uuid:%08x-%04x-%04x-%04x-%012x",
97 - b[:4], b[4:6], b[6:8], b[8:10], b[10:])
98 -}
99 -
100 -// Variant returns the variant encoded in uuid. It returns Invalid if
101 -// uuid is invalid.
102 -func (uuid UUID) Variant() Variant {
103 - if len(uuid) != 16 {
104 - return Invalid
105 - }
106 - switch {
107 - case (uuid[8] & 0xc0) == 0x80:
108 - return RFC4122
109 - case (uuid[8] & 0xe0) == 0xc0:
110 - return Microsoft
111 - case (uuid[8] & 0xe0) == 0xe0:
112 - return Future
113 - default:
114 - return Reserved
115 - }
116 - panic("unreachable")
117 -}
118 -
119 -// Version returns the verison of uuid. It returns false if uuid is not
120 -// valid.
121 -func (uuid UUID) Version() (Version, bool) {
122 - if len(uuid) != 16 {
123 - return 0, false
124 - }
125 - return Version(uuid[6] >> 4), true
126 -}
127 -
128 -func (v Version) String() string {
129 - if v > 15 {
130 - return fmt.Sprintf("BAD_VERSION_%d", v)
131 - }
132 - return fmt.Sprintf("VERSION_%d", v)
133 -}
134 -
135 -func (v Variant) String() string {
136 - switch v {
137 - case RFC4122:
138 - return "RFC4122"
139 - case Reserved:
140 - return "Reserved"
141 - case Microsoft:
142 - return "Microsoft"
143 - case Future:
144 - return "Future"
145 - case Invalid:
146 - return "Invalid"
147 - }
148 - return fmt.Sprintf("BadVariant%d", int(v))
149 -}
150 -
151 -// SetRand sets the random number generator to r, which implents io.Reader.
152 -// If r.Read returns an error when the package requests random data then
153 -// a panic will be issued.
154 -//
155 -// Calling SetRand with nil sets the random number generator to the default
156 -// generator.
157 -func SetRand(r io.Reader) {
158 - if r == nil {
159 - rander = rand.Reader
160 - return
161 - }
162 - rander = r
163 -}
Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/uuid_test.go deleted
-390
@@ -1,390 +0,0 @@
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\n", 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\n", s)
127 - }
128 - m[s] = true
129 - if v, _ := uuid.Version(); v != 4 {
130 - t.Errorf("Random UUID of version %s\n", v)
131 - }
132 - if uuid.Variant() != RFC4122 {
133 - t.Errorf("Random UUID is variant %d\n", 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\n", s)
144 - }
145 - m[s] = true
146 - uuid := Parse(s)
147 - if uuid == nil {
148 - t.Errorf("New returned %q which does not decode\n", s)
149 - continue
150 - }
151 - if v, _ := uuid.Version(); v != 4 {
152 - t.Errorf("Random UUID of version %s\n", v)
153 - }
154 - if uuid.Variant() != RFC4122 {
155 - t.Errorf("Random UUID is variant %d\n", 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\n", 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\n", 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\n", 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\n", 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\n", data, v, text)
217 - }
218 - if v := data.URN(); v != urn {
219 - t.Errorf("%x: urn is %s, expected %s\n", data, v, urn)
220 - }
221 -
222 - uuid := Parse(text)
223 - if !Equal(uuid, data) {
224 - t.Errorf("%s: decoded to %s, expected %s\n", 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\n", uuid1)
234 - }
235 - if v, _ := uuid1.Version(); v != 1 {
236 - t.Errorf("%s: version %s expected 1\n", uuid1, v)
237 - }
238 - if v, _ := uuid2.Version(); v != 1 {
239 - t.Errorf("%s: version %s expected 1\n", uuid2, v)
240 - }
241 - n1 := uuid1.NodeID()
242 - n2 := uuid2.NodeID()
243 - if !bytes.Equal(n1, n2) {
244 - t.Errorf("Different nodes %x != %x\n", n1, n2)
245 - }
246 - t1, ok := uuid1.Time()
247 - if !ok {
248 - t.Errorf("%s: invalid time\n", uuid1)
249 - }
250 - t2, ok := uuid2.Time()
251 - if !ok {
252 - t.Errorf("%s: invalid time\n", uuid2)
253 - }
254 - q1, ok := uuid1.ClockSequence()
255 - if !ok {
256 - t.Errorf("%s: invalid clock sequence\n", 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.Errorf("time stopped\n")
266 - case t1 > t2 && q1 == q2:
267 - t.Errorf("time reversed\n")
268 - case t1 < t2 && q1 != q2:
269 - t.Errorf("clock sequence chaned unexpectedly\n")
270 - }
271 -}
272 -
273 -func TestNodeAndTime(t *testing.T) {
274 - // Time is February 5, 1998 12:30:23.136364800 AM GMT
275 -
276 - uuid := Parse("7d444840-9dc0-11d1-b245-5ffdce74fad2")
277 - node := []byte{0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2}
278 -
279 - ts, ok := uuid.Time()
280 - if ok {
281 - c := time.Unix(ts.UnixTime())
282 - want := time.Date(1998, 2, 5, 0, 30, 23, 136364800, time.UTC)
283 - if !c.Equal(want) {
284 - t.Errorf("Got time %v, want %v", c, want)
285 - }
286 - } else {
287 - t.Errorf("%s: bad time\n", uuid)
288 - }
289 - if !bytes.Equal(node, uuid.NodeID()) {
290 - t.Errorf("Expected node %v got %v\n", node, uuid.NodeID())
291 - }
292 -}
293 -
294 -func TestMD5(t *testing.T) {
295 - uuid := NewMD5(NameSpace_DNS, []byte("python.org")).String()
296 - want := "6fa459ea-ee8a-3ca4-894e-db77e160355e"
297 - if uuid != want {
298 - t.Errorf("MD5: got %q expected %q\n", uuid, want)
299 - }
300 -}
301 -
302 -func TestSHA1(t *testing.T) {
303 - uuid := NewSHA1(NameSpace_DNS, []byte("python.org")).String()
304 - want := "886313e1-3b8a-5372-9b90-0c9aee199e5d"
305 - if uuid != want {
306 - t.Errorf("SHA1: got %q expected %q\n", uuid, want)
307 - }
308 -}
309 -
310 -func TestNodeID(t *testing.T) {
311 - nid := []byte{1, 2, 3, 4, 5, 6}
312 - SetNodeInterface("")
313 - s := NodeInterface()
314 - if s == "" || s == "user" {
315 - t.Errorf("NodeInterface %q after SetInteface\n", s)
316 - }
317 - node1 := NodeID()
318 - if node1 == nil {
319 - t.Errorf("NodeID nil after SetNodeInterface\n", s)
320 - }
321 - SetNodeID(nid)
322 - s = NodeInterface()
323 - if s != "user" {
324 - t.Errorf("Expected NodeInterface %q got %q\n", "user", s)
325 - }
326 - node2 := NodeID()
327 - if node2 == nil {
328 - t.Errorf("NodeID nil after SetNodeID\n", s)
329 - }
330 - if bytes.Equal(node1, node2) {
331 - t.Errorf("NodeID not changed after SetNodeID\n", s)
332 - } else if !bytes.Equal(nid, node2) {
333 - t.Errorf("NodeID is %x, expected %x\n", node2, nid)
334 - }
335 -}
336 -
337 -func testDCE(t *testing.T, name string, uuid UUID, domain Domain, id uint32) {
338 - if uuid == nil {
339 - t.Errorf("%s failed\n", name)
340 - return
341 - }
342 - if v, _ := uuid.Version(); v != 2 {
343 - t.Errorf("%s: %s: expected version 2, got %s\n", name, uuid, v)
344 - return
345 - }
346 - if v, ok := uuid.Domain(); !ok || v != domain {
347 - if !ok {
348 - t.Errorf("%s: %d: Domain failed\n", name, uuid)
349 - } else {
350 - t.Errorf("%s: %s: expected domain %d, got %d\n", name, uuid, domain, v)
351 - }
352 - }
353 - if v, ok := uuid.Id(); !ok || v != id {
354 - if !ok {
355 - t.Errorf("%s: %d: Id failed\n", name, uuid)
356 - } else {
357 - t.Errorf("%s: %s: expected id %d, got %d\n", name, uuid, id, v)
358 - }
359 - }
360 -}
361 -
362 -func TestDCE(t *testing.T) {
363 - testDCE(t, "NewDCESecurity", NewDCESecurity(42, 12345678), 42, 12345678)
364 - testDCE(t, "NewDCEPerson", NewDCEPerson(), Person, uint32(os.Getuid()))
365 - testDCE(t, "NewDCEGroup", NewDCEGroup(), Group, uint32(os.Getgid()))
366 -}
367 -
368 -type badRand struct{}
369 -
370 -func (r badRand) Read(buf []byte) (int, error) {
371 - for i, _ := range buf {
372 - buf[i] = byte(i)
373 - }
374 - return len(buf), nil
375 -}
376 -
377 -func TestBadRand(t *testing.T) {
378 - SetRand(badRand{})
379 - uuid1 := New()
380 - uuid2 := New()
381 - if uuid1 != uuid2 {
382 - t.Errorf("execpted duplicates, got %q and %q\n", uuid1, uuid2)
383 - }
384 - SetRand(nil)
385 - uuid1 = New()
386 - uuid2 = New()
387 - if uuid1 == uuid2 {
388 - t.Errorf("unexecpted duplicates, got %q\n", uuid1)
389 - }
390 -}
Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/version1.go deleted
-41
@@ -1,41 +0,0 @@
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 -}
Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/version4.go deleted
-25
@@ -1,25 +0,0 @@
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 -}
Godeps/_workspace/src/github.com/jbenet/go-datastore/Godeps/Godeps.json
+5 -6
@@ -1,15 +1,10 @@
1 {
2 "ImportPath": "github.com/jbenet/go-datastore",
3 - "GoVersion": "go1.4",
3 + "GoVersion": "go1.4.2",
4 "Packages": [
5 "./..."
6 ],
7 "Deps": [
8 - {
9 - "ImportPath": "code.google.com/p/go-uuid/uuid",
10 - "Comment": "null-12",
11 - "Rev": "7dda39b2e7d5e265014674c5af696ba4186679e9"
12 - },
8 {
9 "ImportPath": "github.com/codahale/blake2",
10 "Rev": "3fa823583afba430e8fc7cdbcc670dbf90bfacc4"
@@ -34,6 +29,10 @@
29 "ImportPath": "github.com/jbenet/goprocess",
30 "Rev": "5b02f8d275a2dd882fb06f8bbdf74347795ff3b1"
31 },
32 + {
33 + "ImportPath": "github.com/satori/go.uuid",
34 + "Rev": "7c7f2020c4c9491594b85767967f4619c2fa75f9"
35 + },
36 {
37 "ImportPath": "github.com/mattbaird/elastigo/api",
38 "Rev": "041b88c1fcf6489a5721ede24378ce1253b9159d"
Godeps/_workspace/src/github.com/jbenet/go-datastore/key.go
+2 -3
@@ -4,9 +4,8 @@ import (
4 "path"
5 "strings"
6
7 - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid"
8 -
7 dsq "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/query"
8 + "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/satori/go.uuid"
9 )
10
11 /*
@@ -204,7 +203,7 @@ func (k Key) IsTopLevel() bool {
203 // RandomKey()
204 // NewKey("/f98719ea086343f7b71f32ea9d9d521d")
205 func RandomKey() Key {
207 - return NewKey(strings.Replace(uuid.New(), "-", "", -1))
206 + return NewKey(strings.Replace(uuid.NewV4().String(), "-", "", -1))
207 }
208
209 /*
Godeps/_workspace/src/github.com/satori/go.uuid/.travis.yml new
+10
@@ -0,0 +1,10 @@
1 +language: go
2 +go:
3 + - 1.0
4 + - 1.1
5 + - 1.2
6 + - 1.3
7 + - 1.4
8 +sudo: false
9 +notifications:
10 + email: false
Godeps/_workspace/src/github.com/satori/go.uuid/LICENSE new
+20
@@ -0,0 +1,20 @@
1 +Copyright (C) 2013-2015 by Maxim Bublis <b@codemonkey.ru>
2 +
3 +Permission is hereby granted, free of charge, to any person obtaining
4 +a copy of this software and associated documentation files (the
5 +"Software"), to deal in the Software without restriction, including
6 +without limitation the rights to use, copy, modify, merge, publish,
7 +distribute, sublicense, and/or sell copies of the Software, and to
8 +permit persons to whom the Software is furnished to do so, subject to
9 +the following conditions:
10 +
11 +The above copyright notice and this permission notice shall be
12 +included in all copies or substantial portions of the Software.
13 +
14 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Godeps/_workspace/src/github.com/satori/go.uuid/README.md new
+66
@@ -0,0 +1,66 @@
1 +# UUID package for Go language
2 +
3 +[![Build Status](https://travis-ci.org/satori/go.uuid.png?branch=master)](https://travis-ci.org/satori/go.uuid)
4 +[![GoDoc](http://godoc.org/github.com/satori/go.uuid?status.png)](http://godoc.org/github.com/satori/go.uuid)
5 +
6 +This package provides pure Go implementation of Universally Unique Identifier (UUID). Supported both creation and parsing of UUIDs.
7 +
8 +With 100% test coverage and benchmarks out of box.
9 +
10 +Supported versions:
11 +* Version 1, based on timestamp and MAC address (RFC 4122)
12 +* Version 2, based on timestamp, MAC address and POSIX UID/GID (DCE 1.1)
13 +* Version 3, based on MD5 hashing (RFC 4122)
14 +* Version 4, based on random numbers (RFC 4122)
15 +* Version 5, based on SHA-1 hashing (RFC 4122)
16 +
17 +## Installation
18 +
19 +Use the `go` command:
20 +
21 + $ go get github.com/satori/go.uuid
22 +
23 +## Requirements
24 +
25 +UUID package requires any stable version of Go Programming Language.
26 +
27 +It is tested against following versions of Go: 1.0-1.4
28 +
29 +## Example
30 +
31 +```go
32 +package main
33 +
34 +import (
35 + "fmt"
36 + "github.com/satori/go.uuid"
37 +)
38 +
39 +func main() {
40 + // Creating UUID Version 4
41 + u1 := uuid.NewV4()
42 + fmt.Printf("UUIDv4: %s\n", u1)
43 +
44 + // Parsing UUID from string input
45 + u2, err := uuid.FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
46 + if err != nil {
47 + fmt.Printf("Something gone wrong: %s", err)
48 + }
49 + fmt.Printf("Successfully parsed: %s", u2)
50 +}
51 +```
52 +
53 +## Documentation
54 +
55 +[Documentation](http://godoc.org/github.com/satori/go.uuid) is hosted at GoDoc project.
56 +
57 +## Links
58 +* [RFC 4122](http://tools.ietf.org/html/rfc4122)
59 +* [DCE 1.1: Authentication and Security Services](http://pubs.opengroup.org/onlinepubs/9696989899/chap5.htm#tagcjh_08_02_01_01)
60 +
61 +## Copyright
62 +
63 +Copyright (C) 2013-2015 by Maxim Bublis <b@codemonkey.ru>.
64 +
65 +UUID package released under MIT License.
66 +See [LICENSE](https://github.com/satori/go.uuid/blob/master/LICENSE) for details.
Godeps/_workspace/src/github.com/satori/go.uuid/benchmarks_test.go new
+121
@@ -0,0 +1,121 @@
1 +// Copyright (C) 2013-2014 by Maxim Bublis <b@codemonkey.ru>
2 +//
3 +// Permission is hereby granted, free of charge, to any person obtaining
4 +// a copy of this software and associated documentation files (the
5 +// "Software"), to deal in the Software without restriction, including
6 +// without limitation the rights to use, copy, modify, merge, publish,
7 +// distribute, sublicense, and/or sell copies of the Software, and to
8 +// permit persons to whom the Software is furnished to do so, subject to
9 +// the following conditions:
10 +//
11 +// The above copyright notice and this permission notice shall be
12 +// included in all copies or substantial portions of the Software.
13 +//
14 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 +
22 +package uuid
23 +
24 +import (
25 + "testing"
26 +)
27 +
28 +func BenchmarkFromBytes(b *testing.B) {
29 + bytes := []byte{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
30 + for i := 0; i < b.N; i++ {
31 + FromBytes(bytes)
32 + }
33 +}
34 +
35 +func BenchmarkFromString(b *testing.B) {
36 + s := "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
37 + for i := 0; i < b.N; i++ {
38 + FromString(s)
39 + }
40 +}
41 +
42 +func BenchmarkFromStringUrn(b *testing.B) {
43 + s := "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8"
44 + for i := 0; i < b.N; i++ {
45 + FromString(s)
46 + }
47 +}
48 +
49 +func BenchmarkFromStringWithBrackets(b *testing.B) {
50 + s := "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}"
51 + for i := 0; i < b.N; i++ {
52 + FromString(s)
53 + }
54 +}
55 +
56 +func BenchmarkNewV1(b *testing.B) {
57 + for i := 0; i < b.N; i++ {
58 + NewV1()
59 + }
60 +}
61 +
62 +func BenchmarkNewV2(b *testing.B) {
63 + for i := 0; i < b.N; i++ {
64 + NewV2(DomainPerson)
65 + }
66 +}
67 +
68 +func BenchmarkNewV3(b *testing.B) {
69 + for i := 0; i < b.N; i++ {
70 + NewV3(NamespaceDNS, "www.example.com")
71 + }
72 +}
73 +
74 +func BenchmarkNewV4(b *testing.B) {
75 + for i := 0; i < b.N; i++ {
76 + NewV4()
77 + }
78 +}
79 +
80 +func BenchmarkNewV5(b *testing.B) {
81 + for i := 0; i < b.N; i++ {
82 + NewV5(NamespaceDNS, "www.example.com")
83 + }
84 +}
85 +
86 +func BenchmarkMarshalBinary(b *testing.B) {
87 + u := NewV4()
88 + for i := 0; i < b.N; i++ {
89 + u.MarshalBinary()
90 + }
91 +}
92 +
93 +func BenchmarkMarshalText(b *testing.B) {
94 + u := NewV4()
95 + for i := 0; i < b.N; i++ {
96 + u.MarshalText()
97 + }
98 +}
99 +
100 +func BenchmarkUnmarshalBinary(b *testing.B) {
101 + bytes := []byte{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
102 + u := UUID{}
103 + for i := 0; i < b.N; i++ {
104 + u.UnmarshalBinary(bytes)
105 + }
106 +}
107 +
108 +func BenchmarkUnmarshalText(b *testing.B) {
109 + bytes := []byte("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
110 + u := UUID{}
111 + for i := 0; i < b.N; i++ {
112 + u.UnmarshalText(bytes)
113 + }
114 +}
115 +
116 +func BenchmarkMarshalToString(b *testing.B) {
117 + u := NewV4()
118 + for i := 0; i < b.N; i++ {
119 + u.String()
120 + }
121 +}
Godeps/_workspace/src/github.com/satori/go.uuid/uuid.go new
+397
@@ -0,0 +1,397 @@
1 +// Copyright (C) 2013-2015 by Maxim Bublis <b@codemonkey.ru>
2 +//
3 +// Permission is hereby granted, free of charge, to any person obtaining
4 +// a copy of this software and associated documentation files (the
5 +// "Software"), to deal in the Software without restriction, including
6 +// without limitation the rights to use, copy, modify, merge, publish,
7 +// distribute, sublicense, and/or sell copies of the Software, and to
8 +// permit persons to whom the Software is furnished to do so, subject to
9 +// the following conditions:
10 +//
11 +// The above copyright notice and this permission notice shall be
12 +// included in all copies or substantial portions of the Software.
13 +//
14 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 +
22 +// Package uuid provides implementation of Universally Unique Identifier (UUID).
23 +// Supported versions are 1, 3, 4 and 5 (as specified in RFC 4122) and
24 +// version 2 (as specified in DCE 1.1).
25 +package uuid
26 +
27 +import (
28 + "bytes"
29 + "crypto/md5"
30 + "crypto/rand"
31 + "crypto/sha1"
32 + "encoding/binary"
33 + "encoding/hex"
34 + "fmt"
35 + "hash"
36 + "net"
37 + "os"
38 + "sync"
39 + "time"
40 +)
41 +
42 +// UUID layout variants.
43 +const (
44 + VariantNCS = iota
45 + VariantRFC4122
46 + VariantMicrosoft
47 + VariantFuture
48 +)
49 +
50 +// UUID DCE domains.
51 +const (
52 + DomainPerson = iota
53 + DomainGroup
54 + DomainOrg
55 +)
56 +
57 +// Difference in 100-nanosecond intervals between
58 +// UUID epoch (October 15, 1582) and Unix epoch (January 1, 1970).
59 +const epochStart = 122192928000000000
60 +
61 +// Used in string method conversion
62 +const dash byte = '-'
63 +
64 +// UUID v1/v2 storage.
65 +var (
66 + storageMutex sync.Mutex
67 + clockSequence uint16
68 + lastTime uint64
69 + hardwareAddr [6]byte
70 + posixUID = uint32(os.Getuid())
71 + posixGID = uint32(os.Getgid())
72 +)
73 +
74 +// String parse helpers.
75 +var (
76 + urnPrefix = []byte("urn:uuid:")
77 + byteGroups = []int{8, 4, 4, 4, 12}
78 +)
79 +
80 +// Epoch calculation function
81 +var epochFunc func() uint64
82 +
83 +// Initialize storage
84 +func init() {
85 + buf := make([]byte, 2)
86 + rand.Read(buf)
87 + clockSequence = binary.BigEndian.Uint16(buf)
88 +
89 + // Initialize hardwareAddr randomly in case
90 + // of real network interfaces absence
91 + rand.Read(hardwareAddr[:])
92 +
93 + // Set multicast bit as recommended in RFC 4122
94 + hardwareAddr[0] |= 0x01
95 +
96 + interfaces, err := net.Interfaces()
97 + if err == nil {
98 + for _, iface := range interfaces {
99 + if len(iface.HardwareAddr) >= 6 {
100 + copy(hardwareAddr[:], iface.HardwareAddr)
101 + break
102 + }
103 + }
104 + }
105 + epochFunc = unixTimeFunc
106 +}
107 +
108 +// Returns difference in 100-nanosecond intervals between
109 +// UUID epoch (October 15, 1582) and current time.
110 +// This is default epoch calculation function.
111 +func unixTimeFunc() uint64 {
112 + return epochStart + uint64(time.Now().UnixNano()/100)
113 +}
114 +
115 +// UUID representation compliant with specification
116 +// described in RFC 4122.
117 +type UUID [16]byte
118 +
119 +// The nil UUID is special form of UUID that is specified to have all
120 +// 128 bits set to zero.
121 +var Nil = UUID{}
122 +
123 +// Predefined namespace UUIDs.
124 +var (
125 + NamespaceDNS, _ = FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
126 + NamespaceURL, _ = FromString("6ba7b811-9dad-11d1-80b4-00c04fd430c8")
127 + NamespaceOID, _ = FromString("6ba7b812-9dad-11d1-80b4-00c04fd430c8")
128 + NamespaceX500, _ = FromString("6ba7b814-9dad-11d1-80b4-00c04fd430c8")
129 +)
130 +
131 +// And returns result of binary AND of two UUIDs.
132 +func And(u1 UUID, u2 UUID) UUID {
133 + u := UUID{}
134 + for i := 0; i < 16; i++ {
135 + u[i] = u1[i] & u2[i]
136 + }
137 + return u
138 +}
139 +
140 +// Or returns result of binary OR of two UUIDs.
141 +func Or(u1 UUID, u2 UUID) UUID {
142 + u := UUID{}
143 + for i := 0; i < 16; i++ {
144 + u[i] = u1[i] | u2[i]
145 + }
146 + return u
147 +}
148 +
149 +// Equal returns true if u1 and u2 equals, otherwise returns false.
150 +func Equal(u1 UUID, u2 UUID) bool {
151 + return bytes.Equal(u1[:], u2[:])
152 +}
153 +
154 +// Version returns algorithm version used to generate UUID.
155 +func (u UUID) Version() uint {
156 + return uint(u[6] >> 4)
157 +}
158 +
159 +// Variant returns UUID layout variant.
160 +func (u UUID) Variant() uint {
161 + switch {
162 + case (u[8] & 0x80) == 0x00:
163 + return VariantNCS
164 + case (u[8]&0xc0)|0x80 == 0x80:
165 + return VariantRFC4122
166 + case (u[8]&0xe0)|0xc0 == 0xc0:
167 + return VariantMicrosoft
168 + }
169 + return VariantFuture
170 +}
171 +
172 +// Bytes returns bytes slice representation of UUID.
173 +func (u UUID) Bytes() []byte {
174 + return u[:]
175 +}
176 +
177 +// Returns canonical string representation of UUID:
178 +// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
179 +func (u UUID) String() string {
180 + buf := make([]byte, 36)
181 +
182 + hex.Encode(buf[0:8], u[0:4])
183 + buf[8] = dash
184 + hex.Encode(buf[9:13], u[4:6])
185 + buf[13] = dash
186 + hex.Encode(buf[14:18], u[6:8])
187 + buf[18] = dash
188 + hex.Encode(buf[19:23], u[8:10])
189 + buf[23] = dash
190 + hex.Encode(buf[24:], u[10:])
191 +
192 + return string(buf)
193 +}
194 +
195 +// SetVersion sets version bits.
196 +func (u *UUID) SetVersion(v byte) {
197 + u[6] = (u[6] & 0x0f) | (v << 4)
198 +}
199 +
200 +// SetVariant sets variant bits as described in RFC 4122.
201 +func (u *UUID) SetVariant() {
202 + u[8] = (u[8] & 0xbf) | 0x80
203 +}
204 +
205 +// MarshalText implements the encoding.TextMarshaler interface.
206 +// The encoding is the same as returned by String.
207 +func (u UUID) MarshalText() (text []byte, err error) {
208 + text = []byte(u.String())
209 + return
210 +}
211 +
212 +// UnmarshalText implements the encoding.TextUnmarshaler interface.
213 +// Following formats are supported:
214 +// "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
215 +// "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}",
216 +// "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8"
217 +func (u *UUID) UnmarshalText(text []byte) (err error) {
218 + if len(text) < 32 {
219 + err = fmt.Errorf("uuid: invalid UUID string: %s", text)
220 + return
221 + }
222 +
223 + if bytes.Equal(text[:9], urnPrefix) {
224 + text = text[9:]
225 + } else if text[0] == '{' {
226 + text = text[1:]
227 + }
228 +
229 + b := u[:]
230 +
231 + for _, byteGroup := range byteGroups {
232 + if text[0] == '-' {
233 + text = text[1:]
234 + }
235 +
236 + _, err = hex.Decode(b[:byteGroup/2], text[:byteGroup])
237 +
238 + if err != nil {
239 + return
240 + }
241 +
242 + text = text[byteGroup:]
243 + b = b[byteGroup/2:]
244 + }
245 +
246 + return
247 +}
248 +
249 +// MarshalBinary implements the encoding.BinaryMarshaler interface.
250 +func (u UUID) MarshalBinary() (data []byte, err error) {
251 + data = u.Bytes()
252 + return
253 +}
254 +
255 +// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.
256 +// It will return error if the slice isn't 16 bytes long.
257 +func (u *UUID) UnmarshalBinary(data []byte) (err error) {
258 + if len(data) != 16 {
259 + err = fmt.Errorf("uuid: UUID must be exactly 16 bytes long, got %d bytes", len(data))
260 + return
261 + }
262 + copy(u[:], data)
263 +
264 + return
265 +}
266 +
267 +// Scan implements the sql.Scanner interface.
268 +// A 16-byte slice is handled by UnmarshalBinary, while
269 +// a longer byte slice or a string is handled by UnmarshalText.
270 +func (u *UUID) Scan(src interface{}) error {
271 + switch src := src.(type) {
272 + case []byte:
273 + if len(src) == 16 {
274 + return u.UnmarshalBinary(src)
275 + }
276 + return u.UnmarshalText(src)
277 +
278 + case string:
279 + return u.UnmarshalText([]byte(src))
280 + }
281 +
282 + return fmt.Errorf("uuid: cannot convert %T to UUID", src)
283 +}
284 +
285 +// FromBytes returns UUID converted from raw byte slice input.
286 +// It will return error if the slice isn't 16 bytes long.
287 +func FromBytes(input []byte) (u UUID, err error) {
288 + err = u.UnmarshalBinary(input)
289 + return
290 +}
291 +
292 +// FromString returns UUID parsed from string input.
293 +// Input is expected in a form accepted by UnmarshalText.
294 +func FromString(input string) (u UUID, err error) {
295 + err = u.UnmarshalText([]byte(input))
296 + return
297 +}
298 +
299 +// Returns UUID v1/v2 storage state.
300 +// Returns epoch timestamp and clock sequence.
301 +func getStorage() (uint64, uint16) {
302 + storageMutex.Lock()
303 + defer storageMutex.Unlock()
304 +
305 + timeNow := epochFunc()
306 + // Clock changed backwards since last UUID generation.
307 + // Should increase clock sequence.
308 + if timeNow <= lastTime {
309 + clockSequence++
310 + }
311 + lastTime = timeNow
312 +
313 + return timeNow, clockSequence
314 +}
315 +
316 +// NewV1 returns UUID based on current timestamp and MAC address.
317 +func NewV1() UUID {
318 + u := UUID{}
319 +
320 + timeNow, clockSeq := getStorage()
321 +
322 + binary.BigEndian.PutUint32(u[0:], uint32(timeNow))
323 + binary.BigEndian.PutUint16(u[4:], uint16(timeNow>>32))
324 + binary.BigEndian.PutUint16(u[6:], uint16(timeNow>>48))
325 + binary.BigEndian.PutUint16(u[8:], clockSeq)
326 +
327 + copy(u[10:], hardwareAddr[:])
328 +
329 + u.SetVersion(1)
330 + u.SetVariant()
331 +
332 + return u
333 +}
334 +
335 +// NewV2 returns DCE Security UUID based on POSIX UID/GID.
336 +func NewV2(domain byte) UUID {
337 + u := UUID{}
338 +
339 + switch domain {
340 + case DomainPerson:
341 + binary.BigEndian.PutUint32(u[0:], posixUID)
342 + case DomainGroup:
343 + binary.BigEndian.PutUint32(u[0:], posixGID)
344 + }
345 +
346 + timeNow, clockSeq := getStorage()
347 +
348 + binary.BigEndian.PutUint16(u[4:], uint16(timeNow>>32))
349 + binary.BigEndian.PutUint16(u[6:], uint16(timeNow>>48))
350 + binary.BigEndian.PutUint16(u[8:], clockSeq)
351 + u[9] = domain
352 +
353 + copy(u[10:], hardwareAddr[:])
354 +
355 + u.SetVersion(2)
356 + u.SetVariant()
357 +
358 + return u
359 +}
360 +
361 +// NewV3 returns UUID based on MD5 hash of namespace UUID and name.
362 +func NewV3(ns UUID, name string) UUID {
363 + u := newFromHash(md5.New(), ns, name)
364 + u.SetVersion(3)
365 + u.SetVariant()
366 +
367 + return u
368 +}
369 +
370 +// NewV4 returns random generated UUID.
371 +func NewV4() UUID {
372 + u := UUID{}
373 + rand.Read(u[:])
374 + u.SetVersion(4)
375 + u.SetVariant()
376 +
377 + return u
378 +}
379 +
380 +// NewV5 returns UUID based on SHA-1 hash of namespace UUID and name.
381 +func NewV5(ns UUID, name string) UUID {
382 + u := newFromHash(sha1.New(), ns, name)
383 + u.SetVersion(5)
384 + u.SetVariant()
385 +
386 + return u
387 +}
388 +
389 +// Returns UUID based on hashing of namespace UUID and name.
390 +func newFromHash(h hash.Hash, ns UUID, name string) UUID {
391 + u := UUID{}
392 + h.Write(ns[:])
393 + h.Write([]byte(name))
394 + copy(u[:], h.Sum(nil))
395 +
396 + return u
397 +}
Godeps/_workspace/src/github.com/satori/go.uuid/uuid_test.go new
+477
@@ -0,0 +1,477 @@
1 +// Copyright (C) 2013, 2015 by Maxim Bublis <b@codemonkey.ru>
2 +//
3 +// Permission is hereby granted, free of charge, to any person obtaining
4 +// a copy of this software and associated documentation files (the
5 +// "Software"), to deal in the Software without restriction, including
6 +// without limitation the rights to use, copy, modify, merge, publish,
7 +// distribute, sublicense, and/or sell copies of the Software, and to
8 +// permit persons to whom the Software is furnished to do so, subject to
9 +// the following conditions:
10 +//
11 +// The above copyright notice and this permission notice shall be
12 +// included in all copies or substantial portions of the Software.
13 +//
14 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 +
22 +package uuid
23 +
24 +import (
25 + "bytes"
26 + "testing"
27 +)
28 +
29 +func TestBytes(t *testing.T) {
30 + u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
31 +
32 + bytes1 := []byte{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
33 +
34 + if !bytes.Equal(u.Bytes(), bytes1) {
35 + t.Errorf("Incorrect bytes representation for UUID: %s", u)
36 + }
37 +}
38 +
39 +func TestString(t *testing.T) {
40 + if NamespaceDNS.String() != "6ba7b810-9dad-11d1-80b4-00c04fd430c8" {
41 + t.Errorf("Incorrect string representation for UUID: %s", NamespaceDNS.String())
42 + }
43 +}
44 +
45 +func TestEqual(t *testing.T) {
46 + if !Equal(NamespaceDNS, NamespaceDNS) {
47 + t.Errorf("Incorrect comparison of %s and %s", NamespaceDNS, NamespaceDNS)
48 + }
49 +
50 + if Equal(NamespaceDNS, NamespaceURL) {
51 + t.Errorf("Incorrect comparison of %s and %s", NamespaceDNS, NamespaceURL)
52 + }
53 +}
54 +
55 +func TestOr(t *testing.T) {
56 + u1 := UUID{0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff}
57 + u2 := UUID{0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00}
58 +
59 + u := UUID{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
60 +
61 + if !Equal(u, Or(u1, u2)) {
62 + t.Errorf("Incorrect bitwise OR result %s", Or(u1, u2))
63 + }
64 +}
65 +
66 +func TestAnd(t *testing.T) {
67 + u1 := UUID{0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff}
68 + u2 := UUID{0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00}
69 +
70 + u := UUID{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
71 +
72 + if !Equal(u, And(u1, u2)) {
73 + t.Errorf("Incorrect bitwise AND result %s", And(u1, u2))
74 + }
75 +}
76 +
77 +func TestVersion(t *testing.T) {
78 + u := UUID{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
79 +
80 + if u.Version() != 1 {
81 + t.Errorf("Incorrect version for UUID: %d", u.Version())
82 + }
83 +}
84 +
85 +func TestSetVersion(t *testing.T) {
86 + u := UUID{}
87 + u.SetVersion(4)
88 +
89 + if u.Version() != 4 {
90 + t.Errorf("Incorrect version for UUID after u.setVersion(4): %d", u.Version())
91 + }
92 +}
93 +
94 +func TestVariant(t *testing.T) {
95 + u1 := UUID{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
96 +
97 + if u1.Variant() != VariantNCS {
98 + t.Errorf("Incorrect variant for UUID variant %d: %d", VariantNCS, u1.Variant())
99 + }
100 +
101 + u2 := UUID{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
102 +
103 + if u2.Variant() != VariantRFC4122 {
104 + t.Errorf("Incorrect variant for UUID variant %d: %d", VariantRFC4122, u2.Variant())
105 + }
106 +
107 + u3 := UUID{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
108 +
109 + if u3.Variant() != VariantMicrosoft {
110 + t.Errorf("Incorrect variant for UUID variant %d: %d", VariantMicrosoft, u3.Variant())
111 + }
112 +
113 + u4 := UUID{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
114 +
115 + if u4.Variant() != VariantFuture {
116 + t.Errorf("Incorrect variant for UUID variant %d: %d", VariantFuture, u4.Variant())
117 + }
118 +}
119 +
120 +func TestSetVariant(t *testing.T) {
121 + u := new(UUID)
122 + u.SetVariant()
123 +
124 + if u.Variant() != VariantRFC4122 {
125 + t.Errorf("Incorrect variant for UUID after u.setVariant(): %d", u.Variant())
126 + }
127 +}
128 +
129 +func TestFromBytes(t *testing.T) {
130 + u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
131 + b1 := []byte{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
132 +
133 + u1, err := FromBytes(b1)
134 + if err != nil {
135 + t.Errorf("Error parsing UUID from bytes: %s", err)
136 + }
137 +
138 + if !Equal(u, u1) {
139 + t.Errorf("UUIDs should be equal: %s and %s", u, u1)
140 + }
141 +
142 + b2 := []byte{}
143 +
144 + _, err = FromBytes(b2)
145 + if err == nil {
146 + t.Errorf("Should return error parsing from empty byte slice, got %s", err)
147 + }
148 +}
149 +
150 +func TestMarshalBinary(t *testing.T) {
151 + u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
152 + b1 := []byte{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
153 +
154 + b2, err := u.MarshalBinary()
155 + if err != nil {
156 + t.Errorf("Error marshaling UUID: %s", err)
157 + }
158 +
159 + if !bytes.Equal(b1, b2) {
160 + t.Errorf("Marshaled UUID should be %s, got %s", b1, b2)
161 + }
162 +}
163 +
164 +func TestUnmarshalBinary(t *testing.T) {
165 + u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
166 + b1 := []byte{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
167 +
168 + u1 := UUID{}
169 + err := u1.UnmarshalBinary(b1)
170 + if err != nil {
171 + t.Errorf("Error unmarshaling UUID: %s", err)
172 + }
173 +
174 + if !Equal(u, u1) {
175 + t.Errorf("UUIDs should be equal: %s and %s", u, u1)
176 + }
177 +
178 + b2 := []byte{}
179 + u2 := UUID{}
180 +
181 + err = u2.UnmarshalBinary(b2)
182 + if err == nil {
183 + t.Errorf("Should return error unmarshalling from empty byte slice, got %s", err)
184 + }
185 +}
186 +
187 +func TestFromString(t *testing.T) {
188 + u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
189 +
190 + s1 := "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
191 + s2 := "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}"
192 + s3 := "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8"
193 +
194 + _, err := FromString("")
195 + if err == nil {
196 + t.Errorf("Should return error trying to parse empty string, got %s", err)
197 + }
198 +
199 + u1, err := FromString(s1)
200 + if err != nil {
201 + t.Errorf("Error parsing UUID from string: %s", err)
202 + }
203 +
204 + if !Equal(u, u1) {
205 + t.Errorf("UUIDs should be equal: %s and %s", u, u1)
206 + }
207 +
208 + u2, err := FromString(s2)
209 + if err != nil {
210 + t.Errorf("Error parsing UUID from string: %s", err)
211 + }
212 +
213 + if !Equal(u, u2) {
214 + t.Errorf("UUIDs should be equal: %s and %s", u, u2)
215 + }
216 +
217 + u3, err := FromString(s3)
218 + if err != nil {
219 + t.Errorf("Error parsing UUID from string: %s", err)
220 + }
221 +
222 + if !Equal(u, u3) {
223 + t.Errorf("UUIDs should be equal: %s and %s", u, u3)
224 + }
225 +}
226 +
227 +func TestMarshalText(t *testing.T) {
228 + u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
229 + b1 := []byte("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
230 +
231 + b2, err := u.MarshalText()
232 + if err != nil {
233 + t.Errorf("Error marshaling UUID: %s", err)
234 + }
235 +
236 + if !bytes.Equal(b1, b2) {
237 + t.Errorf("Marshaled UUID should be %s, got %s", b1, b2)
238 + }
239 +}
240 +
241 +func TestUnmarshalText(t *testing.T) {
242 + u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
243 + b1 := []byte("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
244 +
245 + u1 := UUID{}
246 + err := u1.UnmarshalText(b1)
247 + if err != nil {
248 + t.Errorf("Error unmarshaling UUID: %s", err)
249 + }
250 +
251 + if !Equal(u, u1) {
252 + t.Errorf("UUIDs should be equal: %s and %s", u, u1)
253 + }
254 +
255 + b2 := []byte("")
256 + u2 := UUID{}
257 +
258 + err = u2.UnmarshalText(b2)
259 + if err == nil {
260 + t.Errorf("Should return error trying to unmarshal from empty string")
261 + }
262 +}
263 +
264 +func TestScanBinary(t *testing.T) {
265 + u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
266 + b1 := []byte{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
267 +
268 + u1 := UUID{}
269 + err := u1.Scan(b1)
270 + if err != nil {
271 + t.Errorf("Error unmarshaling UUID: %s", err)
272 + }
273 +
274 + if !Equal(u, u1) {
275 + t.Errorf("UUIDs should be equal: %s and %s", u, u1)
276 + }
277 +
278 + b2 := []byte{}
279 + u2 := UUID{}
280 +
281 + err = u2.Scan(b2)
282 + if err == nil {
283 + t.Errorf("Should return error unmarshalling from empty byte slice, got %s", err)
284 + }
285 +}
286 +
287 +func TestScanString(t *testing.T) {
288 + u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
289 + s1 := "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
290 +
291 + u1 := UUID{}
292 + err := u1.Scan(s1)
293 + if err != nil {
294 + t.Errorf("Error unmarshaling UUID: %s", err)
295 + }
296 +
297 + if !Equal(u, u1) {
298 + t.Errorf("UUIDs should be equal: %s and %s", u, u1)
299 + }
300 +
301 + s2 := ""
302 + u2 := UUID{}
303 +
304 + err = u2.Scan(s2)
305 + if err == nil {
306 + t.Errorf("Should return error trying to unmarshal from empty string")
307 + }
308 +}
309 +
310 +func TestScanText(t *testing.T) {
311 + u := UUID{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
312 + b1 := []byte("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
313 +
314 + u1 := UUID{}
315 + err := u1.Scan(b1)
316 + if err != nil {
317 + t.Errorf("Error unmarshaling UUID: %s", err)
318 + }
319 +
320 + if !Equal(u, u1) {
321 + t.Errorf("UUIDs should be equal: %s and %s", u, u1)
322 + }
323 +
324 + b2 := []byte("")
325 + u2 := UUID{}
326 +
327 + err = u2.Scan(b2)
328 + if err == nil {
329 + t.Errorf("Should return error trying to unmarshal from empty string")
330 + }
331 +}
332 +
333 +func TestScanUnsupported(t *testing.T) {
334 + u := UUID{}
335 +
336 + err := u.Scan(true)
337 + if err == nil {
338 + t.Errorf("Should return error trying to unmarshal from bool")
339 + }
340 +}
341 +
342 +func TestNewV1(t *testing.T) {
343 + u := NewV1()
344 +
345 + if u.Version() != 1 {
346 + t.Errorf("UUIDv1 generated with incorrect version: %d", u.Version())
347 + }
348 +
349 + if u.Variant() != VariantRFC4122 {
350 + t.Errorf("UUIDv1 generated with incorrect variant: %d", u.Variant())
351 + }
352 +
353 + u1 := NewV1()
354 + u2 := NewV1()
355 +
356 + if Equal(u1, u2) {
357 + t.Errorf("UUIDv1 generated two equal UUIDs: %s and %s", u1, u2)
358 + }
359 +
360 + oldFunc := epochFunc
361 + epochFunc = func() uint64 { return 0 }
362 +
363 + u3 := NewV1()
364 + u4 := NewV1()
365 +
366 + if Equal(u3, u4) {
367 + t.Errorf("UUIDv1 generated two equal UUIDs: %s and %s", u3, u4)
368 + }
369 +
370 + epochFunc = oldFunc
371 +}
372 +
373 +func TestNewV2(t *testing.T) {
374 + u1 := NewV2(DomainPerson)
375 +
376 + if u1.Version() != 2 {
377 + t.Errorf("UUIDv2 generated with incorrect version: %d", u1.Version())
378 + }
379 +
380 + if u1.Variant() != VariantRFC4122 {
381 + t.Errorf("UUIDv2 generated with incorrect variant: %d", u1.Variant())
382 + }
383 +
384 + u2 := NewV2(DomainGroup)
385 +
386 + if u2.Version() != 2 {
387 + t.Errorf("UUIDv2 generated with incorrect version: %d", u2.Version())
388 + }
389 +
390 + if u2.Variant() != VariantRFC4122 {
391 + t.Errorf("UUIDv2 generated with incorrect variant: %d", u2.Variant())
392 + }
393 +}
394 +
395 +func TestNewV3(t *testing.T) {
396 + u := NewV3(NamespaceDNS, "www.example.com")
397 +
398 + if u.Version() != 3 {
399 + t.Errorf("UUIDv3 generated with incorrect version: %d", u.Version())
400 + }
401 +
402 + if u.Variant() != VariantRFC4122 {
403 + t.Errorf("UUIDv3 generated with incorrect variant: %d", u.Variant())
404 + }
405 +
406 + if u.String() != "5df41881-3aed-3515-88a7-2f4a814cf09e" {
407 + t.Errorf("UUIDv3 generated incorrectly: %s", u.String())
408 + }
409 +
410 + u = NewV3(NamespaceDNS, "python.org")
411 +
412 + if u.String() != "6fa459ea-ee8a-3ca4-894e-db77e160355e" {
413 + t.Errorf("UUIDv3 generated incorrectly: %s", u.String())
414 + }
415 +
416 + u1 := NewV3(NamespaceDNS, "golang.org")
417 + u2 := NewV3(NamespaceDNS, "golang.org")
418 + if !Equal(u1, u2) {
419 + t.Errorf("UUIDv3 generated different UUIDs for same namespace and name: %s and %s", u1, u2)
420 + }
421 +
422 + u3 := NewV3(NamespaceDNS, "example.com")
423 + if Equal(u1, u3) {
424 + t.Errorf("UUIDv3 generated same UUIDs for different names in same namespace: %s and %s", u1, u2)
425 + }
426 +
427 + u4 := NewV3(NamespaceURL, "golang.org")
428 + if Equal(u1, u4) {
429 + t.Errorf("UUIDv3 generated same UUIDs for sane names in different namespaces: %s and %s", u1, u4)
430 + }
431 +}
432 +
433 +func TestNewV4(t *testing.T) {
434 + u := NewV4()
435 +
436 + if u.Version() != 4 {
437 + t.Errorf("UUIDv4 generated with incorrect version: %d", u.Version())
438 + }
439 +
440 + if u.Variant() != VariantRFC4122 {
441 + t.Errorf("UUIDv4 generated with incorrect variant: %d", u.Variant())
442 + }
443 +}
444 +
445 +func TestNewV5(t *testing.T) {
446 + u := NewV5(NamespaceDNS, "www.example.com")
447 +
448 + if u.Version() != 5 {
449 + t.Errorf("UUIDv5 generated with incorrect version: %d", u.Version())
450 + }
451 +
452 + if u.Variant() != VariantRFC4122 {
453 + t.Errorf("UUIDv5 generated with incorrect variant: %d", u.Variant())
454 + }
455 +
456 + u = NewV5(NamespaceDNS, "python.org")
457 +
458 + if u.String() != "886313e1-3b8a-5372-9b90-0c9aee199e5d" {
459 + t.Errorf("UUIDv5 generated incorrectly: %s", u.String())
460 + }
461 +
462 + u1 := NewV5(NamespaceDNS, "golang.org")
463 + u2 := NewV5(NamespaceDNS, "golang.org")
464 + if !Equal(u1, u2) {
465 + t.Errorf("UUIDv5 generated different UUIDs for same namespace and name: %s and %s", u1, u2)
466 + }
467 +
468 + u3 := NewV5(NamespaceDNS, "example.com")
469 + if Equal(u1, u3) {
470 + t.Errorf("UUIDv5 generated same UUIDs for different names in same namespace: %s and %s", u1, u2)
471 + }
472 +
473 + u4 := NewV5(NamespaceURL, "golang.org")
474 + if Equal(u1, u4) {
475 + t.Errorf("UUIDv3 generated same UUIDs for sane names in different namespaces: %s and %s", u1, u4)
476 + }
477 +}
thirdparty/eventlog/metadata.go
+2 -2
@@ -5,7 +5,7 @@ import (
5 "errors"
6 "reflect"
7
8 - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid"
8 + "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/satori/go.uuid"
9 )
10
11 // Metadata is a convenience type for generic maps
@@ -14,7 +14,7 @@ type Metadata map[string]interface{}
14 // Uuid returns a Metadata with the string key and UUID value
15 func Uuid(key string) Metadata {
16 return Metadata{
17 - key: uuid.New(),
17 + key: uuid.NewV4().String(),
18 }
19 }
20