From f0bd7c3a9dd13bf69ddfcf6587e07bfa1d52a649 Mon Sep 17 00:00:00 2001 From: Anaminus Date: Tue, 14 Aug 2018 10:17:00 -0500 Subject: [PATCH] Remove dependency on satori/go.uuid (closes #6). This package apparently has problems. Only a small subset of any such package is needed anyway (generating V4 UUIDs). So instead of figuring out which fork to use, it's much easier to just implement it directly. --- ref.go | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/ref.go b/ref.go index 2530dba..0036c24 100644 --- a/ref.go +++ b/ref.go @@ -1,9 +1,8 @@ package rbxfile import ( - "encoding/hex" - "github.com/satori/go.uuid" - "strings" + "crypto/rand" + "io" ) // PropRef specifies the property of an instance that is a reference, which is @@ -81,8 +80,35 @@ func IsEmptyReference(ref string) bool { } } +func hexEncode(dst, src []byte) { + const hextable = "0123456789ABCDEF" + for i := len(src) - 1; i >= 0; i-- { + dst[i*2+1] = hextable[src[i]&0x0f] + dst[i*2] = hextable[src[i]>>4] + } +} + +func generateUUID() string { + var buf [36]byte + if _, err := io.ReadFull(rand.Reader, buf[:16]); err != nil { + panic(err) + } + buf[6] = (buf[6] & 0x0F) | 0x40 // Version 4 ; 0100XXXX + buf[8] = (buf[8] & 0x3F) | 0x80 // Variant RFC4122 ; 10XXXXXX + hexEncode(buf[24:36], buf[10:16]) + buf[23] = '-' + hexEncode(buf[19:23], buf[8:10]) + buf[18] = '-' + hexEncode(buf[14:18], buf[6:8]) + buf[13] = '-' + hexEncode(buf[9:13], buf[4:6]) + buf[8] = '-' + hexEncode(buf[0:8], buf[0:4]) + return string(buf[:]) +} + // GenerateReference generates a unique string that can be used as a reference // to an Instance. func GenerateReference() string { - return "RBX" + strings.ToUpper(hex.EncodeToString(uuid.NewV4().Bytes())) + return "RBX" + generateUUID() }