mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
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:
1 parent
b533485f32
commit
ab64d74791
2 files changed
+15
-2
No files matched your search
@@ -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))
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user