Closed osintalex closed 12 months ago
Sadly, I think this is not possible without changing some of the basic constraints of this library. The ULID and the UUID both consist of a 128 bit-sequence, but the layout and interpretation of the underlying structure is very different. When converting a ULID to a UUID we could obviously set the bits of the UUID variant field accordingly, so that it complies with the RFC. This would however make it impossible to do the reverse operation and convert the UUID back to the same ULID.
ulid = ULID()
assert ulid == ULID.from_uuid(ulid.to_uuid()) # This would fail
This being said, I think there is no requirement from the ULID spec side that would hinder us from converting a ULID into a valid, let's say, UUID4.
Release 2.1.0
includes a method ULID.to_uuid4
which allows you to create an RFC 4122 compliant UUIDv4 from a given ULID.
Thank you!!
I'm creating UUIDs with ULID for use in an application. As part of some data validation libraries in that application, these UUIDs must be RFC_4122 compliant.
However, some of the UUIDs created with ULID fail this check:
This bit
uuid_value.variant == uuid.RFC_4122
is what the data validation library does to check that a UUID is RFC_4122 compliant. It would be great to have that supported with ULID if possible.