Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 47b230a

Browse filesBrowse 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 <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>
1 parent def96ae commit 47b230a
Copy full SHA for 47b230a

File tree

Expand file treeCollapse file tree

1 file changed

+3
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+3
-4
lines changed
Open diff view settings
Collapse file

‎lib/internal/crypto/random.js‎

Copy file name to clipboardExpand all lines: lib/internal/crypto/random.js
+3-4Lines changed: 3 additions & 4 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.