From 3f7339a491002e456123c6ab07caa2bc3cffe520 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 16 Aug 2018 18:42:47 -0600 Subject: [PATCH] v1.6.0: use non-deprecated features, update deps --- lib/key-utils.js | 2 +- lib/rsa-extra.js | 8 +------- lib/rsa-forge.js | 2 +- lib/rsa-ursa.js | 4 ++-- node.js | 8 ++++---- package.json | 10 ++-------- tests/generate-sig.js | 2 +- 7 files changed, 12 insertions(+), 24 deletions(-) diff --git a/lib/key-utils.js b/lib/key-utils.js index 7c5ee5d..55defeb 100644 --- a/lib/key-utils.js +++ b/lib/key-utils.js @@ -26,7 +26,7 @@ var utils = { }, b64dec: function(str) { - return new Buffer(utils.toStandardB64(str), "base64"); + return Buffer.from(utils.toStandardB64(str), "base64"); }, isB64String: function(x) { diff --git a/lib/rsa-extra.js b/lib/rsa-extra.js index 38a3e77..2ba7dd1 100644 --- a/lib/rsa-extra.js +++ b/lib/rsa-extra.js @@ -7,13 +7,7 @@ function _bigIntToBase64Url(fbin) { // Invalid hex string hex = '0' + hex; } - var buf; - // See https://github.com/Daplie/rsa-compat.js/issues/9 - try { - buf = Buffer.from(hex, 'hex'); - } catch(e) { - buf = new Buffer(hex, 'hex'); - } + var buf = Buffer.from(hex, 'hex'); var b64 = buf.toString('base64'); var b64Url = b64.replace(/[+]/g, "-").replace(/\//g, "_").replace(/=/g,""); diff --git a/lib/rsa-forge.js b/lib/rsa-forge.js index e00da75..ee04e04 100644 --- a/lib/rsa-forge.js +++ b/lib/rsa-forge.js @@ -25,7 +25,7 @@ var forgec = module.exports = { } , _base64UrlToBin: function (base64) { var std64 = forgec._toStandardBase64(base64); - var hex = new Buffer(std64, 'base64').toString("hex"); + var hex = Buffer.from(std64, 'base64').toString("hex"); return new forge.jsbn.BigInteger(hex, 16); } diff --git a/lib/rsa-ursa.js b/lib/rsa-ursa.js index db033e7..369a249 100644 --- a/lib/rsa-ursa.js +++ b/lib/rsa-ursa.js @@ -27,7 +27,7 @@ var ursac = module.exports = { var components = []; [ 'n', 'e', 'p', 'q', 'dp', 'dq', 'qi', 'd' ].forEach(function (key) { - components.push(new Buffer(jwk[key], 'base64')); + components.push(Buffer.from(jwk[key], 'base64')); }); return components; @@ -35,7 +35,7 @@ var ursac = module.exports = { , _publicJwkToComponents: function (jwk) { var components = []; [ 'n', 'e' ].forEach(function (key) { - components.push(new Buffer(jwk[key], 'base64')); + components.push(Buffer.from(jwk[key], 'base64')); }); return components; diff --git a/node.js b/node.js index 7577925..aa88db6 100644 --- a/node.js +++ b/node.js @@ -40,13 +40,13 @@ function create(deps) { RSA.utils._forgeBytesToBuf = function (bytes) { var forge = require("node-forge"); - return new Buffer(forge.util.bytesToHex(bytes), "hex"); + return Buffer.from(forge.util.bytesToHex(bytes), "hex"); }; RSA._internal = require('./lib/node');//.create(deps); RSA._thumbprintInput = function (n, e) { // #L147 const rsaThumbprintTemplate = `{"e":"%s","kty":"RSA","n":"%s"}` - return new Buffer('{"e":"'+ e + '","kty":"RSA","n":"'+ n +'"}', 'ascii'); + return Buffer.from('{"e":"'+ e + '","kty":"RSA","n":"'+ n +'"}', 'ascii'); }; RSA.thumbprint = function (keypair) { var publicKeyJwk = RSA.exportPublicJwk(keypair); @@ -176,7 +176,7 @@ function create(deps) { }; var sigF = keypair._forge.sign(md); var sig64 = RSA.utils.toWebsafeBase64( - new Buffer(forge.util.bytesToHex(sigF), "hex").toString('base64') + Buffer.from(forge.util.bytesToHex(sigF), "hex").toString('base64') ); return sig64; @@ -209,7 +209,7 @@ function create(deps) { if (protect) { protectedHeader = JSON.stringify(protect); // { alg: prot.alg, nonce: prot.nonce, url: prot.url }); } - var protected64 = RSA.utils.toWebsafeBase64(new Buffer(protectedHeader).toString('base64')); + var protected64 = RSA.utils.toWebsafeBase64(Buffer.from(protectedHeader).toString('base64')); var payload64 = RSA.utils.toWebsafeBase64(payload.toString('base64')); var raw = protected64 + "." + payload64; var sha256Buf = crypto.createHash('sha256').update(raw).digest(); diff --git a/package.json b/package.json index 02b3fad..4eda652 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rsa-compat", - "version": "1.5.1", + "version": "1.6.0", "description": "RSA utils that work on Windows, Mac, and Linux with or without C compiler", "main": "node.js", "bin": { @@ -20,15 +20,9 @@ "certificate", "tls", "ssl", - "javascript", - "js", - "node", - "node.js", "windows", "mac", "linux", - "macOS", - "win", "key", "jwk" ], @@ -39,7 +33,7 @@ }, "homepage": "https://git.coolaj86.com/coolaj86/rsa-compat.js#readme", "dependencies": { - "node-forge": "^0.6.41", + "node-forge": "^0.7.6", "ursa-optional": "^0.9.6" }, "trulyOptionalDependencies": { diff --git a/tests/generate-sig.js b/tests/generate-sig.js index 188c698..b0cadf3 100644 --- a/tests/generate-sig.js +++ b/tests/generate-sig.js @@ -47,7 +47,7 @@ var forgeResult = { var jws = RSA.signJws( keypair -, new Buffer('24bcc5d4d04d095de47db279b05685c97f787c9b8bd87f88cdaa0137e7228879', 'hex') +, Buffer.from('24bcc5d4d04d095de47db279b05685c97f787c9b8bd87f88cdaa0137e7228879', 'hex') , '8ef5624f5ec9d3ef' );