Function std.uuid.sha1UUID
This function generates a name based (Version 5) UUID from a namespace
UUID and a name.
If no namespace UUID was passed, the empty UUID UUID
is used.
UUID sha1UUID
(
scope const(char)[] name,
scope const(UUID) namespace = UUID([cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u], )
) pure nothrow @nogc @safe;
UUID sha1UUID
(
scope const(ubyte)[] data,
scope const(UUID) namespace = UUID([cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u], )
) pure nothrow @nogc @safe;
Note
The default namespaces (dnsNamespace
, ...) defined by
this module should be used when appropriate.
CTFE
CTFE is not supported.
Note
RFC 4122 isn't very clear on how UUIDs should be generated from names.
It is possible that different implementations return different UUIDs
for the same input, so be warned. The implementation for UTF-8 strings
and byte arrays used by std
is compatible with Boost's implementation.
std
guarantees that the same input to this function will generate
the same output at any time, on any system (this especially means endianness
doesn't matter).
Note
This function does not provide overloads for wstring and dstring, as there's no clear answer on how that should be implemented. It could be argued, that string, wstring and dstring input should have the same output, but that wouldn't be compatible with Boost, which generates different output for strings and wstrings. It's always possible to pass wstrings and dstrings by using the ubyte[] function overload (but be aware of endianness issues!).
Example
//Use default UUID.init namespace
auto simpleID = sha1UUID("test.uuid.any.string");
//use a name-based id as namespace
auto namespace = sha1UUID("my.app");
auto id = sha1UUID("some-description", namespace);
Authors
Johannes Pfau