summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Bevenius <daniel.bevenius@gmail.com>2019-06-20 08:09:17 +0200
committerMichaël Zasso <targos@protonmail.com>2019-07-02 09:07:53 +0200
commit47b230a92b2b99b4ebbe02134a7d127f1940f769 (patch)
tree6f094edaa57fc4f60433dc106e196baf3d635498 /lib
parentdef96ae278bcf0437c5fb345a234f8c1a1076b5b (diff)
downloadandroid-node-v8-47b230a92b2b99b4ebbe02134a7d127f1940f769.tar.gz
android-node-v8-47b230a92b2b99b4ebbe02134a7d127f1940f769.tar.bz2
android-node-v8-47b230a92b2b99b4ebbe02134a7d127f1940f769.zip
crypto: move _randomBytes call out of handleError funct
This commit moves the _randomBytes function call out of the handleError function, which now it takes in an error and a buf object as its parameters. PR-URL: https://github.com/nodejs/node/pull/28318 Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/crypto/random.js7
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/internal/crypto/random.js b/lib/internal/crypto/random.js
index 257b00a9ce..f42458aa78 100644
--- a/lib/internal/crypto/random.js
+++ b/lib/internal/crypto/random.js
@@ -51,7 +51,7 @@ function randomBytes(size, cb) {
const buf = Buffer.alloc(size);
- if (!cb) return handleError(buf, 0, size);
+ if (!cb) return handleError(_randomBytes(buf, 0, size), buf);
const wrap = new AsyncWrap(Providers.RANDOMBYTESREQUEST);
wrap.ondone = (ex) => { // Retains buf while request is in flight.
@@ -77,7 +77,7 @@ function randomFillSync(buf, offset = 0, size) {
size = assertSize(size, elementSize, offset, buf.byteLength);
}
- return handleError(buf, offset, size);
+ return handleError(_randomBytes(buf, offset, size), buf);
}
function randomFill(buf, offset, size, cb) {
@@ -115,8 +115,7 @@ function randomFill(buf, offset, size, cb) {
_randomBytes(buf, offset, size, wrap);
}
-function handleError(buf, offset, size) {
- const ex = _randomBytes(buf, offset, size);
+function handleError(ex, buf) {
if (ex) throw ex;
return buf;
}