From 52a4253a5f5b19401bab450f2f29e68480c56077 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 26 Sep 2024 11:51:24 -0700 Subject: [PATCH] [Tests] `crypto.privateDecrypt` is only in node 0.12+ --- test/index.js | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/test/index.js b/test/index.js index b734991..ebd0f1f 100644 --- a/test/index.js +++ b/test/index.js @@ -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(); });