]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cksum: use --tag format by default
authorPádraig Brady <P@draigBrady.com>
Mon, 13 Sep 2021 11:57:34 +0000 (12:57 +0100)
committerPádraig Brady <P@draigBrady.com>
Wed, 15 Sep 2021 19:44:18 +0000 (20:44 +0100)
This format is a better default, since it results in simpler usage,
as you don't need to specify --tag on generation or -a on
checking invocations.  Also it's a more general format supporting
mixed and length adjusted digests.

* doc/coreutils.texi (cksum invocation): Document a new --untagged
option, to use the older coreutils format.
(md5sum invocation): Mention that cksum doesn't support --tag.
* src/digest.c: Adjust cksum(1) to default to --tag,
and accept the new --untagged option.
* tests/misc/b2sum.sh: Adjust accordingly.
* tests/misc/cksum-a.sh: Likewise.
* tests/misc/cksum-c.sh: Likewise.

doc/coreutils.texi
src/digest.c
tests/misc/b2sum.sh
tests/misc/cksum-a.sh
tests/misc/cksum-c.sh
tests/misc/sm3sum.pl

index a5537d78977dfbdb4ed56547c39ee20bdb3fc16d..68bc4470a43e49a925967e810ad32462f1af3fdf 100644 (file)
@@ -3986,6 +3986,16 @@ Supported more modern digest algorithms are:
 @item --debug
 @opindex --debug
 Output extra information to stderr, like the checksum implementation being used.
+
+@item --untagged
+@opindex --untagged
+Output using the original coreutils format used by the other
+standalone checksum utilities like @command{md5sum} for example.
+This format has the checksum at the start of the line, and may be
+more amenable to further processing by other utilities,
+especially in combination with the @option{--zero} option.
+Note this does not identify the digest algorithm used for the checksum.
+@xref{md5sum invocation} for details of this format.
 @end table
 
 
@@ -4147,6 +4157,8 @@ indicating there was a failure.
 @item --tag
 @opindex --tag
 @cindex BSD output
+Note this option is not supported by the @command{cksum} command,
+as this is the default output format that it uses.
 Output BSD style checksums, which indicate the checksum algorithm used.
 As a GNU extension, if @option{--zero} is not used, file names with problematic
 characters are escaped as described above, with the same escaping indicator of
index e841bbb8425085747db349b5314499629356d4ef..467cba88000198dbd40487235119f226d53e0eef 100644 (file)
@@ -355,6 +355,7 @@ enum
   QUIET_OPTION,
   STRICT_OPTION,
   TAG_OPTION,
+  UNTAG_OPTION,
   DEBUG_PROGRAM_OPTION,
 };
 
@@ -372,7 +373,11 @@ static struct option const long_options[] =
   { "text", no_argument, NULL, 't' },
   { "warn", no_argument, NULL, 'w' },
   { "strict", no_argument, NULL, STRICT_OPTION },
+# if HASH_ALGO_CKSUM
+  { "untagged", no_argument, NULL, UNTAG_OPTION },
+# else
   { "tag", no_argument, NULL, TAG_OPTION },
+# endif
   { "zero", no_argument, NULL, 'z' },
 #endif
 #if HASH_ALGO_CKSUM
@@ -444,9 +449,15 @@ Print or check %s (%d-bit) checksums.\n\
                        the blake2 algorithm and must be a multiple of 8\n\
 "), stdout);
 # endif
+# if HASH_ALGO_CKSUM
+      fputs (_("\
+      --untagged       create a reversed style checksum, without digest type\n\
+"), stdout);
+# else
       fputs (_("\
       --tag            create a BSD-style checksum\n\
 "), stdout);
+# endif
       if (O_BINARY)
         fputs (_("\
   -t, --text           read in text mode (default if reading tty stdin)\n\
@@ -1211,7 +1222,11 @@ main (int argc, char **argv)
   int opt;
   bool ok = true;
   int binary = -1;
+#if HASH_ALGO_CKSUM
+  bool prefix_tag = true;
+#else
   bool prefix_tag = false;
+#endif
 
   /* Setting values of global variables.  */
   initialize_main (&argc, &argv);
@@ -1295,10 +1310,16 @@ main (int argc, char **argv)
       case STRICT_OPTION:
         strict = true;
         break;
+# if HASH_ALGO_CKSUM
+      case UNTAG_OPTION:
+        prefix_tag = false;
+        break;
+# else
       case TAG_OPTION:
         prefix_tag = true;
         binary = 1;
         break;
+# endif
       case 'z':
         digest_delim = '\0';
         break;
@@ -1352,9 +1373,6 @@ main (int argc, char **argv)
     case bsd:
     case sysv:
     case crc:
-        if (prefix_tag)
-          die (EXIT_FAILURE, 0,
-              _("--tag is not supported with --algorithm={bsd,sysv,crc}"));
         if (do_check && algorithm_specified)
           die (EXIT_FAILURE, 0,
               _("--check is not supported with --algorithm={bsd,sysv,crc}"));
@@ -1382,13 +1400,21 @@ main (int argc, char **argv)
                      "verifying checksums"));
       usage (EXIT_FAILURE);
     }
