mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
crypto: accept decimal Number in randomBytes
This change adds the ability to pass a double into randomBytes. PR-URL: https://github.com/nodejs/node/pull/15130 Fixes: https://github.com/nodejs/node/issues/15118 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
1 parent
8d5b0130da
commit
484bfa2e37
2 files changed
+15
-14
No files matched your search
+3
-3
@@ -5616,13 +5616,13 @@ void RandomBytesProcessSync(Environment* env,
|
||||
void RandomBytes(const FunctionCallbackInfo<Value>& args) {
|
||||
Environment* env = Environment::GetCurrent(args);
|
||||
|
||||
if (!args[0]->IsUint32()) {
|
||||
if (!args[0]->IsNumber() || args[0].As<v8::Number>()->Value() < 0) {
|
||||
return env->ThrowTypeError("size must be a number >= 0");
|
||||
}
|
||||
|
||||
const int64_t size = args[0]->IntegerValue();
|
||||
if (size < 0 || size > Buffer::kMaxLength)
|
||||
return env->ThrowRangeError("size is not a valid Smi");
|
||||
if (size > Buffer::kMaxLength)
|
||||
return env->ThrowTypeError("size must be a uint32");
|
||||
|
||||
Local<Object> obj = env->randombytes_constructor_template()->
|
||||
NewInstance(env->context()).ToLocalChecked();
|
||||
|
||||
Reference in new issue
Block a user