1-
21#[ macro_export]
32macro_rules! new_test {
43 ( $name: ident, $test_name: expr, $cipher: ty) => {
54 #[ test]
65 fn $name( ) {
7- use block_cipher_trait:: BlockCipher ;
8- use block_cipher_trait:: generic_array:: GenericArray ;
9- use block_cipher_trait:: generic_array:: typenum:: Unsigned ;
106 use block_cipher_trait:: blobby:: Blob3Iterator ;
7+ use block_cipher_trait:: generic_array:: typenum:: Unsigned ;
8+ use block_cipher_trait:: generic_array:: GenericArray ;
9+ use block_cipher_trait:: BlockCipher ;
1110
1211 fn run_test( key: & [ u8 ] , pt: & [ u8 ] , ct: & [ u8 ] ) -> bool {
1312 let state = <$cipher as BlockCipher >:: new_varkey( key) . unwrap( ) ;
@@ -45,14 +44,22 @@ macro_rules! new_test {
4544 // check that `encrypt_blocks` and `encrypt_block`
4645 // result in the same ciphertext
4746 state. encrypt_blocks( & mut blocks1) ;
48- for b in blocks2. iter_mut( ) { state. encrypt_block( b) ; }
49- if blocks1 != blocks2 { return false ; }
47+ for b in blocks2. iter_mut( ) {
48+ state. encrypt_block( b) ;
49+ }
50+ if blocks1 != blocks2 {
51+ return false ;
52+ }
5053
5154 // check that `encrypt_blocks` and `encrypt_block`
5255 // result in the same plaintext
5356 state. decrypt_blocks( & mut blocks1) ;
54- for b in blocks2. iter_mut( ) { state. decrypt_block( b) ; }
55- if blocks1 != blocks2 { return false ; }
57+ for b in blocks2. iter_mut( ) {
58+ state. decrypt_block( b) ;
59+ }
60+ if blocks1 != blocks2 {
61+ return false ;
62+ }
5663
5764 true
5865 }
@@ -64,23 +71,25 @@ macro_rules! new_test {
6471 let plaintext = row[ 1 ] ;
6572 let ciphertext = row[ 2 ] ;
6673 if !run_test( key, plaintext, ciphertext) {
67- panic!( "\n \
68- Failed test №{}\n \
69- key:\t {:?}\n \
70- plaintext:\t {:?}\n \
71- ciphertext:\t {:?}\n ",
74+ panic!(
75+ "\n \
76+ Failed test №{}\n \
77+ key:\t {:?}\n \
78+ plaintext:\t {:?}\n \
79+ ciphertext:\t {:?}\n ",
7280 i, key, plaintext, ciphertext,
7381 ) ;
7482 }
7583
7684 // test parallel blocks encryption/decryption
7785 if pb != 1 {
7886 if !run_par_test( key, plaintext) {
79- panic!( "\n \
80- Failed parallel test №{}\n \
81- key:\t {:?}\n \
82- plaintext:\t {:?}\n \
83- ciphertext:\t {:?}\n ",
87+ panic!(
88+ "\n \
89+ Failed parallel test №{}\n \
90+ key:\t {:?}\n \
91+ plaintext:\t {:?}\n \
92+ ciphertext:\t {:?}\n ",
8493 i, key, plaintext, ciphertext,
8594 ) ;
8695 }
@@ -90,16 +99,16 @@ macro_rules! new_test {
9099 let key = Default :: default ( ) ;
91100 let _ = <$cipher as BlockCipher >:: new( & key) . clone( ) ;
92101 }
93- }
102+ } ;
94103}
95104
96105#[ macro_export]
97106macro_rules! bench {
98107 ( $cipher: path, $key_len: expr) => {
99108 extern crate test;
100109
101- use test:: Bencher ;
102110 use block_cipher_trait:: BlockCipher ;
111+ use test:: Bencher ;
103112
104113 #[ bench]
105114 pub fn encrypt( bh: & mut Bencher ) {
@@ -124,5 +133,5 @@ macro_rules! bench {
124133 } ) ;
125134 bh. bytes = block. len( ) as u64 ;
126135 }
127- }
136+ } ;
128137}
0 commit comments