1- use bouncycastle_core:: traits:: { Hash , HashAlgParams } ;
1+ use bouncycastle_core:: traits:: { HashAlgParams , HashFixedOutput } ;
22
33pub struct TestFrameworkHash {
44 pub enable_partial_final_input_tests : bool ,
@@ -13,30 +13,31 @@ impl TestFrameworkHash {
1313 /// This gives good baseline test coverage, but is not exhaustive; for example it does not test
1414 /// do_final_partial_bits() or do_final_partial_bits_out()
1515 /// because those require different input-output pairs.
16- pub fn test_hash < H : Hash + HashAlgParams + Default > (
16+ pub fn test_hash < H : HashFixedOutput < N > + HashAlgParams + Default , const N : usize > (
1717 & self ,
1818 input : & [ u8 ] ,
1919 expected_output : & [ u8 ] ,
2020 ) {
2121 /*** fn result_len() -> usize ***/
2222 assert_eq ! ( H :: default ( ) . output_len( ) , H :: OUTPUT_LEN ) ;
23+ assert_eq ! ( N , H :: OUTPUT_LEN ) ;
2324
24- /*** fn hash(self, data: &[u8]) -> Vec<u8> **/
25- let output_vec = H :: default ( ) . hash ( input) ;
26- assert_eq ! ( output_vec , expected_output) ;
25+ /*** fn hash(self, data: &[u8]) -> [u8; N] **/
26+ let output_arr = H :: default ( ) . hash ( input) ;
27+ assert_eq ! ( & output_arr [ .. ] , expected_output) ;
2728
2829 /*** fn hash_out(self, data: &[u8], output: &mut [u8]) -> Result<usize, HashError> ***/
2930 let mut output_buf = vec ! [ 0_u8 ; H :: OUTPUT_LEN ] ;
3031 H :: default ( ) . hash_out ( input, & mut output_buf) ;
3132 assert_eq ! ( output_buf, expected_output) ;
3233
3334 /*** fn do_update(&mut self, data: &[u8]) -> Result<(), HashError> ***/
34- /*** fn do_final(self) -> Result<Vec<u8>, HashError> **/
35+ /*** fn do_final(self) -> [u8; N] **/
3536
3637 let mut message_digest = H :: default ( ) ;
3738 message_digest. do_update ( input) ;
3839 let output_buf = message_digest. do_final ( ) ;
39- assert_eq ! ( expected_output, output_buf, "Incorrect output for input (update_bytes)" ) ;
40+ assert_eq ! ( expected_output, & output_buf[ .. ] , "Incorrect output for input (update_bytes)" ) ;
4041
4142 for length in 1 ..output_buf. len ( ) {
4243 let mut truncated = vec ! [ 0_u8 ; length] ;
@@ -58,7 +59,7 @@ impl TestFrameworkHash {
5859 message_digest. do_update ( chunk) ;
5960 }
6061 let output_buf = message_digest. do_final ( ) ;
61- assert_eq ! ( expected_output, output_buf, "Incorrect output for input (update_bytes)" ) ;
62+ assert_eq ! ( expected_output, & output_buf[ .. ] , "Incorrect output for input (update_bytes)" ) ;
6263
6364 /*** fn do_update(&mut self, data: &[u8]) -> Result<(), HashError> ***/
6465 /*** fn do_final_out(self, output: &mut [u8]) -> Result<usize, HashError> ***/
0 commit comments