Skip to content

Commit a776445

Browse files
Correctly set the variant bits of uuid1 (#59428)
1 parent 7ea37ab commit a776445

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

stdlib/UUIDs/src/UUIDs.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ function _build_uuid1(rng::AbstractRNG, timestamp::UInt64)
7474
# mask off clock sequence and node
7575
u &= 0x00000000000000003fffffffffffffff
7676

77-
# set the unicast/multicast bit and version
78-
u |= 0x00000000000010000000010000000000
77+
# set the version, variant, and unicast/multicast bit
78+
u |= 0x00000000000010008000010000000000
7979

8080
ts_low = timestamp & typemax(UInt32)
8181
ts_mid = (timestamp >> 32) & typemax(UInt16)

stdlib/UUIDs/test/runtests.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ u7 = uuid7()
4242
@test uuid_version(u7) == 7
4343
end
4444

45+
@testset "Extraction of variant bits" begin
46+
# RFC 4122, section 4.1.1
47+
uuid_variant(u::UUID) = Int((u.value >> 62) & 0x3)
48+
@test uuid_variant(u1) == 2
49+
@test uuid_variant(u4) == 2
50+
@test uuid_variant(u5) == 2
51+
@test uuid_variant(u7) == 2
52+
end
53+
4554
@testset "Parsing from string" begin
4655
@test u1 == UUID(string(u1)) == UUID(GenericString(string(u1)))
4756
@test u4 == UUID(string(u4)) == UUID(GenericString(string(u4)))

0 commit comments

Comments
 (0)