Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Fix typeof privateKey conditions #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/key-encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -160,4 +160,4 @@ KeyEncoder.prototype.encodePublic = function(publicKey, originalFormat, destinat
}
}

module.exports = KeyEncoder
module.exports = KeyEncoder