crypto: fix and simplify prime option validation

PR-URL: https://github.com/nodejs/node/pull/37164
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Tobias Nießen authored and Danielle Adams committed 2021-02-16 09:12:45 -05:00
1 parent dc38dd2c6f
commit 9dac99a11a
2 files changed
+56 -67

No files matched your search

+22
View File
@@ -71,6 +71,28 @@ const pCheckPrime = promisify(checkPrime);
});
});
{
// Negative BigInts should not be converted to 0 silently.
assert.throws(() => generatePrime(20, { add: -1n }, common.mustNotCall()), {
code: 'ERR_OUT_OF_RANGE',
message: 'The value of "options.add" is out of range. It must be >= 0. ' +
'Received -1n'
});
assert.throws(() => generatePrime(20, { rem: -1n }, common.mustNotCall()), {
code: 'ERR_OUT_OF_RANGE',
message: 'The value of "options.rem" is out of range. It must be >= 0. ' +
'Received -1n'
});
assert.throws(() => checkPrime(-1n, common.mustNotCall()), {
code: 'ERR_OUT_OF_RANGE',
message: 'The value of "candidate" is out of range. It must be >= 0. ' +
'Received -1n'
});
}
generatePrime(80, common.mustSucceed((prime) => {
assert(checkPrimeSync(prime));
checkPrime(prime, common.mustSucceed((result) => {