From: Thomas Weißschuh Date: Mon, 5 Feb 2024 15:06:46 +0000 (+0100) Subject: uuidgen: add support for RFC9562 UUIDs X-Git-Tag: v2.42-start~339^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a3d82ae138f4cd1534220773fcd8c29fa21ef540;p=thirdparty%2Futil-linux.git uuidgen: add support for RFC9562 UUIDs Signed-off-by: Thomas Weißschuh --- diff --git a/bash-completion/uuidgen b/bash-completion/uuidgen index 45f690d45..96b91cd62 100644 --- a/bash-completion/uuidgen +++ b/bash-completion/uuidgen @@ -31,6 +31,8 @@ _uuidgen_module() --md5 --count --sha1 + --time-v6 + --time-v7 --hex --help --version diff --git a/misc-utils/uuidgen.1.adoc b/misc-utils/uuidgen.1.adoc index 659a7804d..1d89fe43d 100644 --- a/misc-utils/uuidgen.1.adoc +++ b/misc-utils/uuidgen.1.adoc @@ -42,6 +42,12 @@ Use MD5 as the hash algorithm. *-s*, *--sha1*:: Use SHA1 as the hash algorithm. +*-6*, *--time-v6*:: +Generate a time-based UUID. This method creates a UUID based on the system clock plus and is lexicographically sortable according to the contained timestamp. + +*-7*, *--time-v7*:: +Generate a time-based UUID. This method creates a UUID based on the system clock plus and is lexicographically sortable according to the contained timestamp. + *-n*, *--namespace* _namespace_:: Generate the hash with the _namespace_ prefix. The _namespace_ is UUID, or '@ns' where "ns" is well-known predefined UUID addressed by namespace name (see above). @@ -71,6 +77,7 @@ uuidgen --sha1 --namespace @dns --name "www.example.com" *uuidparse*(1), *libuuid*(3), link:https://tools.ietf.org/html/rfc4122[RFC 4122] +link:https://tools.ietf.org/html/rfcXXXX[RFC XXXX] include::man-common/bugreports.adoc[] diff --git a/misc-utils/uuidgen.c b/misc-utils/uuidgen.c index 57769c1f4..56dea3c71 100644 --- a/misc-utils/uuidgen.c +++ b/misc-utils/uuidgen.c @@ -40,6 +40,8 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -m, --md5 generate md5 hash\n"), out); fputs(_(" -C, --count generate more uuids in loop\n"), out); fputs(_(" -s, --sha1 generate sha1 hash\n"), out); + fputs(_(" -6, --time-v6 generate time-based v6 uuid\n"), out); + fputs(_(" -7, --time-v7 generate time-based v7 uuid\n"), out); fputs(_(" -x, --hex interpret name as hex string\n"), out); fputs(USAGE_SEPARATOR, out); fprintf(out, USAGE_HELP_OPTIONS(21)); @@ -104,14 +106,16 @@ main (int argc, char *argv[]) {"md5", no_argument, NULL, 'm'}, {"count", required_argument, NULL, 'C'}, {"sha1", no_argument, NULL, 's'}, + {"time-v6", no_argument, NULL, '6'}, + {"time-v7", no_argument, NULL, '7'}, {"hex", no_argument, NULL, 'x'}, {NULL, 0, NULL, 0} }; static const ul_excl_t excl[] = { + { '6', '7', 'm', 'r', 's', 't' }, { 'C', 'm', 's' }, { 'N', 'r', 't' }, - { 'm', 'r', 's', 't' }, { 'n', 'r', 't' }, { 0 } }; @@ -122,7 +126,7 @@ main (int argc, char *argv[]) textdomain(PACKAGE); close_stdout_atexit(); - while ((c = getopt_long(argc, argv, "C:rtVhn:N:msx", longopts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "C:rtVhn:N:msx67", longopts, NULL)) != -1) { err_exclusive_options(c, longopts, excl, excl_st); @@ -151,6 +155,12 @@ main (int argc, char *argv[]) case 'x': is_hex = 1; break; + case '6': + do_type = UUID_TYPE_DCE_TIME_V6; + break; + case '7': + do_type = UUID_TYPE_DCE_TIME_V7; + break; case 'h': usage(); @@ -192,6 +202,12 @@ main (int argc, char *argv[]) case UUID_TYPE_DCE_TIME: uuid_generate_time(uu); break; + case UUID_TYPE_DCE_TIME_V6: + uuid_generate_time_v6(uu); + break; + case UUID_TYPE_DCE_TIME_V7: + uuid_generate_time_v7(uu); + break; case UUID_TYPE_DCE_RANDOM: uuid_generate_random(uu); break; diff --git a/tests/expected/uuid/uuidgen b/tests/expected/uuid/uuidgen index b0d1d98e7..7d517af8a 100644 --- a/tests/expected/uuid/uuidgen +++ b/tests/expected/uuid/uuidgen @@ -2,7 +2,15 @@ option: -r return values: 0 and 0 option: -t return values: 0 and 0 +option: -6 +return values: 0 and 0 +option: -7 +return values: 0 and 0 option: --random return values: 0 and 0 option: --time return values: 0 and 0 +option: --time-v6 +return values: 0 and 0 +option: --time-v7 +return values: 0 and 0 diff --git a/tests/ts/uuid/uuidgen b/tests/ts/uuid/uuidgen index cbaaefa7b..48fab12f7 100755 --- a/tests/ts/uuid/uuidgen +++ b/tests/ts/uuid/uuidgen @@ -37,8 +37,12 @@ test_flag() { test_flag -r test_flag -t +test_flag -6 +test_flag -7 test_flag --random test_flag --time +test_flag --time-v6 +test_flag --time-v7 rm -f "$OUTPUT_FILE"