From 00476268870b01938800af9a5ca776695df13f5d Mon Sep 17 00:00:00 2001 From: Philip Prindeville Date: Tue, 5 Sep 2017 11:19:26 +0200 Subject: libuuid: add support for hash-based UUIDs Adding V3 and V5 UUIDs per RFC-4122. [kzak@redhat.com: - fix symbols file] Signed-off-by: Philip Prindeville Signed-off-by: Karel Zak --- tests/helpers/Makemodule.am | 7 +++++++ tests/helpers/test_sha1.c | 29 +++++++++++++++++++++++++++++ tests/helpers/test_uuid_namespace.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 tests/helpers/test_sha1.c create mode 100644 tests/helpers/test_uuid_namespace.c (limited to 'tests/helpers') diff --git a/tests/helpers/Makemodule.am b/tests/helpers/Makemodule.am index 3070a8bbc..2f2611b67 100644 --- a/tests/helpers/Makemodule.am +++ b/tests/helpers/Makemodule.am @@ -5,6 +5,9 @@ test_byteswap_SOURCES = tests/helpers/test_byteswap.c check_PROGRAMS += test_md5 test_md5_SOURCES = tests/helpers/test_md5.c lib/md5.c +check_PROGRAMS += test_sha1 +test_sha1_SOURCES = tests/helpers/test_sha1.c lib/sha1.c + check_PROGRAMS += test_pathnames test_pathnames_SOURCES = tests/helpers/test_pathnames.c @@ -18,3 +21,7 @@ test_sigreceive_LDADD = $(LDADD) libcommon.la check_PROGRAMS += test_tiocsti test_tiocsti_SOURCES = tests/helpers/test_tiocsti.c +check_PROGRAMS += test_uuid_namespace +test_uuid_namespace_SOURCES = tests/helpers/test_uuid_namespace.c \ + libuuid/src/predefined.c libuuid/src/unpack.c libuuid/src/unparse.c + diff --git a/tests/helpers/test_sha1.c b/tests/helpers/test_sha1.c new file mode 100644 index 000000000..5a1972935 --- /dev/null +++ b/tests/helpers/test_sha1.c @@ -0,0 +1,29 @@ + +#include +#include + +#include "sha1.h" + +int main(void) +{ + int i, ret; + SHA1_CTX ctx; + unsigned char digest[SHA1LENGTH]; + unsigned char buf[BUFSIZ]; + + SHA1Init( &ctx ); + + while(!feof(stdin) && !ferror(stdin)) { + ret = fread(buf, 1, sizeof(buf), stdin); + if (ret) + SHA1Update( &ctx, buf, ret ); + } + + fclose(stdin); + SHA1Final( digest, &ctx ); + + for (i = 0; i < SHA1LENGTH; i++) + printf( "%02x", digest[i] ); + printf("\n"); + return 0; +} diff --git a/tests/helpers/test_uuid_namespace.c b/tests/helpers/test_uuid_namespace.c new file mode 100644 index 000000000..1bbf8754d --- /dev/null +++ b/tests/helpers/test_uuid_namespace.c @@ -0,0 +1,37 @@ +#include +#include +#include + +#include "../libuuid/src/uuid.h" + +static void get_template(const char *ns) +{ + const uuid_t *uuidptr; + char buf[37]; + + uuidptr = uuid_get_template(ns); + if (uuidptr == NULL) + strcpy(buf, "NULL"); + else + uuid_unparse_lower(*uuidptr, buf); + + printf("uuid_get_template %s returns %s\n", (ns ? ns : "NULL"), buf); +} + +int main(void) +{ + get_template("dns"); + + get_template("url"); + + get_template("oid"); + + get_template("x500"); + + get_template(NULL); + get_template(""); + get_template("unknown"); + + exit(0); +} + -- cgit v1.2.3-55-g7522