-
+#if HASH_ALGO_CKSUM
+  if (!prefix_tag && do_check)
+    {
+      error (0, 0, _("the --untagged option is meaningless when "
+                     "verifying checksums"));
+      usage (EXIT_FAILURE);
+    }
+#else
   if (prefix_tag && do_check)
     {
       error (0, 0, _("the --tag option is meaningless when "
                      "verifying checksums"));
       usage (EXIT_FAILURE);
     }
+#endif
 
   if (0 <= binary && do_check)
     {
index c5242bed21782e037181146f91cb9b106b6e4021..99982ca8ce1f76ac43afd694d26aa0ffe8f7340a 100755 (executable)
@@ -25,10 +25,11 @@ for prog in 'b2sum' 'cksum -a blake2b'; do
 
 # Ensure we can --check the --tag format we produce
 rm -f check.b2sum || framework_failure_
+[ "$prog" = 'b2sum' ] && tag_opt='--tag' || tag_opt=''
 for i in 'a' ' b' '*c' '44' ' '; do
   echo "$i" > "$i"
   for l in 0 128; do
-    $prog -l $l --tag "$i" >> check.b2sum
+    $prog -l $l $tag_opt "$i" >> check.b2sum
   done
 done
 # Note -l is inferred from the tags in the mixed format file
@@ -39,15 +40,17 @@ $prog --strict -c openssl.b2sum || fail=1
 
 rm -f check.vals || framework_failure_
 # Ensure we can check non tagged format
+[ "$prog" != 'b2sum' ] && tag_opt='--untagged' || tag_opt=''
 for l in 0 128; do
-  $prog -l $l /dev/null | tee -a check.vals > check.b2sum
+  $prog $tag_opt -l $l /dev/null | tee -a check.vals > check.b2sum
   $prog -l $l --strict -c check.b2sum || fail=1
   $prog --strict -c check.b2sum || fail=1
 done
 
 # Ensure the checksum values are correct.  The reference
 # check.vals was created with the upstream SSE reference implementation.
-$prog --length=128 check.vals > out || fail=1
+[ "$prog" != 'b2sum' ] && tag_opt='--untagged' || tag_opt=''
+$prog $tag_opt --length=128 check.vals > out || fail=1
 printf '%s\n' '796485dd32fe9b754ea5fd6c721271d9  check.vals' > exp
 compare exp out || fail=1
 
index 8c4b32551b15e28dcc69b37d54146635f0f8501f..d6d50ccee447effe85a83a419b95d52b44b4e1bc 100755 (executable)
@@ -32,7 +32,7 @@ sha512  sha512sum -t
 blake2b b2sum -t
 " | while read algo prog; do
   $prog < /dev/null >> out || continue
-  cksum --algorithm=$algo < /dev/null >> out-a || fail=1
+  cksum --untagged --algorithm=$algo < /dev/null >> out-a || fail=1
 done
 compare out out-a || fail=1
 
index d8d26d81396ac1367610ba69f91db3013ff0a98a..ca275d7af89d5fc6a972aa8ff32a69bb9c1b0f35 100755 (executable)
@@ -22,7 +22,7 @@ print_ver_ cksum shuf
 shuf -i 1-10 > input || framework_failure_
 
 for args in '-a sha384' '-a blake2b' '-a blake2b -l 384' '-a sm3'; do
-  cksum $args --tag 'input' >> CHECKSUMS || fail=1
+  cksum $args 'input' >> CHECKSUMS || fail=1
 done
 cksum --strict --check CHECKSUMS || fail=1
 
index 667dac52e02e7546725113cb4d95d702f8ccde2f..91cce6505fb2cc32bc607c088f268e1282619c70 100755 (executable)
@@ -46,7 +46,7 @@ my $t;
 foreach $t (@Tests)
   {
     splice @$t, 1, 0, '--text' unless @$t[1] =~ /--check/;
-    splice @$t, 1, 0, '-a sm3'
+    splice @$t, 1, 0, '--untagged -a sm3'
   }
 
 my $save_temps = $ENV{DEBUG};