mirror of
https://github.com/coreutils/coreutils.git
synced 2024-11-27 03:44:26 +08:00
cksum: use --tag format by default
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.
This commit is contained in:
parent
d9b78a2329
commit
f9a787656b
@ -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
|
||||
|
34
src/digest.c
34
src/digest.c
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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};
|
||||
|
Loading…
Reference in New Issue
Block a user