@@ -312,7 +312,8 @@ fn test_untagged_algorithm_stdin(#[case] algo: &str) {
312312#[ test]
313313fn test_sha_length_invalid ( ) {
314314 for algo in [ "sha2" , "sha3" ] {
315- for l in [ "0" , "00" , "13" , "56" , "99999999999999999999999999" ] {
315+ // 0 and 00 are treated as "no length provided" — same error as missing length
316+ for l in [ "0" , "00" ] {
316317 new_ucmd ! ( )
317318 . arg ( "--algorithm" )
318319 . arg ( algo)
@@ -321,52 +322,54 @@ fn test_sha_length_invalid() {
321322 . arg ( "/dev/null" )
322323 . fails_with_code ( 1 )
323324 . no_stdout ( )
324- . stderr_contains ( format ! ( "invalid length: '{l}'" ) )
325325 . stderr_contains ( format ! (
326- "digest length for '{}' must be 224, 256, 384, or 512" ,
327- algo. to_ascii_uppercase( )
326+ "--algorithm={algo} requires specifying --length 224, 256, 384, or 512"
328327 ) ) ;
328+ }
329329
330- // Also fails with --check
330+ // Non-zero invalid lengths
331+ for l in [ "13" , "56" ] {
331332 new_ucmd ! ( )
332333 . arg ( "--algorithm" )
333334 . arg ( algo)
334335 . arg ( "--length" )
335336 . arg ( l)
336337 . arg ( "/dev/null" )
337- . arg ( "--check" )
338338 . fails_with_code ( 1 )
339339 . no_stdout ( )
340340 . stderr_contains ( format ! ( "invalid length: '{l}'" ) )
341341 . stderr_contains ( format ! (
342342 "digest length for '{}' must be 224, 256, 384, or 512" ,
343343 algo. to_ascii_uppercase( )
344344 ) ) ;
345- }
346345
347- // Different error for NaNs
348- for l in [ "512x" , "x512" , "512x512" ] {
346+ // Also fails with --check
349347 new_ucmd ! ( )
350348 . arg ( "--algorithm" )
351349 . arg ( algo)
352350 . arg ( "--length" )
353351 . arg ( l)
354352 . arg ( "/dev/null" )
353+ . arg ( "--check" )
355354 . fails_with_code ( 1 )
356355 . no_stdout ( )
357- . stderr_contains ( format ! ( "invalid length: '{l}'" ) ) ;
356+ . stderr_contains ( format ! ( "invalid length: '{l}'" ) )
357+ . stderr_contains ( format ! (
358+ "digest length for '{}' must be 224, 256, 384, or 512" ,
359+ algo. to_ascii_uppercase( )
360+ ) ) ;
361+ }
358362
359- // Also fails with --check
363+ // NaNs and overflow are rejected by clap's usize parser
364+ for l in [ "99999999999999999999999999" , "512x" , "x512" , "512x512" ] {
360365 new_ucmd ! ( )
361366 . arg ( "--algorithm" )
362367 . arg ( algo)
363368 . arg ( "--length" )
364369 . arg ( l)
365370 . arg ( "/dev/null" )
366- . arg ( "--check" )
367371 . fails_with_code ( 1 )
368- . no_stdout ( )
369- . stderr_contains ( format ! ( "invalid length: '{l}'" ) ) ;
372+ . no_stdout ( ) ;
370373 }
371374 }
372375}
@@ -766,7 +769,7 @@ fn test_blake2b_length() {
766769
767770#[ test]
768771fn test_blake2b_length_greater_than_512 ( ) {
769- for l in [ "513" , "1024" , "73786976294838206464" ] {
772+ for l in [ "513" , "1024" ] {
770773 new_ucmd ! ( )
771774 . arg ( "--algorithm=blake2b" )
772775 . arg ( "--length" )
@@ -777,19 +780,28 @@ fn test_blake2b_length_greater_than_512() {
777780 . stderr_contains ( format ! ( "invalid length: '{l}'" ) )
778781 . stderr_contains ( "maximum digest length for 'BLAKE2b' is 512 bits" ) ;
779782 }
783+
784+ // Overflow is rejected by clap's usize parser
785+ new_ucmd ! ( )
786+ . arg ( "--algorithm=blake2b" )
787+ . arg ( "--length" )
788+ . arg ( "73786976294838206464" )
789+ . arg ( "lorem_ipsum.txt" )
790+ . fails_with_code ( 1 )
791+ . no_stdout ( ) ;
780792}
781793
782794#[ test]
783795fn test_blake2b_length_nan ( ) {
796+ // Non-numeric values are rejected by clap's usize parser
784797 for l in [ "foo" , "512x" , "x512" , "0xff" ] {
785798 new_ucmd ! ( )
786799 . arg ( "--algorithm=blake2b" )
787800 . arg ( "--length" )
788801 . arg ( l)
789802 . arg ( "lorem_ipsum.txt" )
790803 . fails_with_code ( 1 )
791- . no_stdout ( )
792- . stderr_contains ( format ! ( "invalid length: '{l}'" ) ) ;
804+ . no_stdout ( ) ;
793805 }
794806}
795807
@@ -821,19 +833,26 @@ fn test_blake2b_length_repeated() {
821833
822834#[ test]
823835fn test_blake2b_length_invalid ( ) {
824- for len in [
825- "1" , "01" , // Odd
826- "" ,
827- ] {
836+ // Non-multiple-of-8 values: "01" parses as 1, so error shows '1'
837+ for len in [ "1" , "01" ] {
828838 new_ucmd ! ( )
829839 . arg ( "--length" )
830840 . arg ( len)
831841 . arg ( "--algorithm=blake2b" )
832842 . arg ( "lorem_ipsum.txt" )
833843 . arg ( "alice_in_wonderland.txt" )
834844 . fails_with_code ( 1 )
835- . stderr_contains ( format ! ( "invalid length: '{len}'" ) ) ;
845+ . stderr_contains ( "invalid length: '1'" ) ;
836846 }
847+
848+ // Empty string is rejected by clap's usize parser
849+ new_ucmd ! ( )
850+ . arg ( "--length" )
851+ . arg ( "" )
852+ . arg ( "--algorithm=blake2b" )
853+ . arg ( "lorem_ipsum.txt" )
854+ . fails_with_code ( 1 )
855+ . no_stdout ( ) ;
837856}
838857
839858#[ apply( test_all_algos) ]
0 commit comments