1
- var test = require ( " tape" )
1
+ var test = require ( ' tape' ) ;
2
2
3
- var crypto = require ( 'crypto' )
4
- var cryptoB = require ( '../' )
3
+ var crypto = require ( 'crypto' ) ;
4
+ var cryptoB = require ( '../' ) ;
5
5
6
6
function assertSame ( name , fn ) {
7
- test ( name , function ( t ) {
8
- t . plan ( 1 )
9
- fn ( crypto , function ( err , expected ) {
10
- fn ( cryptoB , function ( err , actual ) {
11
- t . equal ( actual , expected )
12
- t . end ( )
13
- } )
14
- } )
15
- } )
7
+ test ( name , function ( t ) {
8
+ t . plan ( 1 ) ;
9
+ fn ( crypto , function ( err , expected ) {
10
+ fn ( cryptoB , function ( err , actual ) {
11
+ t . equal ( actual , expected ) ;
12
+ t . end ( ) ;
13
+ } ) ;
14
+ } ) ;
15
+ } ) ;
16
16
}
17
17
18
18
var algorithms = [ 'sha1' , 'sha256' , 'md5' ] ;
@@ -21,26 +21,37 @@ var encodings = ['binary', 'hex', 'base64'];
21
21
22
22
algorithms . forEach ( function ( algorithm ) {
23
23
encodings . forEach ( function ( encoding ) {
24
-
25
24
assertSame ( algorithm + ' hash using ' + encoding , function ( crypto , cb ) {
26
25
cb ( null , crypto . createHash ( algorithm ) . update ( 'hello' , 'utf-8' ) . digest ( encoding ) ) ;
27
26
} )
28
27
29
28
assertSame ( algorithm + ' hmac using ' + encoding , function ( crypto , cb ) {
30
29
cb ( null , crypto . createHmac ( algorithm , 'secret' ) . update ( 'hello' , 'utf-8' ) . digest ( encoding ) )
31
30
} )
31
+ } ) ;
32
32
33
+ assertSame ( algorithm + ' with raw binary' , function ( crypto , cb ) {
34
+ var seed = 'hello' ;
35
+ for ( var i = 0 ; i < 1000 ; i ++ ) {
36
+ seed = crypto . createHash ( algorithm ) . update ( seed ) . digest ( 'binary' ) ;
37
+ }
38
+ cb ( null , crypto . createHash ( algorithm ) . update ( seed ) . digest ( 'hex' ) ) ;
39
+ } ) ;
40
+
41
+ assertSame ( algorithm + ' empty string' , function ( crypto , cb ) {
42
+ cb ( null , crypto . createHash ( algorithm ) . update ( '' ) . digest ( 'hex' ) ) ;
33
43
} ) ;
34
44
} ) ;
35
45
46
+
36
47
test ( 'randomBytes' , function ( t ) {
37
- t . plan ( 5 )
38
- t . equal ( cryptoB . randomBytes ( 10 ) . length , 10 )
39
- t . ok ( cryptoB . randomBytes ( 10 ) instanceof Buffer )
40
- cryptoB . randomBytes ( 10 , function ( ex , bytes ) {
41
- t . error ( ex )
42
- t . equal ( bytes . length , 10 )
43
- t . ok ( bytes instanceof Buffer )
44
- t . end ( )
45
- } )
46
- } )
48
+ t . plan ( 5 ) ;
49
+ t . equal ( cryptoB . randomBytes ( 10 ) . length , 10 ) ;
50
+ t . ok ( cryptoB . randomBytes ( 10 ) instanceof Buffer ) ;
51
+ cryptoB . randomBytes ( 10 , function ( ex , bytes ) {
52
+ t . error ( ex ) ;
53
+ t . equal ( bytes . length , 10 ) ;
54
+ t . ok ( bytes instanceof Buffer ) ;
55
+ t . end ( ) ;
56
+ } ) ;
57
+ } ) ;
0 commit comments