Uniq.UUID.uuid5
uuid5
, go back to Uniq.UUID module for more information.
Specs
Generates a UUID using the version 5 scheme, as described in RFC 4122
This scheme provides the means for generating UUIDs deterministically, given a namespace and a name. This means that with the same inputs, you get the same UUID as output.
The main difference between this and the version 5 scheme, is that version 3 uses MD5 for hashing, and version 5 uses SHA1. Both hashes are deprecated these days, but you should prefer version 5 unless otherwise required.
In this scheme, the timestamp, clock sequence and node value are constructed from the namespace and name, as described in RFC 4122, Section 4.3.
Namespaces
You may choose one of several options for namespacing your UUIDs:
- Use a predefined namespace. These are provided by RFC 4122 in order to provide namespacing for common types of names. See below.
- Use your own namespace. For this, simply generate a UUID to represent the namespace.
You may provide this UUID in whatever format is supported by
parse/1
. - Use
nil
. This is bound to a special-case UUID that has no intrinsic meaning, but is valid for use as a namespace.
The set of predefined namespaces consist of the following:
:dns
, intended for namespacing fully-qualified domain names:url
, intended for namespacing URLs:oid
, intended for namespacing ISO OIDs:x500
, intended for namespacing X.500 DNs (in DER or text output format)
Notes
One thing to be aware of with version 3 and 5 UUIDs, is that unlike version 1 and 6, the lexicographical ordering of UUIDs of generated one after the other, is entirely random, as the most significant bits are dependent upon the hash of the namespace and name, and thus not based on time or even the lexicographical ordering of the name.
This is generally worth the tradeoff in favor of determinism, but it is something to be aware of.
Likewise, since the generation is deterministic, care must be taken to ensure that you do not try to use the same name for two different objects within the same namespace. This should be obvious, but since the other schemes are not sensitive in this way, it is worth calling out.