| 1 |
ERLANG UUID |
| 2 |
=========== |
| 3 |
|
| 4 |
This module implements UUID v1, v3, v4, and v5 as of RFC 4122 |
| 5 |
(UUID variant 1 0). |
| 6 |
|
| 7 |
UUID v1 return a UUID generated by a timestamp and node id. |
| 8 |
UUID v3 return a UUID generated using MD5 and a given name within a namespace. |
| 9 |
UUID v4 return a UUID generated by a (pseudo) random number generator. |
| 10 |
UUID v5 return a UUID generated using SHA1 and a given name within a namespace. |
| 11 |
|
| 12 |
Source tracking available at |
| 13 |
|
| 14 |
http://github.com/avtobiff/erlang-uuid |
| 15 |
|
| 16 |
To clone the main developing repository invoke |
| 17 |
|
| 18 |
git clone https://github.com/avtobiff/erlang-uuid.git |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
BUILD AND INSTALL |
| 23 |
----------------- |
| 24 |
Build by invoking |
| 25 |
|
| 26 |
make |
| 27 |
|
| 28 |
Install to default $ERL_ROOT (/usr/lib/erlang) by invoking |
| 29 |
|
| 30 |
sudo make install |
| 31 |
|
| 32 |
Install to different $ERL_ROOT ($PREFIX/lib/erlang) by setting PREFIX |
| 33 |
|
| 34 |
sudo make PREFIX=/opt/erlang install |
| 35 |
|
| 36 |
Include in your own project using Rebar. Add this to your rebar.config |
| 37 |
|
| 38 |
{uuid, ".*", |
| 39 |
{git, "https://github.com/avtobiff/erlang-uuid.git", "master"}} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
LICENSE |
| 44 |
------- |
| 45 |
Erlang UUID is free software: you can redistribute it and/or modify |
| 46 |
it under the terms of the GNU Lesser General Public License as |
| 47 |
published by the Free Software Foundation, either version 3 of the |
| 48 |
License, or (at your option) any later version. |
| 49 |
|
| 50 |
Erlang UUID is distributed in the hope that it will be useful, |
| 51 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 52 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 53 |
GNU Lesser General Public License for more details. |
| 54 |
|
| 55 |
You should have received a copy of the GNU Lesser General Public |
| 56 |
License along with Erlang UUID. If not, see |
| 57 |
<http://www.gnu.org/licenses/>. |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
USE |
| 62 |
--- |
| 63 |
Example of usage |
| 64 |
|
| 65 |
1> uuid:to_string(uuid:uuid1()). |
| 66 |
"f412e400-c445-1131-bdc6-03f9e757eb34" |
| 67 |
2> uuid:to_string(uuid:uuid3(dns, "fqdn.example.com")). |
| 68 |
"06eaa791-8c2e-3b0d-8a07-c80979fd1b98" |
| 69 |
3> uuid:to_string(uuid:uuid3(uuid:uuid4(), "my name")). |
| 70 |
"fcf82b93-aa5e-3d79-b95e-726420f89e1b" |
| 71 |
4> uuid:to_string(uuid:uuid4()). |
| 72 |
"79f492f8-1337-4200-abcd-92bada1cacao" |
| 73 |
5> uuid:to_string(uuid:uuid5(dns, "fqdn.example.com")). |
| 74 |
"8fd7fa87-4c20-5809-a1b0-e07f5c224f02" |
| 75 |
6> uuid:to_string(uuid:uuid5(uuid:uuid4(), "my name")). |
| 76 |
"6ff58b11-e0b2-536c-b6be-bdccd38836a2" |
| 77 |
|
| 78 |
|
| 79 |
UUID v1 |
| 80 |
------- |
| 81 |
UUID v1 uses the number of 100 nanosecond intervals since the west adopted the |
| 82 |
gregorian calendar and the node id IEEE 802 (MAC) address. It is hackishly |
| 83 |
implemented and improvements can be made. |
| 84 |
|
| 85 |
Room for improvement: |
| 86 |
* Timestamp resolution is one (1) second which should be improved. |
| 87 |
* Clock sequence is random (simulating state is always unavailable). |
| 88 |
|
| 89 |
|
| 90 |
UUID v3 |
| 91 |
UUID v5 |
| 92 |
------- |
| 93 |
UUID v3 and UUID v5 uses MD5 and SHA1, respectivaly, to generate a UUID using a |
| 94 |
name and a namespace as initializer. Valid namespaces are the atoms: url, dns, |
| 95 |
oid, x500, nil or using a generated UUID either as a binary or as a UUID string |
| 96 |
representation. |
| 97 |
|
| 98 |
|
| 99 |
UUID v4 |
| 100 |
------- |
| 101 |
UUID v4 uses randomness to create a UUID, the six version and variant bits are |
| 102 |
set all the other 122 bits are randomly generated. |
| 103 |
|
| 104 |
|
| 105 |
UTILITIES |
| 106 |
--------- |
| 107 |
There are several utility functions for introspection of UUIDs. |
| 108 |
|
| 109 |
It is possible to extract variant and version with the functions with the same |
| 110 |
names, both take a UUID binary or UUID string representation. |
| 111 |
|
| 112 |
There are several predicate functions that takes a UUID binary or UUID string |
| 113 |
representation and returns a thruth value. The predicate is_rfc4122/1 returns |
| 114 |
true if the UUID implements RFC 4122 (variant 1 0, version 1, 3, 4, and 5). The |
| 115 |
predicates is_vN/1, where N is either 1, 3, 4, or 5. |
| 116 |
|
| 117 |
Example usage: |
| 118 |
|
| 119 |
1> uuid:version(uuid:uuid4()). |
| 120 |
4 |
| 121 |
2> uuid:is_v1(uuid:uuid4()). |
| 122 |
false |
| 123 |
3> uuid:is_v1(uuid:uuid1()). |
| 124 |
true |
| 125 |
4> uuid:is_rfc4122(uuid:uuid4()). |
| 126 |
true |
| 127 |
5> uuid:is_valid(uuid:uuid4()). |
| 128 |
true |
| 129 |
6> uuid:is_valid(<<1:128>>). |
| 130 |
false |
| 131 |
|
| 132 |
|
| 133 |
Per Andersson <[email protected]> Mon, 20 Feb 2012 21:01:47 +0100 |