Skip to content

spc476/SPCUUID

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SPCUUID: The rather complete UUID generation library

SPCUUID implements an API to generate RFC-9562 style UUIDs, which include 
the following UUID versions:

	1. the time based version (also uses a MAC address if found)
	2. not implemented/not described in RFC-9562
	3. name-based varsion which uses MD5 hashing
	4. a randomly generated UUID
	5. name-based version which uses SHA-1 hashing
	6. a better time based version (based on v1)
	7. based upon the Unix epoch time
	8. experimental/vendor specific

This library also includes definitions for the following UUIDs (as
specificed in RFC-4122):

	1. DNS  UUID: 6ba7b810-9dad-11d1-80b4-00c04fd430c8
	2. URL  UUID: 6ba7b811-9dad-11d1-80b4-00c04fd430c8
	3. OID  UUID: 6ba7b812-9dad-11d1-80b4-00c04fd430c8
	4. X500 UUID: 6ba7b814-9dad-11d1-80b4-00c04fd430c8
	5. NULL UUID: 00000000-0000-0000-0000-000000000000
	6. MAX  UUID: FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF

These are declared as:

	extern uuid__t const c_uuid_namespace_dns;
	extern uuid__t const c_uuid_namespace_url;
	extern uuid__t const c_uuid_namespace_oid;
	extern uuid__t const c_uuid_namespace_x500;
	extern uuid__t const c_uuid_null;
	extern uuid__t const c_uuid_max;

The following functions will return 0 if success and some non-zero value on
error (unless otherwise stated), suitable for use with strerror().  They are
defined as:

	int uuidlib_cmp(const uuid__t *a,const uuid__t *b);

		This function compares two UUIDs and returns a negative
		value if a is less than b, 0 if a is equal to b, and a
		positive value if a is larger than b.  

	int uuidlib_parse(uuid__t *uuid,const char *text);

		This function will parse a text representation of a UUID. 

	int uuidlib_toa(const uuid__t *uuid,char *dest,size_t);

		This function will format a uuid__t for display purposes.
		It returns the number of characters written (36) on success,
		a negative value if there was an error.

	int uuidlib_v1(uuid__t *uuid,int clockseq);

		Generates a version 1 UUID, based off a MAC address and
		the current time.  If a MAC address cannot be found, a
		random MAC will be generated.  If clockseq is less than
		0, a random clock sequence value will be generated;
		otherwise, the value given will be used.

	int uuidlib_v2(uuid__t *uuid);

		Not implemented---returns ENOSYS.

	int uuidlib_v3(
		uuid__t       *uuid,
		uuid__t const *ns,
		void    const *data,
		size_t         size
	);

		Generates a name-based UUID from the given UUID (ns) and
		data (data,size) using an MD5 hash.  You must link to
		-lcrypto if you use this function.

	int uuidlib_v4(uuid__t *uuid);

		Generates a random UUID.  This function assumes that srand()
		has been called prior.

	int uuidlib_v5(
		uuid__t       *uuid,
		uuid__t const *ns,
		void    const *data,
		size_t         size
	);
	
		Generates a name-based UUID from the given UUID (ns) and
		data (data,size) using an MD5 hash.  You must link to
		-lcrypto if you use this function.

	int uuidlib_v6(uuid__t *uuid,int clockseq);

		Generates a version 6 UUID, based off a MAC address and the
		current time.  If a MAC address cannot be found, a random
		MAC will be generated.  If clockseq is less than 0, a random
		clock sequence value will be generated; otherwise, the value
		given will be used.

	int uuidlib_v7(uuid__t *uuid);

		Generates a version 7 UUID, based off the UNIX epoch.  This
		function assumes that srand() has been called prior.

	int uuidlib_v8(uuid__t *uuid);

		This function asssumes that data in uuid has been initialized,
		and will only set the version to 8.

The Lua bindings:

	require "org.conman.uuid"

The predefined UUIDs are:

	org.conman.uuid.URL
	org.conman.uuid.DNS
	org.conman.uuid.X500
	org.conman.uuid.OID
	org.conman.uuid.NIL
	org.conman.uuid.MAX

Functions are:

	org.conman.uuid.parse(string)

		Parse a string into a UUID

	org.conman.uuid.breakout(uuid)

		Return a table with the UUID broken down into fields.

	org.conman.uuid()

		Return a v4 UUID (random UUID)

	org.conman.uuid(n)

		Return a v1 UUID (MAC/time based UUID).  If n < 0, then the
		"clock sequence" portion of the UUID will be randomly
		generated; otherwise, the value of n is used.  n should
		increase with each call; if you really don't care to manage
		this, passing in a -1 should be used.

	org.conman.uuid(n,true)

		Similar to v1 UUID, but instead returns a v6 UUID.

	org.conman.uuid(uuid,string)
	
		Return a v5 UUID (SHA-1 name-based UUID)

	org.conman.uuid(uuid,string,true)

		Return a v3 UUID (MD5 name-based UUID)

	org.conman.uuid(true)

		Return a v7 UUID (UNIX epoch time).

	org.conman.uuid(string)

		Return a v8 UUID (experiemental/vendor specific).  The input
		string is used as the basis of the UUID, but the version and
		variant portions of the UUID will be set accordingly.

UUIDs support the following metamethods:

	__tostring	- returns display format
	__eq		- compares two UUIDs
	__lt		- compares two UUIDs
	__le		- compares two UUIDs
	__len		- returns 16

About

C library to create UUIDs. Also included are Lua bindings.

Resources

License

Stars

Watchers

Forks

Packages

No packages published