From 48bee9204dbccf0c67d21c9a25edb259d72b5253 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 14 Mar 2019 11:50:37 -0600 Subject: [PATCH] v1.2.14: use try/catch on PEM import --- keypairs.js | 10 +++++++--- package.json | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/keypairs.js b/keypairs.js index bf26789..1bbebb4 100644 --- a/keypairs.js +++ b/keypairs.js @@ -346,10 +346,14 @@ Enc.bufToUrlBase64 = function (buf) { // For 'rsa-compat' module only // PLEASE do not use these sync methods, they are deprecated Keypairs._importSync = function (opts) { - if ('RSA' === opts.jwk.kty) { - return Rasha.importSync(opts); - } else { + try { return Eckles.importSync(opts); + } catch(e) { + try { + return Rasha.importSync(opts); + } catch(e) { + console.error("options.pem does not appear to be a valid RSA or ECDSA public or private key"); + } } }; // PLEASE do not use these, they are deprecated diff --git a/package.json b/package.json index 8392355..227928c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "keypairs", - "version": "1.2.13", + "version": "1.2.14", "description": "Lightweight RSA/ECDSA keypair generation and JWK <-> PEM using node's native RSA and ECDSA support", "main": "keypairs.js", "files": [