GeezerVison is showing github.com — crypto: validate key generation options · nodejs/node@ac954d2
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/keygen.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -209,11 +209,11 @@ const nidOnlyKeyPairs = { |
209 | 209 | function createJob(mode, type, options) { |
210 | 210 | validateString(type, 'type'); |
211 | 211 |
|
212 | | - const encoding = new SafeArrayIterator(parseKeyEncoding(type, options)); |
213 | | - |
214 | 212 | if (options !== undefined) |
215 | 213 | validateObject(options, 'options'); |
216 | 214 |
|
| 215 | + const encoding = new SafeArrayIterator(parseKeyEncoding(type, options)); |
| 216 | + |
217 | 217 | switch (type) { |
218 | 218 | case 'rsa': |
219 | 219 | case 'rsa-pss': |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-crypto-keygen.js +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -89,6 +89,21 @@ const isBoringSSL = process.features.openssl_is_boringssl; |
89 | 89 | message: 'The "options" argument must be of type object. ' + |
90 | 90 | 'Received type number (0)' |
91 | 91 | }); |
| 92 | + |
| 93 | + for (const type of ['rsa', 'ed25519']) { |
| 94 | + assert.throws(() => generateKeyPairSync(type, null), { |
| 95 | + name: 'TypeError', |
| 96 | + code: 'ERR_INVALID_ARG_TYPE', |
| 97 | + message: 'The "options" argument must be of type object. ' + |
| 98 | + 'Received null' |
| 99 | + }); |
| 100 | + assert.throws(() => generateKeyPair(type, null, common.mustNotCall()), { |
| 101 | + name: 'TypeError', |
| 102 | + code: 'ERR_INVALID_ARG_TYPE', |
| 103 | + message: 'The "options" argument must be of type object. ' + |
| 104 | + 'Received null' |
| 105 | + }); |
| 106 | + } |
92 | 107 | } |
93 | 108 |
|
94 | 109 | { |
|