crypto: throw error on invalid object in diffieHellman()

PR-URL: https://github.com/nodejs/node/pull/37016
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
ZiJian Liu authored and Michaël Zasso committed 2021-02-02 10:41:56 +01:00
1 parent b533485f32
commit ab64d74791
2 files changed
+15 -2

No files matched your search

+1 -2
View File
@@ -290,8 +290,7 @@ function getFormat(format) {
const dhEnabledKeyTypes = new SafeSet(['dh', 'ec', 'x448', 'x25519']);
function diffieHellman(options) {
if (typeof options !== 'object')
throw new ERR_INVALID_ARG_TYPE('options', 'object', options);
validateObject(options, 'options');
const { privateKey, publicKey } = options;
if (!(privateKey instanceof KeyObject))
+14
View File
@@ -12,6 +12,20 @@ assert.throws(() => crypto.diffieHellman(), {
message: 'The "options" argument must be of type object. Received undefined'
});
assert.throws(() => crypto.diffieHellman(null), {
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options" argument must be of type object. Received null'
});
assert.throws(() => crypto.diffieHellman([]), {
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message:
'The "options" argument must be of type object. ' +
'Received an instance of Array',
});
function test({ publicKey: alicePublicKey, privateKey: alicePrivateKey },
{ publicKey: bobPublicKey, privateKey: bobPrivateKey },
expectedValue) {