Previously, the JS layer would validate that the value of the 'checks'
option was an unsigned 32-bit integer, otherwise throwing an appropriate
error but with a slightly misleading error message. Then the C++ layer
would validate that the value was an unsigned 31-bit integer, otherwise
throwing an appropriate error, but with a different (and even less
helpful) error message.
Instead, make the JS layer aware of the 31-bit restriction so that no
validation in C++ is necessary and so that the error message always
matches the exact requirement.
PR-URL: https://github.com/nodejs/node/pull/47165
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This test had two problems:
* The first argument was a number in both cases, which is what caused
the (expected) ERR_INVALID_ARG_TYPE error -- the validity of the
'checks' option was not actually verified at all. Thus, the first
argument should be valid for this particular test.
* The function returned by common.mustNotCall() was passed to
assert.throws() as a third argument instead of being passed to
checkPrime() as a third argument. (Isn't JavaScript great?) This again
led to the (expected) ERR_INVALID_ARG_TYPE error, but again, the
validity of the 'checks' option was not verified.
Fix both issues by ensuring that all arguments except the 'checks'
option are valid.
Refs: https://github.com/nodejs/node/pull/36997
PR-URL: https://github.com/nodejs/node/pull/47139
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
The current validation in JavaScript is insufficient and also produces
an incorrect error message, restricting the size parameter to 32-bit
values, whereas the C++ backend restricts the size parameter to the
positive range of an int.
This change tightens the validation in JavaScript and adapts the error
message accordingly, making the validation in C++ superfluous.
Refs: https://github.com/nodejs/node/pull/42207
PR-URL: https://github.com/nodejs/node/pull/42234
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/37212
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/37212
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
The previous description incorrectly explained the behavior of
options.add and options.rem for primes that are not safe.
PR-URL: https://github.com/nodejs/node/pull/37085
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
APIs for generating and checking pseudo-random primes
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/36997
Reviewed-By: Tobias Nießen <tniessen@tnie.de>