crypto: fix key handle extraction

PR-URL: https://github.com/nodejs/node/pull/25562
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Tobias Nießen 2019-01-18 10:56:44 +01:00 committed by Ruben Bridgewater
parent d3f8f905b3
commit 9315daaf02
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
2 changed files with 12 additions and 1 deletions

View File

@ -215,7 +215,7 @@ function parsePrivateKeyEncoding(enc, keyType, objName) {
function getKeyObjectHandle(key, isPublic, allowKeyObject) {
if (!allowKeyObject) {
return new ERR_INVALID_ARG_TYPE(
throw new ERR_INVALID_ARG_TYPE(
'key',
['string', 'Buffer', 'TypedArray', 'DataView'],
key

View File

@ -58,6 +58,17 @@ const privatePem = fixtures.readSync('test_rsa_privkey.pem', 'ascii');
assert(plaintext.equals(deciphered));
}
{
// Passing an existing key object should throw.
const publicKey = createPublicKey(publicPem);
common.expectsError(() => createPublicKey(publicKey), {
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "key" argument must be one of type string, Buffer, ' +
'TypedArray, or DataView. Received type object'
});
}
{
const publicKey = createPublicKey(publicPem);
assert.strictEqual(publicKey.type, 'public');