Skip to content

Commit 47b230a

Browse files
danbevtargos
authored andcommitted
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: #28318 Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent def96ae commit 47b230a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

lib/internal/crypto/random.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function randomBytes(size, cb) {
5151

5252
const buf = Buffer.alloc(size);
5353

54-
if (!cb) return handleError(buf, 0, size);
54+
if (!cb) return handleError(_randomBytes(buf, 0, size), buf);
5555

5656
const wrap = new AsyncWrap(Providers.RANDOMBYTESREQUEST);
5757
wrap.ondone = (ex) => { // Retains buf while request is in flight.
@@ -77,7 +77,7 @@ function randomFillSync(buf, offset = 0, size) {
7777
size = assertSize(size, elementSize, offset, buf.byteLength);
7878
}
7979

80-
return handleError(buf, offset, size);
80+
return handleError(_randomBytes(buf, offset, size), buf);
8181
}
8282

8383
function randomFill(buf, offset, size, cb) {
@@ -115,8 +115,7 @@ function randomFill(buf, offset, size, cb) {
115115
_randomBytes(buf, offset, size, wrap);
116116
}
117117

118-
function handleError(buf, offset, size) {
119-
const ex = _randomBytes(buf, offset, size);
118+
function handleError(ex, buf) {
120119
if (ex) throw ex;
121120
return buf;
122121
}

0 commit comments

Comments
 (0)