◐ Shell
clean mode source ↗

crypto: reject inherited key type names · nodejs/node@eeae754

Original file line numberDiff line numberDiff line change

@@ -181,6 +181,7 @@ function parseKeyEncoding(keyType, options = kEmptyObject) {

181181

}

182182
183183

const nidOnlyKeyPairs = {

184+

'__proto__': null,

184185

'ed25519': EVP_PKEY_ED25519,

185186

'ed448': EVP_PKEY_ED448,

186187

'x25519': EVP_PKEY_X25519,

Original file line numberDiff line numberDiff line change

@@ -55,6 +55,20 @@ const { hasOpenSSL3 } = require('../common/crypto');

5555

code: 'ERR_INVALID_ARG_VALUE',

5656

message: "The argument 'type' must be a supported key type. Received 'rsa2'"

5757

});

58+
59+

for (const type of ['toString', 'constructor']) {

60+

assert.throws(() => generateKeyPairSync(type, {}), {

61+

name: 'TypeError',

62+

code: 'ERR_INVALID_ARG_VALUE',

63+

message: `The argument 'type' must be a supported key type. Received '${type}'`

64+

});

65+
66+

assert.throws(() => generateKeyPair(type, {}, common.mustNotCall()), {

67+

name: 'TypeError',

68+

code: 'ERR_INVALID_ARG_VALUE',

69+

message: `The argument 'type' must be a supported key type. Received '${type}'`

70+

});

71+

}

5872

}

5973
6074

{