diff options
author | Zahary Karadjov <zahary@gmail.comy> | 2011-09-07 15:47:03 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.comy> | 2011-09-20 14:13:45 +0300 |
commit | 9b95ca407d38fecb23a39cf0f6d92ed838e57623 (patch) | |
tree | ff77e2ec240b4b4a4d634df2b28d1fa5c11c4095 /lib/pure | |
parent | 91351e5996e48ba1e3235a6dbaf37f9102e067b6 (diff) | |
download | Nim-9b95ca407d38fecb23a39cf0f6d92ed838e57623.tar.gz |
Some very small steps towards an uuid generation module.
I did some basic research on cross-platform UUID generation and didn't want to lose any information, so this code only represents what I learned (uuidMacTime should work tho).
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/uuid.nim | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/pure/uuid.nim b/lib/pure/uuid.nim new file mode 100644 index 000000000..36fa9e445 --- /dev/null +++ b/lib/pure/uuid.nim @@ -0,0 +1,30 @@ +# This module implements the RFC 4122 specification for generating universally unique identifiers +# http://en.wikipedia.org/wiki/Universally_unique_identifier + +# This module is a work-in-progress +# If you want to help with the implementation, take a loot at: +# http://dsource.org/projects/tango/docs/current/tango.util.uuid.Uuid.html + +type TUuid* = array[0..15, char] + +when defined(windows): + # This is actually available only on Windows 2000+ + type PUuid* {.importc: "UUID __RPC_FAR *", header: "<Rpc.h>".} = ptr TUuid + proc uuid1Sys*(uuid: PUuid) {.importc: "UuidCreateSequential", header: "<Rpc.h>".} + +else: + type PUuid {.importc: "uuid_t", header: "<uuid/uuid.h>".} = ptr TUuid + proc uuid1Sys*(uuid: PUuid) {.importc: "uuid_generate_time", header: "<uuid/uuid.h>".} + +# v1 UUIDs include the MAC address of the machine generating the ID and a timestamp +# This scheme has the strongest guaranty of uniqueness, but discloses when the ID was generated +proc uuidMacTime* : TUuid = uuid1Sys(addr(result)) + +# v4 UUID are created entirely using a random number generator. +# Some bits have fixed value in order to indicate the UUID type +proc uuidRandom*[RandomGenerator](rand: RandomGenerator) : TUuid = nil + +# v3 and v5 UUIDs are derived from given namespace and name using a secure hashing algorithm. +# v3 uses MD5, v5 uses SHA1. +proc uuidByName*[Hash](namespace: TUuid, name: string, hasher: Hash, v: int) : TUuid = nil + |