[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/4] cksum: use --tag format by default
From: |
Pádraig Brady |
Subject: |
[PATCH 1/4] cksum: use --tag format by default |
Date: |
Wed, 15 Sep 2021 13:40:33 +0100 |
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.
---
doc/coreutils.texi | 12 ++++++++++++
src/digest.c | 34 ++++++++++++++++++++++++++++++----
tests/misc/b2sum.sh | 9 ++++++---
tests/misc/cksum-a.sh | 2 +-
tests/misc/cksum-c.sh | 2 +-
tests/misc/sm3sum.pl | 2 +-
6 files changed, 51 insertions(+), 10 deletions(-)
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 2acfd43a6..c324dc3ca 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -3984,6 +3984,16 @@ Supported 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
@@ -4143,6 +4153,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
diff --git a/src/digest.c b/src/digest.c
index 188a27488..71ccc47df 100644
--- a/src/digest.c
+++ b/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
@@ -443,9 +448,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\
@@ -1210,7 +1221,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);
@@ -1294,10 +1309,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;
@@ -1351,9 +1372,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}"));
@@ -1381,13 +1399,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)
{
diff --git a/tests/misc/b2sum.sh b/tests/misc/b2sum.sh
index c5242bed2..99982ca8c 100755
--- a/tests/misc/b2sum.sh
+++ b/tests/misc/b2sum.sh
@@ -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
diff --git a/tests/misc/cksum-a.sh b/tests/misc/cksum-a.sh
index 15fc94b7d..aca77bfd0 100755
--- a/tests/misc/cksum-a.sh
+++ b/tests/misc/cksum-a.sh
@@ -32,7 +32,7 @@ sha512 sha512sum
blake2b b2sum
" | 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
diff --git a/tests/misc/cksum-c.sh b/tests/misc/cksum-c.sh
index d8d26d813..ca275d7af 100755
--- a/tests/misc/cksum-c.sh
+++ b/tests/misc/cksum-c.sh
@@ -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
diff --git a/tests/misc/sm3sum.pl b/tests/misc/sm3sum.pl
index 667dac52e..91cce6505 100755
--- a/tests/misc/sm3sum.pl
+++ b/tests/misc/sm3sum.pl
@@ -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};
--
2.26.2
- Re: [PATCH 07/12] cksum: add --algorithm option to select digest mode, (continued)
- [PATCH 12/12] cksum: support --zero in default mode, Pádraig Brady, 2021/09/12
- [PATCH 10/12] cksum: support digest detection for tagged format, Pádraig Brady, 2021/09/12
- [PATCH 11/12] digest: support -length specifiers on all digest tags, Pádraig Brady, 2021/09/12
- Re: [PATCH V2] Add support for cksum --algorithm [sm3], Pádraig Brady, 2021/09/12
- Re: [PATCH V2] Add support for cksum --algorithm [sm3], Pádraig Brady, 2021/09/14
- Re: [PATCH V2] Add support for cksum --algorithm [sm3], Jim Meyering, 2021/09/14
- [PATCH 3/4] doc: improve --help indenting in checksum utils, Pádraig Brady, 2021/09/15
- [PATCH 1/4] cksum: use --tag format by default,
Pádraig Brady <=
- Re: [PATCH 1/4] cksum: use --tag format by default, Eric Blake, 2021/09/17
- Re: [PATCH 1/4] cksum: use --tag format by default, Pádraig Brady, 2021/09/17
- Re: [PATCH 1/4] cksum: use --tag format by default, Pádraig Brady, 2021/09/20
- [PATCH 4/4] digest: support windows format checksum files, Pádraig Brady, 2021/09/15
- Re: [PATCH 4/4] digest: support windows format checksum files, Eric Blake, 2021/09/17
- [PATCH 2/4] cksum: operate in binary mode only, Pádraig Brady, 2021/09/15
- Re: [PATCH V2] Add support for cksum --algorithm [sm3], Eric Blake, 2021/09/17