Code Monkey home page Code Monkey logo

erlang-uuid's Introduction

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 <[email protected]>  Mon, 20 Feb 2012 21:01:47 +0100

erlang-uuid's People

Contributors

avtobiff avatar orva avatar rflynn avatar volatiledream avatar wcummings avatar wk8 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

erlang-uuid's Issues

OS X Mavericks make install fails

When installing with 'make install' on OSX Mavericks, the install fails due to the appfile version number substitution.

sh-3.2# make install
erl -make
create dist directory and install files
mkdir -p /usr/lib/erlang/lib/uuid- {vsn, "0.4.4"},/ebin
install -m0644 ebin/* /usr/lib/erlang/lib/uuid- {vsn, "0.4.4"},/ebin
install: /usr/lib/erlang/lib/uuid-: Inappropriate file type or format
make: *** [install] Error 71
sh-3.2#

hex package

Is it possible to get this as an hex package?

I like this library but we want to publish a hex package, and hex is only supporting publishing of package if all deps is in hex.

UUIDv1 generation is incorrect

If I take a UUIDv1 generated with uuidgen -t and then take one generated by this library (less than a second later on the same machine, with uuid:to_string(uuid:uuid1())), the timestamp is wrong in the erlang-uuid version: '2012-12-07 05:27:59+0000' (uuidgen) vs. '1935-10-13 20:22:43+0000' (erlang-uuid). (I am parsing these by way of inserting them as columns into Cassandra, which sorts TimeUUID columns by their associated timestamp and displays them with their time value, not their UUID value, when selecting data at the cqlsh console.)

Fixes for hardware addresses that are zero or not six octets

Howdy, I've got two patches stored in my local git repository.

One corrects the directory hierarchy to move the include file into an include directory.

The other one fixes the case where a system has devices with hardware addresses that are zero or consist of other than six octets. Linux sit devices, for example, default to four bytes of zeros.

I can't create a text patch for the directory layout change, but the byte problem is included below.

If you want the direct (teste) push of both I need permissions.


src/uuid.erl | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/uuid.erl b/src/uuid.erl
index 38a27c2..ecb7a66 100644
--- a/src/uuid.erl
+++ b/src/uuid.erl
@@ -318,8 +318,12 @@ hwaddr_find([{"lo", _IfConfig}|Rest]) ->
     hwaddr_find(Rest);
  hwaddr_find([{_IfName, IfConfig}|Rest]) ->
     case lists:keyfind(hwaddr, 1, IfConfig) of
-        {hwaddr, HwAddr} ->
+        {hwaddr, [0,0,0,0,0,0] = _HwAddr} ->
+            hwaddr_find(Rest);
+        {hwaddr, HwAddr} when length(HwAddr) == 6 ->
             list_to_binary(HwAddr);
+        {hwaddr, _HwAddr} ->
+            hwaddr_find(Rest);
         false ->
             hwaddr_find(Rest)
     end;
-- 
2.22.0

comparison functions

I think this package needs comparison functions something like
compare(uuid1,uuid2)->boolean()
or
larger_than(uuid1,uuid2)->boolean() something that can be given to utilities like
lists:sort

I think it can be useful specifically for time based uuids.

uuid1() fails in Erlang 19.3 but not in Erlang 20

The same line:

uuid:to_string(uuid:uuid1()))

Fails in Erlang 19.3, but works in 20. In 19.3 it bombs with the error:

Failure/Error: {error,badarg,
                    [{uuid,to_string,1,
                         [{file,
                              "/tmp/_build/default/lib/uuid/src/uuid.erl"},
                          {line,238}]},

However,

uuid:to_string(uuid:uuid4())

works in both. I'm not an expert in Erlang, HOWEVER my guess is it has something to do with os.timestamp here: https://github.com/avtobiff/erlang-uuid/blob/master/src/uuid.erl#L101
This is just a guess of where the problem is because I recall that Erlang changed the behavior of this at some point.

Can't make

p src/uuid.app.src ebin/uuid.app
erl -make
{"init terminating in do_boot",{undef,[{make,all,[],[]},{init,start_it,1,[]},{init,start_em,1,[]}]}}

Crash dump was written to: erl_crash.dump
init terminating in do_boot ()
Makefile:17: recipe for target 'build' failed
make: *** [build] Error 1

Is there something i'm missing?

Generating invalid UUIDs.

17:19:00.019 [info] Application lager started on node nonode@nohost
17:19:00.020 [info] Distributed Erlang is not enabled, generating UUID.
17:19:00.022 [info] Generated UUID: <<158,154,190,66,38,226,17,232,155,216,0,0,0,0>>, converting to string.
17:19:00.022 [error] CRASH REPORT Process <0.1006.0> with 0 neighbours exited with reason: bad argument in uuid:to_string/1 line 238
17:19:00.023 [error] CRASH REPORT Process <0.1004.0> with 0 neighbours exited with reason: {{error,{badarg,[{uuid,to_string,1,[{file,"/tmp/exlam/deps/uuid/src/uuid.erl"},{line,238}]},

This is Amazon Linux.

Now, when I generate identifiers locally, with the same version of Erlang, I'm getting 16 byte identifiers. But, when I run it here, as you can see from the binary above, it's only 14 bytes. This is causing the uuid:to_string method to throw, because it doesn't match at line 238. Any thoughts on why this would happen on a particular variant of Linux?

I'm using uuid4().

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.