Skip to content

Commit feb1519

Browse files
committed
crypto: diffieHellman throw error on invalid object
1 parent e279304 commit feb1519

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/internal/crypto/diffiehellman.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,7 @@ function getFormat(format) {
290290
const dhEnabledKeyTypes = new SafeSet(['dh', 'ec', 'x448', 'x25519']);
291291

292292
function diffieHellman(options) {
293-
if (typeof options !== 'object')
294-
throw new ERR_INVALID_ARG_TYPE('options', 'object', options);
293+
validateObject(options, 'options');
295294

296295
const { privateKey, publicKey } = options;
297296
if (!(privateKey instanceof KeyObject))

test/parallel/test-crypto-dh-stateless.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ assert.throws(() => crypto.diffieHellman(), {
1212
message: 'The "options" argument must be of type object. Received undefined'
1313
});
1414

15+
assert.throws(() => crypto.diffieHellman(null), {
16+
name: 'TypeError',
17+
code: 'ERR_INVALID_ARG_TYPE',
18+
message: 'The "options" argument must be of type object. Received null'
19+
});
20+
21+
assert.throws(() => crypto.diffieHellman([]), {
22+
name: 'TypeError',
23+
code: 'ERR_INVALID_ARG_TYPE',
24+
/* eslint-disable max-len */
25+
message: 'The "options" argument must be of type object. Received an instance of Array'
26+
});
27+
1528
function test({ publicKey: alicePublicKey, privateKey: alicePrivateKey },
1629
{ publicKey: bobPublicKey, privateKey: bobPrivateKey },
1730
expectedValue) {

0 commit comments

Comments
 (0)