@@ -216,18 +216,17 @@ const rfc4231 = [
216
216
}
217
217
] ;
218
218
219
- for ( let i = 0 , l = rfc4231 . length ; i < l ; i ++ ) {
220
- for ( const hash in rfc4231 [ i ] [ ' hmac' ] ) {
221
- let result = crypto . createHmac ( hash , rfc4231 [ i ] [ ' key' ] )
222
- . update ( rfc4231 [ i ] [ ' data' ] )
219
+ for ( const testCase of rfc4231 ) {
220
+ for ( const hash in testCase . hmac ) {
221
+ let result = crypto . createHmac ( hash , testCase . key )
222
+ . update ( testCase . data )
223
223
. digest ( 'hex' ) ;
224
- if ( rfc4231 [ i ] [ ' truncate' ] ) {
224
+ if ( testCase . truncate ) {
225
225
result = result . substr ( 0 , 32 ) ; // first 128 bits == 32 hex chars
226
226
}
227
227
assert . strictEqual (
228
- rfc4231 [ i ] [ 'hmac' ] [ hash ] ,
229
- result ,
230
- `Test HMAC-${ hash } : Test case ${ i + 1 } rfc 4231`
228
+ testCase . hmac [ hash ] ,
229
+ result
231
230
) ;
232
231
}
233
232
}
@@ -341,24 +340,22 @@ const rfc2202_sha1 = [
341
340
}
342
341
] ;
343
342
344
- for ( let i = 0 , l = rfc2202_md5 . length ; i < l ; i ++ ) {
345
- if ( ! common . hasFipsCrypto ) {
343
+ if ( ! common . hasFipsCrypto ) {
344
+ for ( const testCase of rfc2202_md5 ) {
346
345
assert . strictEqual (
347
- rfc2202_md5 [ i ] [ 'hmac' ] ,
348
- crypto . createHmac ( 'md5' , rfc2202_md5 [ i ] [ 'key' ] )
349
- . update ( rfc2202_md5 [ i ] [ 'data' ] )
350
- . digest ( 'hex' ) ,
351
- `Test HMAC-MD5 : Test case ${ i + 1 } rfc 2202`
346
+ testCase . hmac ,
347
+ crypto . createHmac ( 'md5' , testCase . key )
348
+ . update ( testCase . data )
349
+ . digest ( 'hex' )
352
350
) ;
353
351
}
354
352
}
355
- for ( let i = 0 , l = rfc2202_sha1 . length ; i < l ; i ++ ) {
353
+ for ( const testCase of rfc2202_sha1 ) {
356
354
assert . strictEqual (
357
- rfc2202_sha1 [ i ] [ 'hmac' ] ,
358
- crypto . createHmac ( 'sha1' , rfc2202_sha1 [ i ] [ 'key' ] )
359
- . update ( rfc2202_sha1 [ i ] [ 'data' ] )
360
- . digest ( 'hex' ) ,
361
- `Test HMAC-SHA1 : Test case ${ i + 1 } rfc 2202`
355
+ testCase . hmac ,
356
+ crypto . createHmac ( 'sha1' , testCase . key )
357
+ . update ( testCase . data )
358
+ . digest ( 'hex' )
362
359
) ;
363
360
}
364
361
0 commit comments