Skip to content

Commit 73260a4

Browse files
author
oech3
committed
cksum: Back support for -a blake3 and -a shake*
1 parent 81ee8d1 commit 73260a4

File tree

6 files changed

+13
-24
lines changed

6 files changed

+13
-24
lines changed

src/uu/cksum/src/cksum.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,14 @@ fn maybe_sanitize_length(
8888
sanitize_sha2_sha3_length_str(algo, s_len).map(Some)
8989
}
9090

91-
// For BLAKE2b, if a length is provided, validate it.
91+
// For BLAKE2b and SKAKE, if a length is provided, validate it.
9292
(Some(AlgoKind::Blake2b), Some(len)) => calculate_blake2b_length_str(len),
93-
93+
(Some(AlgoKind::Shake128 | AlgoKind::Shake256), Some(s_len)) => {
94+
let len = s_len
95+
.parse::<usize>()
96+
.map_err(|_| ChecksumError::InvalidLength(s_len.to_string()))?;
97+
Ok(Some(len))
98+
}
9499
// For any other provided algorithm, check if length is 0.
95100
// Otherwise, this is an error.
96101
(_, Some(len)) if len.parse::<u32>() == Ok(0_u32) => Ok(None),

src/uu/hashsum/locales/en-US.ftl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ hashsum-help-sha3-224 = work with SHA3-224
3030
hashsum-help-sha3-256 = work with SHA3-256
3131
hashsum-help-sha3-384 = work with SHA3-384
3232
hashsum-help-sha3-512 = work with SHA3-512
33-
hashsum-help-shake128 = work with SHAKE128 using BITS for the output size
34-
hashsum-help-shake256 = work with SHAKE256 using BITS for the output size
3533
hashsum-help-b2sum = work with BLAKE2
36-
hashsum-help-b3sum = work with BLAKE3
3734
3835
# Error messages
3936
hashsum-error-failed-to-read-input = failed to read input

src/uu/hashsum/locales/fr-FR.ftl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ hashsum-help-sha3-224 = travailler avec SHA3-224
2828
hashsum-help-sha3-256 = travailler avec SHA3-256
2929
hashsum-help-sha3-384 = travailler avec SHA3-384
3030
hashsum-help-sha3-512 = travailler avec SHA3-512
31-
hashsum-help-shake128 = travailler avec SHAKE128 en utilisant BITS pour la taille de sortie
32-
hashsum-help-shake256 = travailler avec SHAKE256 en utilisant BITS pour la taille de sortie
3331
hashsum-help-b2sum = travailler avec BLAKE2
34-
hashsum-help-b3sum = travailler avec BLAKE3
3532
3633
# Messages d'erreur
3734
hashsum-error-failed-to-read-input = échec de la lecture de l'entrée

src/uu/hashsum/src/hashsum.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ fn create_algorithm_from_flags(matches: &ArgMatches) -> UResult<(AlgoKind, Optio
7272
if matches.get_flag("b2sum") {
7373
set_or_err((AlgoKind::Blake2b, None))?;
7474
}
75-
if matches.get_flag("b3sum") {
76-
set_or_err((AlgoKind::Blake3, None))?;
77-
}
7875
if matches.get_flag("sha3") {
7976
match matches.get_one::<String>(options::LENGTH) {
8077
Some(len) => set_or_err((
@@ -96,12 +93,6 @@ fn create_algorithm_from_flags(matches: &ArgMatches) -> UResult<(AlgoKind, Optio
9693
if matches.get_flag("sha3-512") {
9794
set_or_err((AlgoKind::Sha3, Some(512)))?;
9895
}
99-
if matches.get_flag("shake128") {
100-
set_or_err((AlgoKind::Shake128, Some(128)))?;
101-
}
102-
if matches.get_flag("shake256") {
103-
set_or_err((AlgoKind::Shake256, Some(256)))?;
104-
}
10596

10697
if alg.is_none() {
10798
return Err(ChecksumError::NeedAlgorithmToHash.into());
@@ -374,10 +365,7 @@ pub fn uu_app_custom() -> Command {
374365
("sha3-256", translate!("hashsum-help-sha3-256")),
375366
("sha3-384", translate!("hashsum-help-sha3-384")),
376367
("sha3-512", translate!("hashsum-help-sha3-512")),
377-
("shake128", translate!("hashsum-help-shake128")),
378-
("shake256", translate!("hashsum-help-shake256")),
379368
("b2sum", translate!("hashsum-help-b2sum")),
380-
("b3sum", translate!("hashsum-help-b3sum")),
381369
];
382370

383371
for (name, desc) in algorithms {

src/uucore/src/lib/features/checksum/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub enum AlgoKind {
8686
Sha384,
8787
Sha512,
8888

89-
// Not available in cksum
89+
// Extension
9090
Shake128,
9191
Shake256,
9292
Blake3,
@@ -114,6 +114,11 @@ impl AlgoKind {
114114
ALGORITHM_OPTIONS_SHA256 => Sha256,
115115
ALGORITHM_OPTIONS_SHA384 => Sha384,
116116
ALGORITHM_OPTIONS_SHA512 => Sha512,
117+
118+
// Extension
119+
ALGORITHM_OPTIONS_BLAKE3 => Blake3,
120+
ALGORITHM_OPTIONS_SHAKE128 => Shake128,
121+
ALGORITHM_OPTIONS_SHAKE256 => Shake256,
117122
_ => return Err(ChecksumError::UnknownAlgorithm(algo.as_ref().to_string()).into()),
118123
})
119124
}

tests/by-util/test_hashsum.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,6 @@ macro_rules! test_digest_with_len {
203203

204204
test_digest! {md5, md5}
205205
test_digest! {sha1, sha1}
206-
test_digest! {b3sum, b3sum}
207-
test_digest! {shake128, shake128}
208-
test_digest! {shake256, shake256}
209206

210207
test_digest_with_len! {sha224, sha224, 224}
211208
test_digest_with_len! {sha256, sha256, 256}

0 commit comments

Comments
 (0)