We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent def96ae commit 47b230aCopy full SHA for 47b230a
lib/internal/crypto/random.js
@@ -51,7 +51,7 @@ function randomBytes(size, cb) {
51
52
const buf = Buffer.alloc(size);
53
54
- if (!cb) return handleError(buf, 0, size);
+ if (!cb) return handleError(_randomBytes(buf, 0, size), buf);
55
56
const wrap = new AsyncWrap(Providers.RANDOMBYTESREQUEST);
57
wrap.ondone = (ex) => { // Retains buf while request is in flight.
@@ -77,7 +77,7 @@ function randomFillSync(buf, offset = 0, size) {
77
size = assertSize(size, elementSize, offset, buf.byteLength);
78
}
79
80
- return handleError(buf, offset, size);
+ return handleError(_randomBytes(buf, offset, size), buf);
81
82
83
function randomFill(buf, offset, size, cb) {
@@ -115,8 +115,7 @@ function randomFill(buf, offset, size, cb) {
115
_randomBytes(buf, offset, size, wrap);
116
117
118
-function handleError(buf, offset, size) {
119
- const ex = _randomBytes(buf, offset, size);
+function handleError(ex, buf) {
120
if (ex) throw ex;
121
return buf;
122
0 commit comments