From 87dc97b49b27c630a850993d2ec427df258de21f Mon Sep 17 00:00:00 2001 From: Marco <mcastelluccio@mozilla.com> Date: Wed, 16 Mar 2016 12:43:44 +0100 Subject: [PATCH] Fix typeof privateKey conditions The old condition always evaluated to false. --- lib/key-encoder.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/key-encoder.js b/lib/key-encoder.js index 286e522..ef2ea53 100644 --- a/lib/key-encoder.js +++ b/lib/key-encoder.js @@ -85,7 +85,7 @@ KeyEncoder.prototype.encodePrivate = function(privateKey, originalFormat, destin /* Parse the incoming private key and convert it to a private key object */ if (originalFormat === 'raw') { - if (!typeof privateKey === 'string') { + if (typeof privateKey !== 'string') { throw 'private key must be a string' } var privateKeyObject = this.options.curve.keyFromPrivate(privateKey, 'hex'), @@ -101,7 +101,7 @@ KeyEncoder.prototype.encodePrivate = function(privateKey, originalFormat, destin } privateKeyObject = ECPrivateKeyASN.decode(privateKey, 'der') } else if (originalFormat === 'pem') { - if (!typeof privateKey === 'string') { + if (typeof privateKey !== 'string') { throw 'private key must be a string' } privateKeyObject = ECPrivateKeyASN.decode(privateKey, 'pem', this.options.privatePEMOptions) @@ -126,7 +126,7 @@ KeyEncoder.prototype.encodePublic = function(publicKey, originalFormat, destinat /* Parse the incoming public key and convert it to a public key object */ if (originalFormat === 'raw') { - if (!typeof publicKey === 'string') { + if (typeof publicKey !== 'string') { throw 'public key must be a string' } publicKeyObject = this.publicKeyObject(publicKey) @@ -140,7 +140,7 @@ KeyEncoder.prototype.encodePublic = function(publicKey, originalFormat, destinat } publicKeyObject = SubjectPublicKeyInfoASN.decode(publicKey, 'der') } else if (originalFormat === 'pem') { - if (!typeof publicKey === 'string') { + if (typeof publicKey !== 'string') { throw 'public key must be a string' } publicKeyObject = SubjectPublicKeyInfoASN.decode(publicKey, 'pem', this.options.publicPEMOptions) @@ -160,4 +160,4 @@ KeyEncoder.prototype.encodePublic = function(publicKey, originalFormat, destinat } } -module.exports = KeyEncoder \ No newline at end of file +module.exports = KeyEncoder