1
1
var test = require ( 'tape' ) ;
2
- var crypto = require ( '../' ) ;
2
+ var crypto = require ( 'browserify-aes/browser' ) ;
3
+ var randomBytes = require ( 'randombytes' ) ;
3
4
test ( 'ciphers' , function ( t ) {
4
5
crypto . listCiphers ( ) . forEach ( function ( cipher ) {
5
6
t . test ( cipher , function ( t ) {
6
7
t . plan ( 1 ) ;
7
- var data = crypto . randomBytes ( 562 ) ;
8
- var password = crypto . randomBytes ( 20 ) ;
8
+ var data = randomBytes ( 562 ) ;
9
+ var password = randomBytes ( 20 ) ;
9
10
var crypter = crypto . createCipher ( cipher , password ) ;
10
11
var decrypter = crypto . createDecipher ( cipher , password ) ;
11
12
var out = [ ] ;
@@ -22,4 +23,19 @@ test('ciphers', function (t) {
22
23
test ( 'getCiphers' , function ( t ) {
23
24
t . plan ( 1 ) ;
24
25
t . ok ( crypto . getCiphers ( ) . length , 'get ciphers returns an array' ) ;
26
+ } ) ;
27
+ test ( 'through crypto browserify works' , function ( t ) {
28
+ t . plan ( 2 ) ;
29
+ var crypto = require ( '../' ) ;
30
+ var cipher = 'aes-128-ctr' ;
31
+ var data = randomBytes ( 562 ) ;
32
+ var password = randomBytes ( 20 ) ;
33
+ var crypter = crypto . createCipher ( cipher , password ) ;
34
+ var decrypter = crypto . createDecipher ( cipher , password ) ;
35
+ var out = [ ] ;
36
+ out . push ( decrypter . update ( crypter . update ( data ) ) ) ;
37
+ out . push ( decrypter . update ( crypter . final ( ) ) ) ;
38
+ out . push ( decrypter . final ( ) ) ;
39
+ t . equals ( data . toString ( 'hex' ) , Buffer . concat ( out ) . toString ( 'hex' ) ) ;
40
+ t . ok ( crypto . getCiphers ( ) . length , 'get ciphers returns an array' ) ;
25
41
} ) ;
0 commit comments