@@ -26,27 +26,31 @@ test('browserify-rsa', function (t) {
26
26
) ;
27
27
}
28
28
29
- var len = priv . modulus . byteLength ( ) ;
30
- for ( var j2 = 1 ; j2 < 41 ; ++ j2 ) {
31
- do {
32
- r = new BN ( crypto . randomBytes ( len ) ) ;
33
- } while ( r . cmp ( priv . modulus ) >= 0 ) ;
34
- var buf = r . toArrayLike ( Buffer , 'be' ) ;
35
- if ( buf . byteLength < priv . modulus . byteLength ( ) ) {
36
- var tmp = new Buffer ( priv . modulus . byteLength ( ) - buf . byteLength ) ;
37
- tmp . fill ( 0 ) ;
38
- buf = Buffer . concat ( [ tmp , buf ] ) ;
29
+ st . test ( 'compared to node encryption' , { skip : ! crypto . privateDecrypt } , function ( s2t ) {
30
+ var len = priv . modulus . byteLength ( ) ;
31
+ for ( var j2 = 1 ; j2 < 41 ; ++ j2 ) {
32
+ do {
33
+ r = new BN ( crypto . randomBytes ( len ) ) ;
34
+ } while ( r . cmp ( priv . modulus ) >= 0 ) ;
35
+ var buf = r . toArrayLike ( Buffer , 'be' ) ;
36
+ if ( buf . byteLength < priv . modulus . byteLength ( ) ) {
37
+ var tmp = new Buffer ( priv . modulus . byteLength ( ) - buf . byteLength ) ;
38
+ tmp . fill ( 0 ) ;
39
+ buf = Buffer . concat ( [ tmp , buf ] ) ;
40
+ }
41
+ var nodeEncrypt = crypto . privateDecrypt ( {
42
+ padding : constants . RSA_NO_PADDING ,
43
+ key : key
44
+ } , buf ) . toString ( 'hex' ) ;
45
+ s2t . equal (
46
+ crt ( buf , priv ) . toString ( 'hex' ) ,
47
+ nodeEncrypt ,
48
+ 'round trip key ' + ( i + 1 ) + ' run ' + j2 + ' equal encrypts'
49
+ ) ;
39
50
}
40
- var nodeEncrypt = crypto . privateDecrypt ( {
41
- padding : constants . RSA_NO_PADDING ,
42
- key : key
43
- } , buf ) . toString ( 'hex' ) ;
44
- st . equal (
45
- crt ( buf , priv ) . toString ( 'hex' ) ,
46
- nodeEncrypt ,
47
- 'round trip key ' + ( i + 1 ) + ' run ' + j2 + ' equal encrypts'
48
- ) ;
49
- }
51
+
52
+ s2t . end ( ) ;
53
+ } ) ;
50
54
51
55
st . end ( ) ;
52
56
} ) ;
0 commit comments