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:
parent
d3f8f905b3
commit
9315daaf02
@ -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
|
||||
|
@ -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');
|
||||
|
Loading…
x
Reference in New Issue
Block a user