aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorCollin Funk <collin.funk1@gmail.com>2025-10-04 17:18:01 -0700
committerCollin Funk <collin.funk1@gmail.com>2025-10-05 15:38:27 -0700
commitce8c22d25f827edc853a8bc96d506577f0b0badc (patch)
tree274b821595f2a0f9f8013c3cf833b8439ccf175a /tests
parentmaint: omit trailing white space in config.h (diff)
downloadcoreutils-ce8c22d25f827edc853a8bc96d506577f0b0badc.tar.gz
coreutils-ce8c22d25f827edc853a8bc96d506577f0b0badc.zip
cksum: allow -a {blake2b,sha2,sha3} --check to work on base64
* NEWS: Mention the bug. * src/digest.c (split_3): Check that the base64 digest matches the length supported by the algorithm. (digest_check): Check that the read digest matches the base64 length of the algorithm's digest. The previous condition would not work for 'cksum -a blake2b -l 8 ...'. * tests/cksum/cksum-base64-untagged.sh: New file. * tests/local.mk (all_tests): Add the new test.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/cksum/cksum-base64-untagged.sh50
-rw-r--r--tests/local.mk1
2 files changed, 51 insertions, 0 deletions
diff --git a/tests/cksum/cksum-base64-untagged.sh b/tests/cksum/cksum-base64-untagged.sh
new file mode 100755
index 000000000..14e194289
--- /dev/null
+++ b/tests/cksum/cksum-base64-untagged.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+# Test that cksum can guess the digest length from base64 checksums.
+
+# Copyright (C) 2025 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ cksum
+
+echo 'test input' > inp
+echo 'inp: OK' > expout
+echo 'cksum: truncated: no properly formatted checksum lines found' > experr
+
+for algorithm in sha2 sha3; do
+ for length in 224 256 384 512; do
+ # Create files with base64 checksums in the untagged format.
+ cksum -a $algorithm --length $length --base64 --untagged inp \
+ > check || fail=1
+ # Check that the length can be determined from the base64 checksum.
+ cksum -a $algorithm --check check > out || fail=1
+ compare expout out || fail=1
+ # Check that only valid lengths are supported.
+ sed 's|[a-zA-Z0-9+/=] inp$| inp|g' check > truncated || fail=1
+ returns_ 1 cksum -a $algorithm --check truncated 2> err || fail=1
+ compare experr err || fail=1
+ done
+done
+
+for length in 8 216 224 232 248 256 264 376 384 392 504 512; do
+ # Create files with base64 checksums in the untagged format.
+ cksum -a blake2b --length $length --base64 --untagged inp \
+ > check || fail=1
+ # Check that the length can be determined from the base64 checksum.
+ cksum -a blake2b --check check > out || fail=1
+ compare expout out || fail=1
+done
+
+Exit $fail
diff --git a/tests/local.mk b/tests/local.mk
index 19bc194fb..52184b7ac 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -305,6 +305,7 @@ all_tests = \
tests/cksum/cksum-a.sh \
tests/cksum/cksum-c.sh \
tests/cksum/cksum-base64.pl \
+ tests/cksum/cksum-base64-untagged.sh \
tests/cksum/cksum-raw.sh \
tests/misc/comm.pl \
tests/csplit/csplit.sh \