diff options
author | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
---|---|---|
committer | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
commit | 107c1cdb09c575aa2f61d97f48d8587eb6bada4c (patch) | |
tree | ca7d008643efc555c388baeaf1d986e0b6b3e28c /vendor/github.com/hashicorp/go-uuid/uuid.go | |
parent | 844b5a68d8af4791755b8f0ad293cc99f5959183 (diff) | |
download | terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.gz terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.zst terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.zip |
Upgrade to 0.12
Diffstat (limited to 'vendor/github.com/hashicorp/go-uuid/uuid.go')
-rw-r--r-- | vendor/github.com/hashicorp/go-uuid/uuid.go | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/vendor/github.com/hashicorp/go-uuid/uuid.go b/vendor/github.com/hashicorp/go-uuid/uuid.go index ff9364c..911227f 100644 --- a/vendor/github.com/hashicorp/go-uuid/uuid.go +++ b/vendor/github.com/hashicorp/go-uuid/uuid.go | |||
@@ -15,9 +15,11 @@ func GenerateRandomBytes(size int) ([]byte, error) { | |||
15 | return buf, nil | 15 | return buf, nil |
16 | } | 16 | } |
17 | 17 | ||
18 | const uuidLen = 16 | ||
19 | |||
18 | // GenerateUUID is used to generate a random UUID | 20 | // GenerateUUID is used to generate a random UUID |
19 | func GenerateUUID() (string, error) { | 21 | func GenerateUUID() (string, error) { |
20 | buf, err := GenerateRandomBytes(16) | 22 | buf, err := GenerateRandomBytes(uuidLen) |
21 | if err != nil { | 23 | if err != nil { |
22 | return "", err | 24 | return "", err |
23 | } | 25 | } |
@@ -25,11 +27,11 @@ func GenerateUUID() (string, error) { | |||
25 | } | 27 | } |
26 | 28 | ||
27 | func FormatUUID(buf []byte) (string, error) { | 29 | func FormatUUID(buf []byte) (string, error) { |
28 | if len(buf) != 16 { | 30 | if buflen := len(buf); buflen != uuidLen { |
29 | return "", fmt.Errorf("wrong length byte slice (%d)", len(buf)) | 31 | return "", fmt.Errorf("wrong length byte slice (%d)", buflen) |
30 | } | 32 | } |
31 | 33 | ||
32 | return fmt.Sprintf("%08x-%04x-%04x-%04x-%12x", | 34 | return fmt.Sprintf("%x-%x-%x-%x-%x", |
33 | buf[0:4], | 35 | buf[0:4], |
34 | buf[4:6], | 36 | buf[4:6], |
35 | buf[6:8], | 37 | buf[6:8], |
@@ -38,16 +40,14 @@ func FormatUUID(buf []byte) (string, error) { | |||
38 | } | 40 | } |
39 | 41 | ||
40 | func ParseUUID(uuid string) ([]byte, error) { | 42 | func ParseUUID(uuid string) ([]byte, error) { |
41 | if len(uuid) != 36 { | 43 | if len(uuid) != 2 * uuidLen + 4 { |
42 | return nil, fmt.Errorf("uuid string is wrong length") | 44 | return nil, fmt.Errorf("uuid string is wrong length") |
43 | } | 45 | } |
44 | 46 | ||
45 | hyph := []byte("-") | 47 | if uuid[8] != '-' || |
46 | 48 | uuid[13] != '-' || | |
47 | if uuid[8] != hyph[0] || | 49 | uuid[18] != '-' || |
48 | uuid[13] != hyph[0] || | 50 | uuid[23] != '-' { |
49 | uuid[18] != hyph[0] || | ||
50 | uuid[23] != hyph[0] { | ||
51 | return nil, fmt.Errorf("uuid is improperly formatted") | 51 | return nil, fmt.Errorf("uuid is improperly formatted") |
52 | } | 52 | } |
53 | 53 | ||
@@ -57,7 +57,7 @@ func ParseUUID(uuid string) ([]byte, error) { | |||
57 | if err != nil { | 57 | if err != nil { |
58 | return nil, err | 58 | return nil, err |
59 | } | 59 | } |
60 | if len(ret) != 16 { | 60 | if len(ret) != uuidLen { |
61 | return nil, fmt.Errorf("decoded hex is the wrong length") | 61 | return nil, fmt.Errorf("decoded hex is the wrong length") |
62 | } | 62 | } |
63 | 63 | ||