On 02/09/2025 00:18, Collin Funk wrote:
Pádraig Brady <[email protected]> writes:

Well we'd still allow `cksum -a sha256` but only document `cksum -a sha2 -l 
256`.
Anyway I'll think more about it.

Ah, okay that makes sense and seems reasonable.

Anyways, here is a revised patch.

Looks great.
I've only textual tweaks (attached).

thanks!
Padraig
From 101e79918078ff683e2b8a8fcc5f1f6de3660e86 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Tue, 2 Sep 2025 13:14:04 +0100
Subject: [PATCH] cksum: tweaks

... to squash in
---
 doc/coreutils.texi        |  6 +++---
 src/digest.c              | 10 +++++-----
 tests/cksum/cksum-sha3.sh |  1 -
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index f313c56cc..561832855 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -4181,10 +4181,10 @@ like the checksum implementation being used.
 @opindex --length
 @cindex BLAKE2 hash length
 @cindex SHA-3 hash length
-Specify the digest size used by the algorithm.  For @samp{blake2b} this
-option is optional.  By default a 512 bit digest will be used.  If the
+Specify the digest size used with @option{-a sha3} or @option{-a blake2b}.
+For @samp{blake2b} this is optional, with 512 being the default.  If the
 option is given it must be a multiple of 8.  For @samp{sha3} this option
-is required.  The value must be 224, 256, 384, or 512.
+is required, and the @var{length} must be one of 224, 256, 384, or 512.
 
 This option is ignored when @option{--check} is specified,
 as the length is automatically determined when checking.
diff --git a/src/digest.c b/src/digest.c
index 3592ee9fd..5acf54997 100644
--- a/src/digest.c
+++ b/src/digest.c
@@ -506,9 +506,9 @@ Print or check %s (%d-bit) checksums.\n\
 "), stdout);
 # if HASH_ALGO_BLAKE2 || HASH_ALGO_CKSUM
         fputs (_("\
-  -l, --length=BITS     digest length in bits; must not exceed the max\n\
-                          size and must be a multiple of 8 for blake2b; must\n\
-                          be 224, 256, 384, or 512 for sha3\n\
+  -l, --length=BITS     digest length in bits; must not exceed the max size\n\
+                          and must be a multiple of 8 for blake2b;\n\
+                          must be 224, 256, 384, or 512 for sha3\n\
 "), stdout);
 # endif
 # if HASH_ALGO_CKSUM
@@ -1535,8 +1535,8 @@ main (int argc, char **argv)
     {
       /* Do not require --length with --check.  */
       if (digest_length == 0 && *digest_length_str == '\0' && ! do_check)
-        error (EXIT_FAILURE, 0, _("--algorithm=sha3 requires use of the "
-                                  "--length option"));
+        error (EXIT_FAILURE, 0, _("--algorithm=sha3 requires specifying "
+                                  "--length 224, 256, 384, or 512"));
       /* If --check and --length are used we verify the digest length.  */
       if ((! do_check || *digest_length_str != '\0')
           && digest_length != SHA3_224_DIGEST_SIZE * 8
diff --git a/tests/cksum/cksum-sha3.sh b/tests/cksum/cksum-sha3.sh
index 5f2383fef..4c414f937 100755
--- a/tests/cksum/cksum-sha3.sh
+++ b/tests/cksum/cksum-sha3.sh
@@ -61,7 +61,6 @@ cksum: inp: no properly formatted checksum lines found
 EOF
 compare exp err || fail=1
 
-# This would fail before coreutil-9.4
 # Only validate the last specified, used length
 cksum -a sha3 -l 253 -l 256 /dev/null || fail=1
 
-- 
2.50.1

Reply via email to