Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion lib/internal/crypto/keygen.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const {
FunctionPrototypeCall,
ObjectDefineProperty,
ObjectPrototypeHasOwnProperty,
SafeArrayIterator,
} = primordials;

Expand Down Expand Up @@ -356,7 +357,7 @@ function createJob(mode, type, options) {
...encoding);
}
default: {
if (nidOnlyKeyPairs[type] === undefined) {
if (!ObjectPrototypeHasOwnProperty(nidOnlyKeyPairs, type)) {
throw new ERR_INVALID_ARG_VALUE('type', type, 'must be a supported key type');
}
return new NidKeyPairGenJob(mode, nidOnlyKeyPairs[type], ...encoding);
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-crypto-keygen.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ const { hasOpenSSL3 } = require('../common/crypto');
code: 'ERR_INVALID_ARG_VALUE',
message: "The argument 'type' must be a supported key type. Received 'rsa2'"
});

for (const type of ['toString', 'constructor']) {
assert.throws(() => generateKeyPairSync(type, {}), {
name: 'TypeError',
code: 'ERR_INVALID_ARG_VALUE',
message: `The argument 'type' must be a supported key type. Received '${type}'`
});

assert.throws(() => generateKeyPair(type, {}, common.mustNotCall()), {
name: 'TypeError',
code: 'ERR_INVALID_ARG_VALUE',
message: `The argument 'type' must be a supported key type. Received '${type}'`
});
}
}

{
Expand Down
Loading