1#!/bin/sh
2# Validate cksum --raw operation
3
4# Copyright (C) 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 date od
21
22cat > digest_types <<\EOF || framework_failure_
23bsd     u2
24sysv    u2
25crc     u4
26md5     x1
27sha1    x1
28sha224  x1
29sha256  x1
30sha384  x1
31sha512  x1
32blake2b x1
33sm3     x1
34EOF
35
36date > file.in || framework_failure_
37
38while read algo type; do
39  # Binary converted back to text
40  cksum --raw --algorithm $algo file.in > digest.bin || fail=1
41  d='digest.bin.txt'
42  od --endian=big -An -w1024 -t$type < digest.bin | tr -d ' ' \
43    > "$d" || framework_failure_
44  # Pad the bsd checksum with leading 0's, if needed.
45  case $algo in bsd) n=$(cat "$d"); printf '%05d\n' "$n" > "$d" ;; esac
46
47  # Standard text output
48  cksum --untagged --algorithm $algo < file.in | cut -d ' ' -f1 \
49    > digest.txt || fail=1
50
51  compare digest.txt "$d" || fail=1
52done < digest_types
53
54# Ensure --base64 and --raw not used together
55returns_ 1 cksum --base64 --raw </dev/null || fail=1
56
57# Ensure --raw not supported with multiple files
58returns_ 1 cksum --raw /dev/null /dev/null || fail=1
59
60Exit $fail
61