@@ -4,21 +4,15 @@ var Buffer = require('safe-buffer').Buffer;
4
4
var asn1 = require ( 'parse-asn1/asn1' ) ;
5
5
var test = require ( 'tape' ) . test ;
6
6
var nCrypto = require ( 'crypto' ) ;
7
+ var semver = require ( 'semver' ) ;
7
8
var bCrypto = require ( '../browser' ) ;
8
9
var fixtures = require ( './fixtures' ) ;
9
10
10
- function isNode10 ( ) {
11
- return parseInt ( process . version . split ( '.' ) [ 1 ] , 10 ) <= 10 ;
12
- }
13
-
14
11
fixtures . valid . rsa . forEach ( function ( f ) {
15
12
var message = Buffer . from ( f . message ) ;
16
13
var pub = Buffer . from ( f [ 'public' ] , 'base64' ) ;
17
14
var priv ;
18
15
19
- // skip passphrase tests in node 10
20
- if ( f . passphrase && isNode10 ( ) ) { return ; }
21
-
22
16
if ( f . passphrase ) {
23
17
priv = {
24
18
key : Buffer . from ( f [ 'private' ] , 'base64' ) ,
@@ -63,14 +57,41 @@ fixtures.valid.rsa.forEach(function (f) {
63
57
} ) ;
64
58
} ) ;
65
59
60
+ // node has padding support since 8.0
61
+ // TODO: figure out why node v8.0 - v8.6 is broken
62
+ ( semver . satisfies ( process . versions . node , '>= 8.6' ) ? test : test . skip ) ( 'padding option' , function ( t ) {
63
+ var f = fixtures . valid . rsa [ 0 ] ;
64
+ var message = Buffer . from ( f . message ) ;
65
+ var priv = {
66
+ key : Buffer . from ( f [ 'private' ] , 'base64' ) ,
67
+ padding : 11646841 // Some invalid value
68
+ } ;
69
+
70
+ t . test ( 'invalid padding option' , function ( st ) {
71
+ var bSign = bCrypto . createSign ( f . scheme ) ;
72
+ var nSign = nCrypto . createSign ( f . scheme ) ;
73
+ st [ 'throws' ] (
74
+ function ( ) { bSign . update ( message ) . sign ( priv ) ; } ,
75
+ / i l l e g a l o r u n s u p p o r t e d p a d d i n g m o d e / ,
76
+ 'browser throws exception with proper message'
77
+ ) ;
78
+ st [ 'throws' ] (
79
+ function ( ) { nSign . update ( message ) . sign ( priv ) ; } ,
80
+ / i l l e g a l o r u n s u p p o r t e d p a d d i n g m o d e / ,
81
+ 'node throws exception with proper message'
82
+ ) ;
83
+
84
+ st . end ( ) ;
85
+ } ) ;
86
+
87
+ t . end ( ) ;
88
+ } ) ;
89
+
66
90
fixtures . valid . ec . forEach ( function ( f ) {
67
91
var message = Buffer . from ( f . message ) ;
68
92
var pub = Buffer . from ( f [ 'public' ] , 'base64' ) ;
69
93
var priv ;
70
94
71
- // skip passphrase tests in node 10
72
- if ( f . passphrase && isNode10 ( ) ) { return ; }
73
-
74
95
if ( f . passphrase ) {
75
96
priv = {
76
97
key : Buffer . from ( f [ 'private' ] , 'base64' ) ,
0 commit comments