1#!/bin/sh
2# Validate cksum --check dynamic operation
3
4# Copyright (C) 2021-2023 Free Software Foundation, Inc.
5
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15
16# You should have received a copy of the GNU General Public License
17# along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20print_ver_ cksum shuf
21
22shuf -i 1-10 > input || framework_failure_
23
24for args in '-a sha384' '-a blake2b' '-a blake2b -l 384' '-a sm3'; do
25  cksum $args 'input' >> CHECKSUMS || fail=1
26done
27cksum --strict --check CHECKSUMS || fail=1
28
29# Ensure leading whitespace and \ ignored
30sed 's/^/ \\/' CHECKSUMS | cksum --strict -c || fail=1
31
32# Check common signed checksums format works in non strict mode
33cat >> signed_CHECKSUMS <<\EOF
34-----BEGIN PGP SIGNED MESSAGE-----
35Hash: SHA384
36
37# ignored comment
38EOF
39cat CHECKSUMS >> signed_CHECKSUMS
40cat >> signed_CHECKSUMS <<\EOF
41-----BEGIN PGP SIGNATURE-----
42
43# Note base64 doesn't have ambiguous delimiters in its charset
44SHA384+BCAAdFiEEjFummQvbJuGfKhqAEWGuaUVxmjkFAmCDId0ACgkQEWGuaUVx
45BLAKE2b/00001EuON62pTEnqrJ5lav61QxRByiuDp/6VODrRL2JWM6Stxu1Myws=
46=AWU7
47-----END PGP SIGNATURE-----
48EOF
49cksum --check signed_CHECKSUMS || fail=1
50
51# Can check individual digests in a mixed file
52cksum --check -a sm3 CHECKSUMS || fail=1
53
54# Checks against older (non hex) checksum formats not supported
55returns_ 1 cksum -a crc -c CHECKSUMS || fail=1
56cksum -a crc 'input' > CHECKSUMS.crc || fail=1
57returns_ 1 cksum -c CHECKSUMS.crc || fail=1
58
59Exit $fail
60