GeezerVison is showing github.com — crypto: throw error on invalid object in diffieHellman() · nodejs/node@ab64d74
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/crypto/diffiehellman.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -290,8 +290,7 @@ function getFormat(format) { |
290 | 290 | const dhEnabledKeyTypes = new SafeSet(['dh', 'ec', 'x448', 'x25519']); |
291 | 291 |
|
292 | 292 | function diffieHellman(options) { |
293 | | - if (typeof options !== 'object') |
294 | | - throw new ERR_INVALID_ARG_TYPE('options', 'object', options); |
| 293 | + validateObject(options, 'options'); |
295 | 294 |
|
296 | 295 | const { privateKey, publicKey } = options; |
297 | 296 | if (!(privateKey instanceof KeyObject)) |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-crypto-dh-stateless.js +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,6 +12,20 @@ assert.throws(() => crypto.diffieHellman(), { |
12 | 12 | message: 'The "options" argument must be of type object. Received undefined' |
13 | 13 | }); |
14 | 14 |
|
| 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 | + |
15 | 29 | function test({ publicKey: alicePublicKey, privateKey: alicePrivateKey }, |
16 | 30 | { publicKey: bobPublicKey, privateKey: bobPrivateKey }, |
17 | 31 | expectedValue) { |
|