@@ -18,8 +18,6 @@ pub struct TestVector {
1818 pub plaintext : & ' static [ u8 ] ,
1919 /// Ciphertext
2020 pub ciphertext : & ' static [ u8 ] ,
21- /// Whether the test vector should pass (`[1]`) or fail (`[0]`)
22- pub pass : & ' static [ u8 ] ,
2321}
2422
2523/// Run AEAD test for the provided passing test vector
@@ -30,10 +28,8 @@ pub fn pass_test<C: AeadInOut + KeyInit>(
3028 aad,
3129 plaintext,
3230 ciphertext,
33- pass,
3431 } : & TestVector ,
3532) -> Result < ( ) , & ' static str > {
36- assert_eq ! ( pass, & [ 1 ] ) ;
3733 let nonce = nonce. try_into ( ) . expect ( "wrong nonce size" ) ;
3834 let cipher = <C as KeyInit >:: new_from_slice ( key) . expect ( "failed to initialize the cipher" ) ;
3935
@@ -109,11 +105,9 @@ pub fn fail_test<C: AeadInOut + KeyInit>(
109105 nonce,
110106 aad,
111107 ciphertext,
112- pass,
113108 ..
114109 } : & TestVector ,
115110) -> Result < ( ) , & ' static str > {
116- assert_eq ! ( pass, & [ 0 ] ) ;
117111 let nonce = nonce. try_into ( ) . expect ( "wrong nonce size" ) ;
118112 let cipher = <C as KeyInit >:: new_from_slice ( key) . expect ( "failed to initialize the cipher" ) ;
119113
@@ -131,9 +125,9 @@ pub fn fail_test<C: AeadInOut + KeyInit>(
131125 }
132126}
133127
134- /// Define AEAD test
128+ /// Define AEAD test for passing test vectors
135129#[ macro_export]
136- macro_rules! new_test {
130+ macro_rules! new_pass_test {
137131 ( $name: ident, $test_name: expr, $cipher: ty $( , ) ?) => {
138132 #[ test]
139133 fn $name( ) {
@@ -142,17 +136,43 @@ macro_rules! new_test {
142136 $crate:: dev:: blobby:: parse_into_structs!(
143137 include_bytes!( concat!( "data/" , $test_name, ".blb" ) ) ;
144138 static TEST_VECTORS : & [
145- TestVector { key, nonce, aad, plaintext, ciphertext, pass }
139+ TestVector { key, nonce, aad, plaintext, ciphertext }
146140 ] ;
147141 ) ;
148142
149143 for ( i, tv) in TEST_VECTORS . iter( ) . enumerate( ) {
150- let pass = tv. pass[ 0 ] == 1 ;
151- let res = if pass {
152- $crate:: dev:: pass_test:: <$cipher>( tv)
153- } else {
154- $crate:: dev:: fail_test:: <$cipher>( tv)
155- } ;
144+ let res = $crate:: dev:: pass_test:: <$cipher>( tv) ;
145+
146+ if let Err ( reason) = res {
147+ panic!(
148+ "\n \
149+ Failed test #{i}\n \
150+ reason:\t {reason:?}\n \
151+ test vector:\t {tv:?}\n "
152+ ) ;
153+ }
154+ }
155+ }
156+ } ;
157+ }
158+
159+ /// Define AEAD test for failing test vectors
160+ #[ macro_export]
161+ macro_rules! new_fail_test {
162+ ( $name: ident, $test_name: expr, $cipher: ty $( , ) ?) => {
163+ #[ test]
164+ fn $name( ) {
165+ use $crate:: dev:: TestVector ;
166+
167+ $crate:: dev:: blobby:: parse_into_structs!(
168+ include_bytes!( concat!( "data/" , $test_name, ".blb" ) ) ;
169+ static TEST_VECTORS : & [
170+ TestVector { key, nonce, aad, plaintext, ciphertext }
171+ ] ;
172+ ) ;
173+
174+ for ( i, tv) in TEST_VECTORS . iter( ) . enumerate( ) {
175+ let res = $crate:: dev:: fail_test:: <$cipher>( tv) ;
156176
157177 if let Err ( reason) = res {
158178 panic!(
0 commit comments