Skip to content

Commit

Permalink
finish updating rfc references to new number
Browse files Browse the repository at this point in the history
  • Loading branch information
kohenkatz authored May 10, 2024
1 parent beea71e commit 9fa75ca
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
14 changes: 7 additions & 7 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (g *Gen) NewV1() (UUID, error) {
copy(u[10:], hardwareAddr)

u.SetVersion(V1)
u.SetVariant(VariantRFC4122)
u.SetVariant(VariantRFC9562)

return u, nil
}
Expand All @@ -239,7 +239,7 @@ func (g *Gen) NewV1() (UUID, error) {
func (g *Gen) NewV3(ns UUID, name string) UUID {
u := newFromHash(md5.New(), ns, name)
u.SetVersion(V3)
u.SetVariant(VariantRFC4122)
u.SetVariant(VariantRFC9562)

return u
}
Expand All @@ -251,7 +251,7 @@ func (g *Gen) NewV4() (UUID, error) {
return Nil, err
}
u.SetVersion(V4)
u.SetVariant(VariantRFC4122)
u.SetVariant(VariantRFC9562)

return u, nil
}
Expand All @@ -260,7 +260,7 @@ func (g *Gen) NewV4() (UUID, error) {
func (g *Gen) NewV5(ns UUID, name string) UUID {
u := newFromHash(sha1.New(), ns, name)
u.SetVersion(V5)
u.SetVariant(VariantRFC4122)
u.SetVariant(VariantRFC9562)

return u
}
Expand Down Expand Up @@ -302,7 +302,7 @@ func (g *Gen) NewV6() (UUID, error) {
u.SetVersion(V6)

//overwrite first 2 bits of byte[8] for the variant
u.SetVariant(VariantRFC4122)
u.SetVariant(VariantRFC9562)

return u, nil
}
Expand Down Expand Up @@ -350,7 +350,7 @@ func (g *Gen) NewV7() (UUID, error) {
return Nil, err
}
//override first 2 bits of byte[8] for the variant
u.SetVariant(VariantRFC4122)
u.SetVariant(VariantRFC9562)

return u, nil
}
Expand Down Expand Up @@ -407,7 +407,7 @@ func (g *Gen) getHardwareAddr() ([]byte, error) {
if _, err = io.ReadFull(g.rand, g.hardwareAddr[:]); err != nil {
return
}
// Set multicast bit as recommended by RFC-4122
// Set multicast bit as recommended by RFC-9562
g.hardwareAddr[0] |= 0x01
})
if err != nil {
Expand Down
18 changes: 9 additions & 9 deletions generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func testNewV1Basic(t *testing.T) {
if got, want := u.Version(), V1; got != want {
t.Errorf("generated UUID with version %d, want %d", got, want)
}
if got, want := u.Variant(), VariantRFC4122; got != want {
if got, want := u.Variant(), VariantRFC9562; got != want {
t.Errorf("generated UUID with variant %d, want %d", got, want)
}
}
Expand All @@ -110,7 +110,7 @@ func testNewV1BasicWithOptions(t *testing.T) {
if got, want := u.Version(), V1; got != want {
t.Errorf("generated UUID with version %d, want %d", got, want)
}
if got, want := u.Variant(), VariantRFC4122; got != want {
if got, want := u.Variant(), VariantRFC9562; got != want {
t.Errorf("generated UUID with variant %d, want %d", got, want)
}
}
Expand Down Expand Up @@ -249,7 +249,7 @@ func testNewV3Basic(t *testing.T) {
if got, want := u.Version(), V3; got != want {
t.Errorf("NewV3(%v, %q): got version %d, want %d", ns, name, got, want)
}
if got, want := u.Variant(), VariantRFC4122; got != want {
if got, want := u.Variant(), VariantRFC9562; got != want {
t.Errorf("NewV3(%v, %q): got variant %d, want %d", ns, name, got, want)
}
want := "5df41881-3aed-3515-88a7-2f4a814cf09e"
Expand Down Expand Up @@ -296,7 +296,7 @@ func testNewV4Basic(t *testing.T) {
if got, want := u.Version(), V4; got != want {
t.Errorf("got version %d, want %d", got, want)
}
if got, want := u.Variant(), VariantRFC4122; got != want {
if got, want := u.Variant(), VariantRFC9562; got != want {
t.Errorf("got variant %d, want %d", got, want)
}
}
Expand Down Expand Up @@ -383,7 +383,7 @@ func testNewV5Basic(t *testing.T) {
if got, want := u.Version(), V5; got != want {
t.Errorf("NewV5(%v, %q): got version %d, want %d", ns, name, got, want)
}
if got, want := u.Variant(), VariantRFC4122; got != want {
if got, want := u.Variant(), VariantRFC9562; got != want {
t.Errorf("NewV5(%v, %q): got variant %d, want %d", ns, name, got, want)
}
want := "2ed6657d-e927-568b-95e1-2665a8aea6a2"
Expand Down Expand Up @@ -433,7 +433,7 @@ func testNewV6Basic(t *testing.T) {
if got, want := u.Version(), V6; got != want {
t.Errorf("generated UUID with version %d, want %d", got, want)
}
if got, want := u.Variant(), VariantRFC4122; got != want {
if got, want := u.Variant(), VariantRFC9562; got != want {
t.Errorf("generated UUID with variant %d, want %d", got, want)
}
}
Expand Down Expand Up @@ -624,7 +624,7 @@ func makeTestNewV7Basic() func(t *testing.T) {
if got, want := u.Version(), V7; got != want {
t.Errorf("got version %d, want %d", got, want)
}
if got, want := u.Variant(), VariantRFC4122; got != want {
if got, want := u.Variant(), VariantRFC9562; got != want {
t.Errorf("got variant %d, want %d", got, want)
}
}
Expand Down Expand Up @@ -652,7 +652,7 @@ func makeTestNewV7TestVector() func(t *testing.T) {
if got, want := u.Version(), V7; got != want {
t.Errorf("got version %d, want %d", got, want)
}
if got, want := u.Variant(), VariantRFC4122; got != want {
if got, want := u.Variant(), VariantRFC9562; got != want {
t.Errorf("got variant %d, want %d", got, want)
}
if got, want := u.String()[:15], "017f22e2-79b0-7"; got != want {
Expand All @@ -677,7 +677,7 @@ func makeTestNewV7Basic10000000() func(t *testing.T) {
if got, want := u.Version(), V7; got != want {
t.Errorf("got version %d, want %d", got, want)
}
if got, want := u.Variant(), VariantRFC4122; got != want {
if got, want := u.Variant(), VariantRFC9562; got != want {
t.Errorf("got variant %d, want %d", got, want)
}
}
Expand Down
20 changes: 10 additions & 10 deletions uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import (
// Size of a UUID in bytes.
const Size = 16

// UUID is an array type to represent the value of a UUID, as defined in RFC-4122.
// UUID is an array type to represent the value of a UUID, as defined in RFC-9562.
type UUID [Size]byte

// UUID versions.
Expand Down Expand Up @@ -145,12 +145,12 @@ func TimestampFromV7(u UUID) (Timestamp, error) {
return Timestamp(tsNanos), nil
}

// Nil is the nil UUID, as specified in RFC-4122, that has all 128 bits set to
// Nil is the nil UUID, as specified in RFC-9562, that has all 128 bits set to
// zero.
var Nil = UUID{}

// Max is the maximum UUID, as specified in a draft of RFC-4122, that has all 128 bits
// set to one. This feature is subject to removal if it is removed from the final draft of the RFC.
// Max is the maximum UUID, as specified in RFC-9562, that has all 128 bits
// set to one.
var Max = UUID{
0xFF,
0xFF,
Expand Down Expand Up @@ -194,7 +194,7 @@ func (u UUID) Variant() byte {
case (u[8] >> 7) == 0x00:
return VariantNCS
case (u[8] >> 6) == 0x02:
return VariantRFC4122
return VariantRFC9562
case (u[8] >> 5) == 0x06:
return VariantMicrosoft
case (u[8] >> 5) == 0x07:
Expand All @@ -209,7 +209,7 @@ func (u UUID) Bytes() []byte {
return u[:]
}

// encodeCanonical encodes the canonical RFC-4122 form of UUID u into the
// encodeCanonical encodes the canonical RFC-9562 form of UUID u into the
// first 36 bytes dst.
func encodeCanonical(dst []byte, u UUID) {
const hextable = "0123456789abcdef"
Expand All @@ -230,7 +230,7 @@ func encodeCanonical(dst []byte, u UUID) {
}
}

// String returns a canonical RFC-4122 string representation of the UUID:
// String returns a canonical RFC-9562 string representation of the UUID:
// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
func (u UUID) String() string {
var buf [36]byte
Expand All @@ -242,8 +242,8 @@ func (u UUID) String() string {
//
// The behavior is as follows:
// The 'x' and 'X' verbs output only the hex digits of the UUID, using a-f for 'x' and A-F for 'X'.
// The 'v', '+v', 's' and 'q' verbs return the canonical RFC-4122 string representation.
// The 'S' verb returns the RFC-4122 format, but with capital hex digits.
// The 'v', '+v', 's' and 'q' verbs return the canonical RFC-9562 string representation.
// The 'S' verb returns the RFC-9562 format, but with capital hex digits.
// The '#v' verb returns the "Go syntax" representation, which is a 16 byte array initializer.
// All other verbs not handled directly by the fmt package (like '%p') are unsupported and will return
// "%!verb(uuid.UUID=value)" as recommended by the fmt package.
Expand Down Expand Up @@ -296,7 +296,7 @@ func (u *UUID) SetVariant(v byte) {
switch v {
case VariantNCS:
u[8] = (u[8]&(0xff>>1) | (0x00 << 7))
case VariantRFC4122:
case VariantRFC9562:
u[8] = (u[8]&(0xff>>2) | (0x02 << 6))
case VariantMicrosoft:
u[8] = (u[8]&(0xff>>3) | (0x06 << 5))
Expand Down
2 changes: 1 addition & 1 deletion uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func testUUIDVariant(t *testing.T) {
},
{
u: UUID{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
want: VariantRFC4122,
want: VariantRFC9562,
},
{
u: UUID{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
Expand Down

0 comments on commit 9fa75ca

Please sign in to comment.