Skip to content

Commit ab64d74

Browse files
Lxxyxtargos
authored andcommitted
crypto: throw error on invalid object in diffieHellman()
PR-URL: #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>
1 parent b533485 commit ab64d74

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎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
constdhEnabledKeyTypes=newSafeSet(['dh','ec','x448','x25519']);
291291

292292
functiondiffieHellman(options){
293-
if(typeofoptions!=='object')
294-
thrownewERR_INVALID_ARG_TYPE('options','object',options);
293+
validateObject(options,'options');
295294

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

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ 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+
message:
25+
'The "options" argument must be of type object. '+
26+
'Received an instance of Array',
27+
});
28+
1529
functiontest({publicKey: alicePublicKey,privateKey: alicePrivateKey},
1630
{publicKey: bobPublicKey,privateKey: bobPrivateKey},
1731
expectedValue){

0 commit comments

Comments
 (0)