v1.6.0: use non-deprecated features, update deps

This commit is contained in:
AJ ONeal 2018-08-16 18:42:47 -06:00
parent 718c3eb42f
commit 3f7339a491
7 changed files with 12 additions and 24 deletions

View File

@ -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) {

View File

@ -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,"");

View File

@ -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);
}

View File

@ -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;

View File

@ -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();

View File

@ -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": {

View File

@ -47,7 +47,7 @@ var forgeResult = {
var jws = RSA.signJws(
keypair
, new Buffer('24bcc5d4d04d095de47db279b05685c97f787c9b8bd87f88cdaa0137e7228879', 'hex')
, Buffer.from('24bcc5d4d04d095de47db279b05685c97f787c9b8bd87f88cdaa0137e7228879', 'hex')
, '8ef5624f5ec9d3ef'
);