Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dee3483

Browse files
committed
cksum: Add SHA3/SHAKE support with comprehensive test coverage
This commit consolidates all changes for SHA3/SHAKE algorithm support: Features: - Add SHA3 and SHAKE algorithm support to cksum - Support --length parameter for SHA3 (224, 256, 384, 512 bits) - Support --length parameter for SHAKE (any length) - Add base64 output support for SHA3/SHAKE - Add --debug flag (no-op matching GNU behavior) Tests: - Add comprehensive test coverage for SHA3/SHAKE with various lengths - Add tests for base64 output format - Add tests for error cases (invalid lengths, missing length parameter) - Remove redundant test coverage Localization: - Update English and French locale files with SHA3/SHAKE descriptions Fixes PR #8948 code review feedback from @cakebaker, @sylvestre, and @evilpie. All 134 tests pass with no regressions.
1 parent 95b266f commit dee3483

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cksum-after-help = DIGEST determines the digest algorithm and default output for
99
- md5: (equivalent to md5sum)
1010
- sha1: (equivalent to sha1sum)
1111
- sha2: (equivalent to sha{"{224,256,384,512}"}sum)
12-
- sha3: (only available through cksum)
12+
- sha3: (requires --length: 224, 256, 384, or 512)
1313
- blake2b: (equivalent to b2sum)
1414
- sm3: (only available through cksum)
1515

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cksum-after-help = DIGEST détermine l'algorithme de condensé et le format de s
99
- md5 : (équivalent à md5sum)
1010
- sha1 : (équivalent à sha1sum)
1111
- sha2: (équivalent à sha{"{224,256,384,512}"}sum)
12-
- sha3 : (disponible uniquement via cksum)
12+
- sha3 : (nécessite --length : 224, 256, 384, ou 512)
1313
- blake2b : (équivalent à b2sum)
1414
- sm3 : (disponible uniquement via cksum)
1515

tests/by-util/test_cksum.rs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,6 +2668,97 @@ mod gnu_cksum_c {
26682668
}
26692669
}
26702670

2671+
#[test]
2672+
fn test_sha3_with_length() {
2673+
// Test SHA3-224
2674+
new_ucmd!()
2675+
.arg("-a")
2676+
.arg("sha3")
2677+
.arg("--length")
2678+
.arg("224")
2679+
.arg("lorem_ipsum.txt")
2680+
.succeeds()
2681+
.stdout_contains("SHA3-224 (lorem_ipsum.txt) = ");
2682+
2683+
// Test SHA3-256
2684+
new_ucmd!()
2685+
.arg("-a")
2686+
.arg("sha3")
2687+
.arg("--length")
2688+
.arg("256")
2689+
.arg("lorem_ipsum.txt")
2690+
.succeeds()
2691+
.stdout_contains("SHA3-256 (lorem_ipsum.txt) = ");
2692+
2693+
// Test SHA3-384
2694+
new_ucmd!()
2695+
.arg("-a")
2696+
.arg("sha3")
2697+
.arg("--length")
2698+
.arg("384")
2699+
.arg("lorem_ipsum.txt")
2700+
.succeeds()
2701+
.stdout_contains("SHA3-384 (lorem_ipsum.txt) = ");
2702+
2703+
// Test SHA3-512
2704+
new_ucmd!()
2705+
.arg("-a")
2706+
.arg("sha3")
2707+
.arg("--length")
2708+
.arg("512")
2709+
.arg("lorem_ipsum.txt")
2710+
.succeeds()
2711+
.stdout_contains("SHA3-512 (lorem_ipsum.txt) = ");
2712+
}
2713+
2714+
#[test]
2715+
fn test_sha3_invalid_length() {
2716+
// Test SHA3 with invalid length (not 224, 256, 384, or 512)
2717+
new_ucmd!()
2718+
.arg("-a")
2719+
.arg("sha3")
2720+
.arg("--length")
2721+
.arg("128")
2722+
.arg("lorem_ipsum.txt")
2723+
.fails()
2724+
.stderr_contains("digest length for 'SHA3' must be 224, 256, 384, or 512");
2725+
2726+
// Test SHA3 without length
2727+
new_ucmd!()
2728+
.arg("-a")
2729+
.arg("sha3")
2730+
.arg("lorem_ipsum.txt")
2731+
.fails()
2732+
.stderr_contains("--algorithm=sha3 requires specifying --length 224, 256, 384, or 512");
2733+
}
2734+
2735+
#[test]
2736+
fn test_sha3_base64_output() {
2737+
// Test SHA3 with base64 output format
2738+
new_ucmd!()
2739+
.arg("--base64")
2740+
.arg("-a")
2741+
.arg("sha3")
2742+
.arg("--length")
2743+
.arg("256")
2744+
.arg("lorem_ipsum.txt")
2745+
.succeeds()
2746+
.stdout_contains("SHA3-256 (lorem_ipsum.txt) = ");
2747+
}
2748+
2749+
#[test]
2750+
fn test_sha3_untagged() {
2751+
// Test SHA3 with untagged output
2752+
new_ucmd!()
2753+
.arg("--untagged")
2754+
.arg("-a")
2755+
.arg("sha3")
2756+
.arg("--length")
2757+
.arg("256")
2758+
.arg("lorem_ipsum.txt")
2759+
.succeeds();
2760+
}
2761+
26712762
/// The tests in this module check the behavior of cksum when given different
26722763
/// checksum formats and algorithms in the same file, while specifying an
26732764
/// algorithm on CLI or not.

0 commit comments

Comments
 (0)