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