UUID V3 and V5 are not rfc compliant
trobert opened this issue · 1 comments
trobert commented
The UUID v3 and v5 generated by this lib are buggy. For example (V3):
val dnsNs = UUID.fromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
val name = "a-thing"
UUID.V3.from(dnsNs, name)
res1: UUID = a814fa2d-efaa-32b1-4d2c-3dd50ccaa107
the same using java.util.UUID.nameUUIDFromBytes
:
val buffer: ByteBuffer = ByteBuffer.allocate(16 + name.length)
buffer.putLong(dnsNs.getMostSignificantBits)
buffer.putLong(dnsNs.getLeastSignificantBits)
buffer.put(name.getBytes())
buffer.flip()
java.util.UUID.nameUUIDFromBytes(buffer.array())
res2: java.util.UUID = a814fa2d-efaa-32b1-8d0c-3dd50ccaa107
The UUID differ on two bytes:
- a814fa2d-efaa-32b1-4d2c-3dd50ccaa107
- a814fa2d-efaa-32b1-8d0c-3dd50ccaa107
The problem is that the RFC requires setting bits 63,62 (variant field) to 1,0 after hashing, but memeid updates bits 53,52 instead.
The java result is consistent with https://www.uuidtools.com/generate/v3 and other implementations of UUID I tried.
UUID.V5
has the same exact problem.