Loading...
Searching...
No Matches
RFC 4122 compliant UUID's

Provides RFC 4122 compliant UUID's. More...

Detailed Description

Provides RFC 4122 compliant UUID's.

This module provides RFC 4122 compliant UUID generation. The UUID stored in uuid_t struct is stored in network byte order.

Files

file  uuid.h
 RFC 4122 UUID functions
 

Data Structures

struct  uuid_t
 UUID layout. More...
 

Macros

#define UUID_NODE_LEN   (6U)
 Size of the node identifier in bytes.
 
#define UUID_STR_LEN   (36U)
 Size of a string UUID without null character.
 

Functions

void uuid_v3 (uuid_t *uuid, const uuid_t *ns, const uint8_t *name, size_t len)
 Generate a version 3(md5 based) UUID from a namespace and a byte array.
 
void uuid_v4 (uuid_t *uuid)
 Generate a version 4(Full random) UUID.
 
void uuid_v5 (uuid_t *uuid, const uuid_t *ns, const uint8_t *name, size_t len)
 Generate a version 5(sha1 based) UUID from a namespace and a byte array.
 
static unsigned uuid_version (const uuid_t *uuid)
 Retrieve the type number of a UUID.
 
static bool uuid_equal (const uuid_t *uuid1, const uuid_t *uuid2)
 Compare two UUID's.
 
void uuid_to_string (const uuid_t *uuid, char *str)
 Generate an UUID string from an UUID structure.
 
int uuid_from_string (uuid_t *uuid, const char *str)
 Populate an UUID structure from an UUID string.
 

Namespace IDs from RFC4122

Copied from rfc4122 Appendix C

const uuid_t uuid_namespace_dns
 DNS namespace UUID.
 
const uuid_t uuid_namespace_url
 URL namespace UUID.
 
const uuid_t uuid_namespace_iso
 ISO OID namespace UUID.
 
const uuid_t uuid_namespace_x500
 X.500 DN namespace UUID.
 

UUID version identifiers

#define UUID_V1   (0x01)
 Type 1 UUID - timestamp based

 
#define UUID_V2   (0x02)
 Type 2 UUID - DCE Security version.
 
#define UUID_V3   (0x03)
 Type 3 UUID - Name based with MD5

 
#define UUID_V4   (0x04)
 Type 4 UUID - Random generated

 
#define UUID_V5   (0x05)
 Type 5 UUID - Name based with SHA1.
 

Version part of the time_hi field

#define UUID_VERSION_MASK   (0xF000)
 

Macro Definition Documentation

◆ UUID_NODE_LEN

#define UUID_NODE_LEN   (6U)

Size of the node identifier in bytes.

Definition at line 39 of file uuid.h.

◆ UUID_STR_LEN

#define UUID_STR_LEN   (36U)

Size of a string UUID without null character.

Definition at line 41 of file uuid.h.

◆ UUID_V1

#define UUID_V1   (0x01)

Type 1 UUID - timestamp based

Definition at line 47 of file uuid.h.

◆ UUID_V2

#define UUID_V2   (0x02)

Type 2 UUID - DCE Security version.

Definition at line 48 of file uuid.h.

◆ UUID_V3

#define UUID_V3   (0x03)

Type 3 UUID - Name based with MD5

Definition at line 49 of file uuid.h.

◆ UUID_V4

#define UUID_V4   (0x04)

Type 4 UUID - Random generated

Definition at line 50 of file uuid.h.

◆ UUID_V5

#define UUID_V5   (0x05)

Type 5 UUID - Name based with SHA1.

Definition at line 51 of file uuid.h.

◆ UUID_VERSION_MASK

#define UUID_VERSION_MASK   (0xF000)

Definition at line 57 of file uuid.h.

Function Documentation

◆ uuid_equal()

static bool uuid_equal ( const uuid_t uuid1,
const uuid_t uuid2 
)
inlinestatic

Compare two UUID's.

Parameters
[in]uuid1First uuid to compare
[in]uuid2Second uuid to compare
Returns
True when equal

Definition at line 138 of file uuid.h.

◆ uuid_from_string()

int uuid_from_string ( uuid_t uuid,
const char *  str 
)

Populate an UUID structure from an UUID string.

Parameters
[out]uuidout UUID
[in]strnull-terminated input UUID string, must be UUID_STR_LEN bytes
Returns
0 on success, < 0 if str is not valid

◆ uuid_to_string()

void uuid_to_string ( const uuid_t uuid,
char *  str 
)

Generate an UUID string from an UUID structure.

Parameters
[in]uuidUUID
[out]strnull-terminated UUID string, must be at least UUID_STR_LEN + 1 bytes

◆ uuid_v3()

void uuid_v3 ( uuid_t uuid,
const uuid_t ns,
const uint8_t *  name,
size_t  len 
)

Generate a version 3(md5 based) UUID from a namespace and a byte array.

Parameters
[out]uuidUUID struct to fill
[in]nsNamespace UUID
[in]namePtr to byte array to use as name part
[in]lenLength of the byte array

◆ uuid_v4()

void uuid_v4 ( uuid_t uuid)

Generate a version 4(Full random) UUID.

Parameters
[out]uuidUUID struct to fill

◆ uuid_v5()

void uuid_v5 ( uuid_t uuid,
const uuid_t ns,
const uint8_t *  name,
size_t  len 
)

Generate a version 5(sha1 based) UUID from a namespace and a byte array.

Parameters
[out]uuidUUID struct to fill
[in]nsNamespace UUID
[in]namePtr to byte array to use as name part
[in]lenLength of the byte array

◆ uuid_version()

static unsigned uuid_version ( const uuid_t uuid)
inlinestatic

Retrieve the type number of a UUID.

Parameters
[in]uuidUUID to retrieve version number from
Returns
Version number

Definition at line 123 of file uuid.h.