Add support for Universally Unique Identifier (UUID) version 5 as per RFC 4122.
This commit is contained in:
parent
146fd99cb8
commit
604931c629
|
@ -62,6 +62,7 @@ TSK_BEGIN_DECLS
|
|||
#include "tsk_md5.h"
|
||||
#include "tsk_hmac.h"
|
||||
#include "tsk_base64.h"
|
||||
#include "tsk_uuid.h"
|
||||
|
||||
TSK_END_DECLS
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
/**@page tsk_string_page String utils Tutorial
|
||||
*/
|
||||
|
||||
static char HEX[] = "0123456789ABCDEF";
|
||||
static char HEX[] = "0123456789abcdef";
|
||||
|
||||
/**@ingroup tsk_string_group
|
||||
* From base 10 to base 16
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (C) 2009 Mamadou Diop.
|
||||
*
|
||||
* Contact: Mamadou Diop <diopmamadou@yahoo.fr>
|
||||
*
|
||||
* This file is part of Open Source Doubango Framework.
|
||||
*
|
||||
* DOUBANGO is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* DOUBANGO 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 General Public License
|
||||
* along with DOUBANGO.
|
||||
*
|
||||
*/
|
||||
|
||||
/**@file tsk_uuid.c
|
||||
* @brief Universally Unique Identifier (UUID version 5) implementation (RFC 4122).
|
||||
* This implementation is not fully conform to RFC 4122 but could be safely used to generate random UUIDs.
|
||||
*
|
||||
* @author Mamadou Diop <diopmamadou(at)yahoo.fr>
|
||||
*
|
||||
* @date Created: Sat Nov 8 16:54:58 2009 mdiop
|
||||
*/
|
||||
#include "tsk_uuid.h"
|
||||
|
||||
#include "tsk_sha1.h"
|
||||
#include "tsk_string.h"
|
||||
#include "tsk_time.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int tsk_uuidgenerate(tsk_uuidstring_t *result)
|
||||
{
|
||||
/* From wikipedia
|
||||
* Version 5 UUIDs use a scheme with SHA-1 hashing, otherwise it is the same idea as in version 3.
|
||||
* RFC 4122 states that version 5 is preferred over version 3 name based UUIDs.
|
||||
* Note that the 160 bit SHA-1 hash is truncated to 128 bits to make the length work out.
|
||||
*/
|
||||
tsk_sha1string_t sha1result;
|
||||
tsk_istr_t epoch;
|
||||
unsigned i, k;
|
||||
static char HEX[] = "0123456789abcdef";
|
||||
|
||||
tsk_itoa(tsk_time_epoch(), &epoch);
|
||||
tsk_sha1compute(epoch, sizeof(epoch), &sha1result);
|
||||
|
||||
/* XOR the SHA-1 result with random numbers. */
|
||||
for(i=0; i<(TSK_UUID_DIGEST_SIZE*2); i+=4){
|
||||
*((uint32_t*)&sha1result[i]) ^= rand();
|
||||
|
||||
for(k=0; k<sizeof(uint32_t); k++){
|
||||
sha1result[i+k] = HEX[sha1result[i+k] & 0x0F]; /* To hexa. */
|
||||
}
|
||||
}
|
||||
|
||||
/* f47ac10b-58cc-4372-a567-0e02b2c3d479 */
|
||||
memcpy(&(*result)[0], &sha1result[0], 8);
|
||||
(*result)[8] = '-';
|
||||
|
||||
memcpy(&(*result)[9], &sha1result[8], 4);
|
||||
(*result)[13] = '-';
|
||||
|
||||
memcpy(&(*result)[14], &sha1result[12], 4);
|
||||
(*result)[18] = '-';
|
||||
|
||||
memcpy(&(*result)[19], &sha1result[16], 4);
|
||||
(*result)[23] = '-';
|
||||
|
||||
memcpy(&(*result)[24], &sha1result[20], 12);
|
||||
(*result)[36] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (C) 2009 Mamadou Diop.
|
||||
*
|
||||
* Contact: Mamadou Diop <diopmamadou@yahoo.fr>
|
||||
*
|
||||
* This file is part of Open Source Doubango Framework.
|
||||
*
|
||||
* DOUBANGO is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* DOUBANGO 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 General Public License
|
||||
* along with DOUBANGO.
|
||||
*
|
||||
*/
|
||||
|
||||
/**@file tsk_uuid.h
|
||||
* @brief Universally Unique Identifier (UUID version 5) implementation (RFC 4122).
|
||||
* This implementation is not fully conform to RFC 4122 but could be safely used to generate random UUIDs.
|
||||
*
|
||||
* @author Mamadou Diop <diopmamadou(at)yahoo.fr>
|
||||
*
|
||||
* @date Created: Sat Nov 8 16:54:58 2009 mdiop
|
||||
*/
|
||||
#ifndef _TINYSAK_UUID_H_
|
||||
#define _TINYSAK_UUID_H_
|
||||
|
||||
#include "tinySAK_config.h"
|
||||
|
||||
TSK_BEGIN_DECLS
|
||||
|
||||
#define TSK_UUID_DIGEST_SIZE 16
|
||||
#define TSK_UUID_STRING_SIZE ((TSK_UUID_DIGEST_SIZE*2)+4/*-*/)
|
||||
|
||||
typedef char tsk_uuidstring_t[TSK_UUID_STRING_SIZE+1]; /**< Hexadecimal UUID digest string. */
|
||||
typedef char tsk_uuiddigest_t[TSK_UUID_DIGEST_SIZE]; /**< UUID digest bytes. */
|
||||
|
||||
TINYSAK_API int tsk_uuidgenerate(tsk_uuidstring_t *result);
|
||||
|
||||
TSK_END_DECLS
|
||||
|
||||
#endif /* _TINYSAK_UUID_H_ */
|
|
@ -46,10 +46,11 @@
|
|||
#define RUN_TEST_PARAMS 0
|
||||
#define RUN_TEST_TIMER 0
|
||||
#define RUN_TEST_RUNNABLE 0
|
||||
#define RUN_TEST_BUFFER 1
|
||||
#define RUN_TEST_BUFFER 0
|
||||
#define RUN_TEST_MD5 0
|
||||
#define RUN_TEST_SHA1 0
|
||||
#define RUN_TEST_BASE64 0
|
||||
#define RUN_TEST_UUID 1
|
||||
|
||||
#if RUN_TEST_LISTS || RUN_TEST_ALL
|
||||
#include "test_lists.h"
|
||||
|
@ -115,6 +116,9 @@
|
|||
#include "test_base64.h"
|
||||
#endif
|
||||
|
||||
#if RUN_TEST_UUID || RUN_TEST_ALL
|
||||
#include "test_uuid.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
@ -229,6 +233,12 @@ int main()
|
|||
/* test base64 encoding/decoding */
|
||||
test_base64();
|
||||
#endif
|
||||
|
||||
#if RUN_TEST_UUID || RUN_TEST_ALL
|
||||
/* test fake UUID (version5) */
|
||||
test_uuid();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
getchar();
|
||||
|
|
|
@ -431,6 +431,10 @@
|
|||
RelativePath=".\test_url.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\test_uuid.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\ReadMe.txt"
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (C) 2009 Mamadou Diop.
|
||||
*
|
||||
* Contact: Mamadou Diop <diopmamadou@yahoo.fr>
|
||||
*
|
||||
* This file is part of Open Source Doubango Framework.
|
||||
*
|
||||
* DOUBANGO is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* DOUBANGO 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 General Public License
|
||||
* along with DOUBANGO.
|
||||
*
|
||||
*/
|
||||
#ifndef _TEST_UUID_H_
|
||||
#define _TEST_UUID_H_
|
||||
|
||||
void test_uuid()
|
||||
{
|
||||
tsk_uuidstring_t uuid;
|
||||
|
||||
tsk_uuidgenerate(&uuid);
|
||||
|
||||
TSK_DEBUG_INFO("Generated UUID: %s", uuid);
|
||||
}
|
||||
|
||||
#endif /* _TEST_UUID_H_ */
|
||||
|
|
@ -458,6 +458,10 @@
|
|||
RelativePath=".\src\tsk_url.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\tsk_uuid.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\tsk_xml.h"
|
||||
>
|
||||
|
@ -568,6 +572,10 @@
|
|||
RelativePath=".\src\tsk_url.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\tsk_uuid.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\tsk_xml.c"
|
||||
>
|
||||
|
|
Loading…
Reference in New Issue