]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
uuidgen: add support for RFC9562 UUIDs
authorThomas Weißschuh <thomas@t-8ch.de>
Mon, 5 Feb 2024 15:06:46 +0000 (16:06 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Fri, 10 May 2024 08:36:26 +0000 (10:36 +0200)
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
bash-completion/uuidgen
misc-utils/uuidgen.1.adoc
misc-utils/uuidgen.c
tests/expected/uuid/uuidgen
tests/ts/uuid/uuidgen

index 45f690d45eaed4f32ce4162f9b561d5187e88271..96b91cd624fed2b2c4998d7ca4cc7a5dca79fa59 100644 (file)
@@ -31,6 +31,8 @@ _uuidgen_module()
                                --md5
                                --count
                                --sha1
+                               --time-v6
+                               --time-v7
                                --hex
                                --help
                                --version
index 659a7804dc827a67fcf323b63931bef8929899dd..1d89fe43d63963105183c1020a0e2ee1cdd17f02 100644 (file)
@@ -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[]
 
index 57769c1f40511b08ec2e13ac468e17eb18b50dfa..56dea3c711f1b99946b41d3902322623d8905ac7 100644 (file)
@@ -40,6 +40,8 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_(" -m, --md5             generate md5 hash\n"), out);
        fputs(_(" -C, --count <num>     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;
index b0d1d98e7412e1a214fc1d41467f8835ba426bf2..7d517af8a36dea9a371ff1292b4dc161a02d2ea4 100644 (file)
@@ -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
index cbaaefa7b3e1dec0240daf1fcd95fb81c06ea21b..48fab12f7be770709250e3d081f815d48027ff4f 100755 (executable)
@@ -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"