diff options
author | Felix Lange <fjl@twurst.com> | 2015-09-14 18:06:59 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-09-14 18:06:59 +0800 |
commit | a9c809b441146dcd2c3f4d174f00148a510aeb75 (patch) | |
tree | ce7bb6b4597c97405fed4621e54df5e8bb24c884 | |
parent | 55ed8d108d72d12543ecdc6d8c9d9978392dabf0 (diff) | |
parent | 0d4072777520a665637937efd440e06f18ea0626 (diff) | |
download | dexon-a9c809b441146dcd2c3f4d174f00148a510aeb75.tar.gz dexon-a9c809b441146dcd2c3f4d174f00148a510aeb75.tar.zst dexon-a9c809b441146dcd2c3f4d174f00148a510aeb75.zip |
Merge pull request #1792 from jeffallen/uuid
Change go-uuid to use the current supported repository.
-rw-r--r-- | Godeps/Godeps.json | 9 | ||||
-rw-r--r-- | Godeps/_workspace/src/github.com/pborman/uuid/CONTRIBUTORS | 1 | ||||
-rw-r--r-- | Godeps/_workspace/src/github.com/pborman/uuid/LICENSE (renamed from Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/LICENSE) | 2 | ||||
-rw-r--r-- | Godeps/_workspace/src/github.com/pborman/uuid/dce.go (renamed from Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/dce.go) | 0 | ||||
-rw-r--r-- | Godeps/_workspace/src/github.com/pborman/uuid/doc.go (renamed from Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/doc.go) | 0 | ||||
-rw-r--r-- | Godeps/_workspace/src/github.com/pborman/uuid/hash.go (renamed from Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/hash.go) | 0 | ||||
-rw-r--r-- | Godeps/_workspace/src/github.com/pborman/uuid/json.go | 30 | ||||
-rw-r--r-- | Godeps/_workspace/src/github.com/pborman/uuid/json_test.go | 32 | ||||
-rw-r--r-- | Godeps/_workspace/src/github.com/pborman/uuid/node.go (renamed from Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/node.go) | 0 | ||||
-rw-r--r-- | Godeps/_workspace/src/github.com/pborman/uuid/seq_test.go | 66 | ||||
-rw-r--r-- | Godeps/_workspace/src/github.com/pborman/uuid/sql.go | 40 | ||||
-rw-r--r-- | Godeps/_workspace/src/github.com/pborman/uuid/sql_test.go | 53 | ||||
-rw-r--r-- | Godeps/_workspace/src/github.com/pborman/uuid/time.go (renamed from Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/time.go) | 10 | ||||
-rw-r--r-- | Godeps/_workspace/src/github.com/pborman/uuid/util.go (renamed from Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/util.go) | 0 | ||||
-rw-r--r-- | Godeps/_workspace/src/github.com/pborman/uuid/uuid.go (renamed from Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/uuid.go) | 0 | ||||
-rw-r--r-- | Godeps/_workspace/src/github.com/pborman/uuid/uuid_test.go (renamed from Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/uuid_test.go) | 0 | ||||
-rw-r--r-- | Godeps/_workspace/src/github.com/pborman/uuid/version1.go (renamed from Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/version1.go) | 4 | ||||
-rw-r--r-- | Godeps/_workspace/src/github.com/pborman/uuid/version4.go (renamed from Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/version4.go) | 0 | ||||
-rw-r--r-- | crypto/crypto.go | 2 | ||||
-rw-r--r-- | crypto/key.go | 2 | ||||
-rw-r--r-- | crypto/key_store_passphrase.go | 2 |
21 files changed, 237 insertions, 16 deletions
diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 7c6dd59b1..e4b37a12e 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -6,11 +6,6 @@ ], "Deps": [ { - "ImportPath": "code.google.com/p/go-uuid/uuid", - "Comment": "null-12", - "Rev": "7dda39b2e7d5e265014674c5af696ba4186679e9" - }, - { "ImportPath": "github.com/codegangsta/cli", "Comment": "1.2.0-95-g9b2bd2b", "Rev": "9b2bd2b3489748d4d0a204fa4eb2ee9e89e0ebc6" @@ -63,6 +58,10 @@ "Rev": "675ffd907b7401b8a709a5ef2249978af5616bb2" }, { + "ImportPath": "github.com/pborman/uuid", + "Rev": "cccd189d45f7ac3368a0d127efb7f4d08ae0b655" + }, + { "ImportPath": "github.com/peterh/liner", "Rev": "29f6a646557d83e2b6e9ba05c45fbea9c006dbe8" }, diff --git a/Godeps/_workspace/src/github.com/pborman/uuid/CONTRIBUTORS b/Godeps/_workspace/src/github.com/pborman/uuid/CONTRIBUTORS new file mode 100644 index 000000000..b382a04ed --- /dev/null +++ b/Godeps/_workspace/src/github.com/pborman/uuid/CONTRIBUTORS @@ -0,0 +1 @@ +Paul Borman <borman@google.com> diff --git a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/LICENSE b/Godeps/_workspace/src/github.com/pborman/uuid/LICENSE index ab6b011a1..5dc68268d 100644 --- a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/LICENSE +++ b/Godeps/_workspace/src/github.com/pborman/uuid/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009 Google Inc. All rights reserved. +Copyright (c) 2009,2014 Google Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are diff --git a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/dce.go b/Godeps/_workspace/src/github.com/pborman/uuid/dce.go index 50a0f2d09..50a0f2d09 100644 --- a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/dce.go +++ b/Godeps/_workspace/src/github.com/pborman/uuid/dce.go diff --git a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/doc.go b/Godeps/_workspace/src/github.com/pborman/uuid/doc.go index d8bd013e6..d8bd013e6 100644 --- a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/doc.go +++ b/Godeps/_workspace/src/github.com/pborman/uuid/doc.go diff --git a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/hash.go b/Godeps/_workspace/src/github.com/pborman/uuid/hash.go index cdd4192fd..cdd4192fd 100644 --- a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/hash.go +++ b/Godeps/_workspace/src/github.com/pborman/uuid/hash.go diff --git a/Godeps/_workspace/src/github.com/pborman/uuid/json.go b/Godeps/_workspace/src/github.com/pborman/uuid/json.go new file mode 100644 index 000000000..760580a50 --- /dev/null +++ b/Godeps/_workspace/src/github.com/pborman/uuid/json.go @@ -0,0 +1,30 @@ +// Copyright 2014 Google Inc. 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 "errors" + +func (u UUID) MarshalJSON() ([]byte, error) { + if len(u) == 0 { + return []byte(`""`), nil + } + return []byte(`"` + u.String() + `"`), nil +} + +func (u *UUID) UnmarshalJSON(data []byte) error { + if len(data) == 0 || string(data) == `""` { + return nil + } + if len(data) < 2 || data[0] != '"' || data[len(data)-1] != '"' { + return errors.New("invalid UUID format") + } + data = data[1 : len(data)-1] + uu := Parse(string(data)) + if uu == nil { + return errors.New("invalid UUID format") + } + *u = uu + return nil +} diff --git a/Godeps/_workspace/src/github.com/pborman/uuid/json_test.go b/Godeps/_workspace/src/github.com/pborman/uuid/json_test.go new file mode 100644 index 000000000..b5eae0924 --- /dev/null +++ b/Godeps/_workspace/src/github.com/pborman/uuid/json_test.go @@ -0,0 +1,32 @@ +// Copyright 2014 Google Inc. 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 ( + "encoding/json" + "reflect" + "testing" +) + +var testUUID = Parse("f47ac10b-58cc-0372-8567-0e02b2c3d479") + +func TestJSON(t *testing.T) { + type S struct { + ID1 UUID + ID2 UUID + } + s1 := S{ID1: testUUID} + data, err := json.Marshal(&s1) + if err != nil { + t.Fatal(err) + } + var s2 S + if err := json.Unmarshal(data, &s2); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(&s1, &s2) { + t.Errorf("got %#v, want %#v", s2, s1) + } +} diff --git a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/node.go b/Godeps/_workspace/src/github.com/pborman/uuid/node.go index dd0a8ac18..dd0a8ac18 100644 --- a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/node.go +++ b/Godeps/_workspace/src/github.com/pborman/uuid/node.go diff --git a/Godeps/_workspace/src/github.com/pborman/uuid/seq_test.go b/Godeps/_workspace/src/github.com/pborman/uuid/seq_test.go new file mode 100644 index 000000000..3b3d1430d --- /dev/null +++ b/Godeps/_workspace/src/github.com/pborman/uuid/seq_test.go @@ -0,0 +1,66 @@ +// Copyright 2014 Google Inc. 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 ( + "flag" + "runtime" + "testing" + "time" +) + +// This test is only run when --regressions is passed on the go test line. +var regressions = flag.Bool("regressions", false, "run uuid regression tests") + +// TestClockSeqRace tests for a particular race condition of returning two +// identical Version1 UUIDs. The duration of 1 minute was chosen as the race +// condition, before being fixed, nearly always occured in under 30 seconds. +func TestClockSeqRace(t *testing.T) { + if !*regressions { + t.Skip("skipping regression tests") + } + duration := time.Minute + + done := make(chan struct{}) + defer close(done) + + ch := make(chan UUID, 10000) + ncpu := runtime.NumCPU() + switch ncpu { + case 0, 1: + // We can't run the test effectively. + t.Skip("skipping race test, only one CPU detected") + return + default: + runtime.GOMAXPROCS(ncpu) + } + for i := 0; i < ncpu; i++ { + go func() { + for { + select { + case <-done: + return + case ch <- NewUUID(): + } + } + }() + } + + uuids := make(map[string]bool) + cnt := 0 + start := time.Now() + for u := range ch { + s := u.String() + if uuids[s] { + t.Errorf("duplicate uuid after %d in %v: %s", cnt, time.Since(start), s) + return + } + uuids[s] = true + if time.Since(start) > duration { + return + } + cnt++ + } +} diff --git a/Godeps/_workspace/src/github.com/pborman/uuid/sql.go b/Godeps/_workspace/src/github.com/pborman/uuid/sql.go new file mode 100644 index 000000000..2d7679e2a --- /dev/null +++ b/Godeps/_workspace/src/github.com/pborman/uuid/sql.go @@ -0,0 +1,40 @@ +// Copyright 2015 Google Inc. 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 ( + "errors" + "fmt" +) + +// Scan implements sql.Scanner so UUIDs can be read from databases transparently +// Currently, database types that map to string and []byte are supported. Please +// consult database-specific driver documentation for matching types. +func (uuid *UUID) Scan(src interface{}) error { + switch src.(type) { + case string: + // see uuid.Parse for required string format + parsed := Parse(src.(string)) + + if parsed == nil { + return errors.New("Scan: invalid UUID format") + } + + *uuid = parsed + case []byte: + // assumes a simple slice of bytes, just check validity and store + u := UUID(src.([]byte)) + + if u.Variant() == Invalid { + return errors.New("Scan: invalid UUID format") + } + + *uuid = u + default: + return fmt.Errorf("Scan: unable to scan type %T into UUID", src) + } + + return nil +} diff --git a/Godeps/_workspace/src/github.com/pborman/uuid/sql_test.go b/Godeps/_workspace/src/github.com/pborman/uuid/sql_test.go new file mode 100644 index 000000000..d643567ee --- /dev/null +++ b/Godeps/_workspace/src/github.com/pborman/uuid/sql_test.go @@ -0,0 +1,53 @@ +// Copyright 2015 Google Inc. 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 ( + "strings" + "testing" +) + +func TestScan(t *testing.T) { + var stringTest string = "f47ac10b-58cc-0372-8567-0e02b2c3d479" + var byteTest []byte = Parse(stringTest) + var badTypeTest int = 6 + var invalidTest string = "f47ac10b-58cc-0372-8567-0e02b2c3d4" + var invalidByteTest []byte = Parse(invalidTest) + + var uuid UUID + err := (&uuid).Scan(stringTest) + if err != nil { + t.Fatal(err) + } + + err = (&uuid).Scan(byteTest) + if err != nil { + t.Fatal(err) + } + + err = (&uuid).Scan(badTypeTest) + if err == nil { + t.Error("int correctly parsed and shouldn't have") + } + if !strings.Contains(err.Error(), "unable to scan type") { + t.Error("attempting to parse an int returned an incorrect error message") + } + + err = (&uuid).Scan(invalidTest) + if err == nil { + t.Error("invalid uuid was parsed without error") + } + if !strings.Contains(err.Error(), "invalid UUID") { + t.Error("attempting to parse an invalid UUID returned an incorrect error message") + } + + err = (&uuid).Scan(invalidByteTest) + if err == nil { + t.Error("invalid byte uuid was parsed without error") + } + if !strings.Contains(err.Error(), "invalid UUID") { + t.Error("attempting to parse an invalid byte UUID returned an incorrect error message") + } +} diff --git a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/time.go b/Godeps/_workspace/src/github.com/pborman/uuid/time.go index b9369c200..7ebc9bef1 100644 --- a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/time.go +++ b/Godeps/_workspace/src/github.com/pborman/uuid/time.go @@ -40,15 +40,15 @@ func (t Time) UnixTime() (sec, nsec int64) { } // GetTime returns the current Time (100s of nanoseconds since 15 Oct 1582) and -// adjusts the clock sequence as needed. An error is returned if the current -// time cannot be determined. -func GetTime() (Time, error) { +// clock sequence as well as adjusting the clock sequence as needed. An error +// is returned if the current time cannot be determined. +func GetTime() (Time, uint16, error) { defer mu.Unlock() mu.Lock() return getTime() } -func getTime() (Time, error) { +func getTime() (Time, uint16, error) { t := timeNow() // If we don't have a clock sequence already, set one. @@ -63,7 +63,7 @@ func getTime() (Time, error) { clock_seq = ((clock_seq + 1) & 0x3fff) | 0x8000 } lasttime = now - return Time(now), nil + return Time(now), clock_seq, nil } // ClockSequence returns the current clock sequence, generating one if not diff --git a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/util.go b/Godeps/_workspace/src/github.com/pborman/uuid/util.go index de40b102c..de40b102c 100644 --- a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/util.go +++ b/Godeps/_workspace/src/github.com/pborman/uuid/util.go diff --git a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/uuid.go b/Godeps/_workspace/src/github.com/pborman/uuid/uuid.go index 2920fae63..2920fae63 100644 --- a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/uuid.go +++ b/Godeps/_workspace/src/github.com/pborman/uuid/uuid.go diff --git a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/uuid_test.go b/Godeps/_workspace/src/github.com/pborman/uuid/uuid_test.go index 417ebeb26..417ebeb26 100644 --- a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/uuid_test.go +++ b/Godeps/_workspace/src/github.com/pborman/uuid/uuid_test.go diff --git a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/version1.go b/Godeps/_workspace/src/github.com/pborman/uuid/version1.go index 63580044b..0127eacfa 100644 --- a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/version1.go +++ b/Godeps/_workspace/src/github.com/pborman/uuid/version1.go @@ -19,7 +19,7 @@ func NewUUID() UUID { SetNodeInterface("") } - now, err := GetTime() + now, seq, err := GetTime() if err != nil { return nil } @@ -34,7 +34,7 @@ func NewUUID() UUID { binary.BigEndian.PutUint32(uuid[0:], time_low) binary.BigEndian.PutUint16(uuid[4:], time_mid) binary.BigEndian.PutUint16(uuid[6:], time_hi) - binary.BigEndian.PutUint16(uuid[8:], clock_seq) + binary.BigEndian.PutUint16(uuid[8:], seq) copy(uuid[10:], nodeID) return uuid diff --git a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/version4.go b/Godeps/_workspace/src/github.com/pborman/uuid/version4.go index b3d4a368d..b3d4a368d 100644 --- a/Godeps/_workspace/src/code.google.com/p/go-uuid/uuid/version4.go +++ b/Godeps/_workspace/src/github.com/pborman/uuid/version4.go diff --git a/crypto/crypto.go b/crypto/crypto.go index a474d6f13..b3a8d730b 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -33,12 +33,12 @@ import ( "encoding/json" "errors" - "code.google.com/p/go-uuid/uuid" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto/ecies" "github.com/ethereum/go-ethereum/crypto/secp256k1" "github.com/ethereum/go-ethereum/crypto/sha3" "github.com/ethereum/go-ethereum/rlp" + "github.com/pborman/uuid" "golang.org/x/crypto/pbkdf2" "golang.org/x/crypto/ripemd160" ) diff --git a/crypto/key.go b/crypto/key.go index d80b99759..35139b67f 100644 --- a/crypto/key.go +++ b/crypto/key.go @@ -23,8 +23,8 @@ import ( "encoding/json" "io" - "code.google.com/p/go-uuid/uuid" "github.com/ethereum/go-ethereum/common" + "github.com/pborman/uuid" ) const ( diff --git a/crypto/key_store_passphrase.go b/crypto/key_store_passphrase.go index f21af8dd9..c7ee00987 100644 --- a/crypto/key_store_passphrase.go +++ b/crypto/key_store_passphrase.go @@ -36,9 +36,9 @@ import ( "io" "reflect" - "code.google.com/p/go-uuid/uuid" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto/randentropy" + "github.com/pborman/uuid" "golang.org/x/crypto/pbkdf2" "golang.org/x/crypto/scrypt" ) |