summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/xtgo
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/xtgo')
-rw-r--r--vendor/github.com/xtgo/uuid/AUTHORS5
-rw-r--r--vendor/github.com/xtgo/uuid/LICENSE27
-rw-r--r--vendor/github.com/xtgo/uuid/uuid.go204
-rw-r--r--vendor/github.com/xtgo/uuid/uuid_test.go102
4 files changed, 338 insertions, 0 deletions
diff --git a/vendor/github.com/xtgo/uuid/AUTHORS b/vendor/github.com/xtgo/uuid/AUTHORS
new file mode 100644
index 000000000..a6f045160
--- /dev/null
+++ b/vendor/github.com/xtgo/uuid/AUTHORS
@@ -0,0 +1,5 @@
+# This source file refers to The gocql Authors for copyright purposes.
+
+Christoph Hack <christoph@tux21b.org>
+Jonathan Rudenberg <jonathan@titanous.com>
+Thorsten von Eicken <tve@rightscale.com>
diff --git a/vendor/github.com/xtgo/uuid/LICENSE b/vendor/github.com/xtgo/uuid/LICENSE
new file mode 100644
index 000000000..18d25f923
--- /dev/null
+++ b/vendor/github.com/xtgo/uuid/LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) 2012 The gocql Authors. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with the
+distribution.
+ * Neither the name of Google Inc. nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/vendor/github.com/xtgo/uuid/uuid.go b/vendor/github.com/xtgo/uuid/uuid.go
new file mode 100644
index 000000000..a0fd7a5a5
--- /dev/null
+++ b/vendor/github.com/xtgo/uuid/uuid.go
@@ -0,0 +1,204 @@
+// Copyright (c) 2012 The gocql Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Package uuid can be used to generate and parse universally unique
+// identifiers, a standardized format in the form of a 128 bit number.
+//
+// http://tools.ietf.org/html/rfc4122
+package uuid
+
+import (
+ "crypto/rand"
+ "encoding/hex"
+ "errors"
+ "io"
+ "net"
+ "strconv"
+ "time"
+)
+
+type UUID [16]byte
+
+var hardwareAddr []byte
+
+const (
+ VariantNCSCompat = 0
+ VariantIETF = 2
+ VariantMicrosoft = 6
+ VariantFuture = 7
+)
+
+func init() {
+ if interfaces, err := net.Interfaces(); err == nil {
+ for _, i := range interfaces {
+ if i.Flags&net.FlagLoopback == 0 && len(i.HardwareAddr) > 0 {
+ hardwareAddr = i.HardwareAddr
+ break
+ }
+ }
+ }
+ if hardwareAddr == nil {
+ // If we failed to obtain the MAC address of the current computer,
+ // we will use a randomly generated 6 byte sequence instead and set
+ // the multicast bit as recommended in RFC 4122.
+ hardwareAddr = make([]byte, 6)
+ _, err := io.ReadFull(rand.Reader, hardwareAddr)
+ if err != nil {
+ panic(err)
+ }
+ hardwareAddr[0] = hardwareAddr[0] | 0x01
+ }
+}
+
+// Parse parses a 32 digit hexadecimal number (that might contain hyphens)
+// representing an UUID.
+func Parse(input string) (UUID, error) {
+ var u UUID
+ j := 0
+ for i := 0; i < len(input); i++ {
+ b := input[i]
+ switch {
+ default:
+ fallthrough
+ case j == 32:
+ goto err
+ case b == '-':
+ continue
+ case '0' <= b && b <= '9':
+ b -= '0'
+ case 'a' <= b && b <= 'f':
+ b -= 'a' - 10
+ case 'A' <= b && b <= 'F':
+ b -= 'A' - 10
+ }
+ u[j/2] |= b << byte(^j&1<<2)
+ j++
+ }
+ if j == 32 {
+ return u, nil
+ }
+err:
+ return UUID{}, errors.New("invalid UUID " + strconv.Quote(input))
+}
+
+// FromBytes converts a raw byte slice to an UUID. It will panic if the slice
+// isn't exactly 16 bytes long.
+func FromBytes(input []byte) UUID {
+ var u UUID
+ if len(input) != 16 {
+ panic("UUIDs must be exactly 16 bytes long")
+ }
+ copy(u[:], input)
+ return u
+}
+
+// NewRandom generates a totally random UUID (version 4) as described in
+// RFC 4122.
+func NewRandom() UUID {
+ var u UUID
+ io.ReadFull(rand.Reader, u[:])
+ u[6] &= 0x0F // clear version
+ u[6] |= 0x40 // set version to 4 (random uuid)
+ u[8] &= 0x3F // clear variant
+ u[8] |= 0x80 // set to IETF variant
+ return u
+}
+
+var timeBase = time.Date(1582, time.October, 15, 0, 0, 0, 0, time.UTC).Unix()
+
+// NewTime generates a new time based UUID (version 1) as described in RFC
+// 4122. This UUID contains the MAC address of the node that generated the
+// UUID, a timestamp and a sequence number.
+func NewTime() UUID {
+ var u UUID
+
+ now := time.Now().In(time.UTC)
+ t := uint64(now.Unix()-timeBase)*10000000 + uint64(now.Nanosecond()/100)
+ u[0], u[1], u[2], u[3] = byte(t>>24), byte(t>>16), byte(t>>8), byte(t)
+ u[4], u[5] = byte(t>>40), byte(t>>32)
+ u[6], u[7] = byte(t>>56)&0x0F, byte(t>>48)
+
+ var clockSeq [2]byte
+ io.ReadFull(rand.Reader, clockSeq[:])
+ u[8] = clockSeq[1]
+ u[9] = clockSeq[0]
+
+ copy(u[10:], hardwareAddr)
+
+ u[6] |= 0x10 // set version to 1 (time based uuid)
+ u[8] &= 0x3F // clear variant
+ u[8] |= 0x80 // set to IETF variant
+
+ return u
+}
+
+// String returns the UUID in it's canonical form, a 32 digit hexadecimal
+// number in the form of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
+func (u UUID) String() string {
+ buf := [36]byte{8: '-', 13: '-', 18: '-', 23: '-'}
+ hex.Encode(buf[0:], u[0:4])
+ hex.Encode(buf[9:], u[4:6])
+ hex.Encode(buf[14:], u[6:8])
+ hex.Encode(buf[19:], u[8:10])
+ hex.Encode(buf[24:], u[10:])
+ return string(buf[:])
+}
+
+// Bytes returns the raw byte slice for this UUID. A UUID is always 128 bits
+// (16 bytes) long.
+func (u UUID) Bytes() []byte {
+ return u[:]
+}
+
+// Variant returns the variant of this UUID. This package will only generate
+// UUIDs in the IETF variant.
+func (u UUID) Variant() int {
+ x := u[8]
+ switch byte(0) {
+ case x & 0x80:
+ return VariantNCSCompat
+ case x & 0x40:
+ return VariantIETF
+ case x & 0x20:
+ return VariantMicrosoft
+ }
+ return VariantFuture
+}
+
+// Version extracts the version of this UUID variant. The RFC 4122 describes
+// five kinds of UUIDs.
+func (u UUID) Version() int {
+ return int(u[6] & 0xF0 >> 4)
+}
+
+// Node extracts the MAC address of the node who generated this UUID. It will
+// return nil if the UUID is not a time based UUID (version 1).
+func (u UUID) Node() []byte {
+ if u.Version() != 1 {
+ return nil
+ }
+ return u[10:]
+}
+
+// Timestamp extracts the timestamp information from a time based UUID
+// (version 1).
+func (u UUID) Timestamp() uint64 {
+ if u.Version() != 1 {
+ return 0
+ }
+ return uint64(u[0])<<24 + uint64(u[1])<<16 + uint64(u[2])<<8 +
+ uint64(u[3]) + uint64(u[4])<<40 + uint64(u[5])<<32 +
+ uint64(u[7])<<48 + uint64(u[6]&0x0F)<<56
+}
+
+// Time is like Timestamp, except that it returns a time.Time.
+func (u UUID) Time() time.Time {
+ t := u.Timestamp()
+ if t == 0 {
+ return time.Time{}
+ }
+ sec := t / 10000000
+ nsec := t - sec
+ return time.Unix(int64(sec)+timeBase, int64(nsec))
+}
diff --git a/vendor/github.com/xtgo/uuid/uuid_test.go b/vendor/github.com/xtgo/uuid/uuid_test.go
new file mode 100644
index 000000000..3cef4a31a
--- /dev/null
+++ b/vendor/github.com/xtgo/uuid/uuid_test.go
@@ -0,0 +1,102 @@
+// Copyright (c) 2012 The gocql Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package uuid
+
+import (
+ "bytes"
+ "testing"
+)
+
+func TestNil(t *testing.T) {
+ var uuid UUID
+ want, got := "00000000-0000-0000-0000-000000000000", uuid.String()
+ if want != got {
+ t.Fatalf("TestNil: expected %q got %q", want, got)
+ }
+}
+
+var tests = []struct {
+ input string
+ variant int
+ version int
+}{
+ {"b4f00409-cef8-4822-802c-deb20704c365", VariantIETF, 4},
+ {"f81d4fae-7dec-11d0-a765-00a0c91e6bf6", VariantIETF, 1},
+ {"00000000-7dec-11d0-a765-00a0c91e6bf6", VariantIETF, 1},
+ {"3051a8d7-aea7-1801-e0bf-bc539dd60cf3", VariantFuture, 1},
+ {"3051a8d7-aea7-2801-e0bf-bc539dd60cf3", VariantFuture, 2},
+ {"3051a8d7-aea7-3801-e0bf-bc539dd60cf3", VariantFuture, 3},
+ {"3051a8d7-aea7-4801-e0bf-bc539dd60cf3", VariantFuture, 4},
+ {"3051a8d7-aea7-3801-e0bf-bc539dd60cf3", VariantFuture, 5},
+ {"d0e817e1-e4b1-1801-3fe6-b4b60ccecf9d", VariantNCSCompat, 0},
+ {"d0e817e1-e4b1-1801-bfe6-b4b60ccecf9d", VariantIETF, 1},
+ {"d0e817e1-e4b1-1801-dfe6-b4b60ccecf9d", VariantMicrosoft, 0},
+ {"d0e817e1-e4b1-1801-ffe6-b4b60ccecf9d", VariantFuture, 0},
+}
+
+func TestPredefined(t *testing.T) {
+ for i := range tests {
+ uuid, err := Parse(tests[i].input)
+ if err != nil {
+ t.Errorf("Parse #%d: %v", i, err)
+ continue
+ }
+
+ if str := uuid.String(); str != tests[i].input {
+ t.Errorf("String #%d: expected %q got %q", i, tests[i].input, str)
+ continue
+ }
+
+ if variant := uuid.Variant(); variant != tests[i].variant {
+ t.Errorf("Variant #%d: expected %d got %d", i, tests[i].variant, variant)
+ }
+
+ if tests[i].variant == VariantIETF {
+ if version := uuid.Version(); version != tests[i].version {
+ t.Errorf("Version #%d: expected %d got %d", i, tests[i].version, version)
+ }
+ }
+ }
+}
+
+func TestNewRandom(t *testing.T) {
+ for i := 0; i < 20; i++ {
+ uuid := NewRandom()
+
+ if variant := uuid.Variant(); variant != VariantIETF {
+ t.Errorf("wrong variant. expected %d got %d", VariantIETF, variant)
+ }
+ if version := uuid.Version(); version != 4 {
+ t.Errorf("wrong version. expected %d got %d", 4, version)
+ }
+ }
+}
+
+func TestNewTime(t *testing.T) {
+ var node []byte
+ timestamp := uint64(0)
+ for i := 0; i < 20; i++ {
+ uuid := NewTime()
+
+ if variant := uuid.Variant(); variant != VariantIETF {
+ t.Errorf("wrong variant. expected %d got %d", VariantIETF, variant)
+ }
+ if version := uuid.Version(); version != 1 {
+ t.Errorf("wrong version. expected %d got %d", 1, version)
+ }
+
+ if n := uuid.Node(); !bytes.Equal(n, node) && i > 0 {
+ t.Errorf("wrong node. expected %x, got %x", node, n)
+ } else if i == 0 {
+ node = n
+ }
+
+ ts := uuid.Timestamp()
+ if ts < timestamp {
+ t.Errorf("timestamps must grow")
+ }
+ timestamp = ts
+ }
+}