@@ -8,47 +8,31 @@ var vectors = require('hash-test-vectors/hmac');
8
8
function testLib ( name , createHmac ) {
9
9
algorithms . forEach ( function ( alg ) {
10
10
test ( name + ' hmac(' + alg + ')' , function ( t ) {
11
- function run ( i ) {
12
- if ( i >= vectors . length ) {
13
- t . end ( ) ;
14
- return ;
15
- }
16
- var input = vectors [ i ] ;
11
+ vectors . forEach ( function ( input ) {
17
12
var output = createHmac ( alg , new Buffer ( input . key , 'hex' ) )
18
13
. update ( input . data , 'hex' ) . digest ( ) ;
19
14
20
15
output = input . truncate ? output . slice ( 0 , input . truncate ) : output ;
21
16
output = output . toString ( 'hex' ) ;
22
- if ( output !== input [ alg ] ) {
23
- t . equal ( output , input [ alg ] ) ;
24
- }
25
- setTimeout ( run , 0 , i + 1 ) ;
26
- }
17
+ t . equal ( output , input [ alg ] ) ;
18
+ } ) ;
27
19
28
- run ( 0 ) ;
20
+ t . end ( ) ;
29
21
} ) ;
30
22
31
23
test ( 'hmac(' + alg + ')' , function ( t ) {
32
- function run ( i ) {
33
- if ( i >= vectors . length ) {
34
- t . end ( ) ;
35
- return ;
36
- }
37
- var input = vectors [ i ] ;
24
+ vectors . forEach ( function ( input ) {
38
25
var hmac = createHmac ( alg , new Buffer ( input . key , 'hex' ) ) ;
39
26
40
27
hmac . end ( input . data , 'hex' ) ;
41
28
var output = hmac . read ( ) ;
42
29
43
30
output = input . truncate ? output . slice ( 0 , input . truncate ) : output ;
44
31
output = output . toString ( 'hex' ) ;
45
- if ( output !== input [ alg ] ) {
46
- t . equal ( output , input [ alg ] ) ;
47
- }
48
- setTimeout ( run , 0 , i + 1 ) ;
49
- }
32
+ t . equal ( output , input [ alg ] ) ;
33
+ } ) ;
50
34
51
- run ( 0 ) ;
35
+ t . end ( ) ;
52
36
} ) ;
53
37
} ) ;
54
38
}
0 commit comments