Skip to content

Commit 52a4253

Browse files
committed
[Tests] crypto.privateDecrypt is only in node 0.12+
1 parent bd5d1c2 commit 52a4253

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

test/index.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,31 @@ test('browserify-rsa', function (t) {
2626
);
2727
}
2828

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+
);
3950
}
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+
});
5054

5155
st.end();
5256
});

0 commit comments

Comments
 (0)