1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-21 03:12:48 +02:00

cksum: accept new option: --base64 (-b)

* src/digest.c [HASH_ALGO_CKSUM]: Include "base64.h"
[HASH_ALGO_CKSUM] (base64_digest): New global.
[HASH_ALGO_CKSUM] (enum BASE64_DIGEST_OPTION): New enum.
[HASH_ALGO_CKSUM] (long_options): Add "base64".
(valid_digits): Rename from hex_digits, now taking an input length argument.
Adjust callers.
(bsd_split_3): Rename arg from hex_digits to digest.
Add new *d_len parameter for length of extracted digest.
Move "i" declaration down to first use.
(split_3): Rename arg from hex_digits to digest.
Add new *d_len parameter for length of extracted digest.
Instead of relying on "known" length of digest to find the following
must-be-whitespace byte, search for the first whitespace byte.
[HASH_ALGO_CKSUM] (output_file): Handle base64_digest.
[HASH_ALGO_CKSUM] (main): Set base64_digest.
[HASH_ALGO_CKSUM] (b64_equal): New function.
(hex_equal): New function, factored out of digest_check.
(digest_check) Factored part into b64_equal and hex_equal.
Rename local hex_digest to digest.
* tests/misc/cksum-base64.pl: Add tests.
* tests/local.mk (all_tests): Add to the list.
* cfg.mk (_cksum): Define.
(exclude_file_name_regexp--sc_prohibit_test_backticks): Exempt new test.
(exclude_file_name_regexp--sc_long_lines): Likewise.
* doc/coreutils.texi (cksum invocation): Document it.
(md5sum invocation) [--check]: Mention digest encoding auto-detect.
* NEWS (New Features): Mention this.
This commit is contained in:
Jim Meyering
2023-01-20 18:09:26 -08:00
committed by Jim Meyering
parent 7a8db7dbaf
commit b319685c6e
6 changed files with 261 additions and 53 deletions

View File

@@ -4039,6 +4039,22 @@ Supported more modern digest algorithms are:
@samp{sm3} only available through @command{cksum}
@end example
@item -b
@itemx --base64
@opindex -b
@opindex --base64
@cindex base64 checksum encoding
Print base64-encoded digests not hexadecimal.
This option is ignored with @option{--check}.
The format conforms to
@uref{https://tools.ietf.org/search/rfc4648#section-4, RFC 4648#4}.
Note that each base64-encoded digest has zero, one or two trailing padding
(@samp{=}) bytes. The length of that padding is the checksum-bit-length
modulo 3, and the @option{--check} parser requires precisely the same
input digest string as what is output. I.e., removing or adding any
@samp{=} padding renders a digest non-matching.
@item --debug
@opindex --debug
Output extra information to stderr, like the checksum implementation being used.
@@ -4168,6 +4184,11 @@ For the @command{cksum} command, the @option{--check} option
supports auto-detecting the digest algorithm to use,
when presented with checksum information in the @option{--tag} output format.
Also for the @command{cksum} command, the @option{--check} option
auto-detects the digest encoding, accepting both standard hexidecimal
checksums and those generated via @command{cksum} with its
@option{--base64} option.
Output with @option{--zero} enabled is not supported by @option{--check}.
@sp 1
For each such line, @command{md5sum} reads the named file and computes its