Skip to content

Commit

Permalink
[Tests] crypto.privateDecrypt is only in node 0.12+
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Sep 26, 2024
1 parent bd5d1c2 commit 52a4253
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,31 @@ test('browserify-rsa', function (t) {
);
}

var len = priv.modulus.byteLength();
for (var j2 = 1; j2 < 41; ++j2) {
do {
r = new BN(crypto.randomBytes(len));
} while (r.cmp(priv.modulus) >= 0);
var buf = r.toArrayLike(Buffer, 'be');
if (buf.byteLength < priv.modulus.byteLength()) {
var tmp = new Buffer(priv.modulus.byteLength() - buf.byteLength);
tmp.fill(0);
buf = Buffer.concat([tmp, buf]);
st.test('compared to node encryption', { skip: !crypto.privateDecrypt }, function (s2t) {
var len = priv.modulus.byteLength();
for (var j2 = 1; j2 < 41; ++j2) {
do {
r = new BN(crypto.randomBytes(len));
} while (r.cmp(priv.modulus) >= 0);
var buf = r.toArrayLike(Buffer, 'be');
if (buf.byteLength < priv.modulus.byteLength()) {
var tmp = new Buffer(priv.modulus.byteLength() - buf.byteLength);
tmp.fill(0);
buf = Buffer.concat([tmp, buf]);
}
var nodeEncrypt = crypto.privateDecrypt({
padding: constants.RSA_NO_PADDING,
key: key
}, buf).toString('hex');
s2t.equal(
crt(buf, priv).toString('hex'),
nodeEncrypt,
'round trip key ' + (i + 1) + ' run ' + j2 + ' equal encrypts'
);
}
var nodeEncrypt = crypto.privateDecrypt({
padding: constants.RSA_NO_PADDING,
key: key
}, buf).toString('hex');
st.equal(
crt(buf, priv).toString('hex'),
nodeEncrypt,
'round trip key ' + (i + 1) + ' run ' + j2 + ' equal encrypts'
);
}

s2t.end();
});

st.end();
});
Expand Down

0 comments on commit 52a4253

Please sign in to comment.