Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions doc/api/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -5574,9 +5574,12 @@ changes:

* `buffer` {ArrayBuffer|Buffer|TypedArray|DataView} Must be supplied. The
size of the provided `buffer` must not be larger than `2**31 - 1`.
* `offset` {number} **Default:** `0`
* `size` {number} **Default:** `buffer.length - offset`. The `size` must
not be larger than `2**31 - 1`.
* `offset` {number} The start position, in elements for a `TypedArray` and in
bytes for an `ArrayBuffer` or `DataView`. **Default:** `0`
* `size` {number} The amount to fill, in the same units as `offset`.
**Default:** `buffer.length - offset` for a `TypedArray`, or
`buffer.byteLength - offset` for an `ArrayBuffer` or `DataView`. The `size`
must not be larger than `2**31 - 1`.
* `callback` {Function} `function(err, buf) {}`.

This function is similar to [`crypto.randomBytes()`][] but requires the first
Expand Down Expand Up @@ -5711,9 +5714,12 @@ changes:

* `buffer` {ArrayBuffer|Buffer|TypedArray|DataView} Must be supplied. The
size of the provided `buffer` must not be larger than `2**31 - 1`.
* `offset` {number} **Default:** `0`
* `size` {number} **Default:** `buffer.length - offset`. The `size` must
not be larger than `2**31 - 1`.
* `offset` {number} The start position, in elements for a `TypedArray` and in
bytes for an `ArrayBuffer` or `DataView`. **Default:** `0`
* `size` {number} The amount to fill, in the same units as `offset`.
**Default:** `buffer.length - offset` for a `TypedArray`, or
`buffer.byteLength - offset` for an `ArrayBuffer` or `DataView`. The `size`
must not be larger than `2**31 - 1`.
* Returns: {ArrayBuffer|Buffer|TypedArray|DataView} The object passed as
`buffer` argument.

Expand Down
42 changes: 42 additions & 0 deletions test/parallel/test-crypto-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,48 @@ common.expectWarning('DeprecationWarning',
}));
}

{
const buf = new Uint16Array(4);
const before = Buffer.from(buf.buffer).toString('hex');
crypto.randomFillSync(buf, 1, 1);
const after = Buffer.from(buf.buffer).toString('hex');
assert.notStrictEqual(before, after);
assert.deepStrictEqual(before.slice(0, 4), after.slice(0, 4));
assert.deepStrictEqual(before.slice(8), after.slice(8));
}

{
const buf = new Uint32Array(4);
const before = Buffer.from(buf.buffer).toString('hex');
crypto.randomFillSync(buf, 1, 1);
const after = Buffer.from(buf.buffer).toString('hex');
assert.notStrictEqual(before, after);
assert.deepStrictEqual(before.slice(0, 8), after.slice(0, 8));
assert.deepStrictEqual(before.slice(16), after.slice(16));
}

{
const buf = new Uint16Array(4);
const before = Buffer.from(buf.buffer).toString('hex');
crypto.randomFill(buf, 1, 1, common.mustSucceed((buf) => {
const after = Buffer.from(buf.buffer).toString('hex');
assert.notStrictEqual(before, after);
assert.deepStrictEqual(before.slice(0, 4), after.slice(0, 4));
assert.deepStrictEqual(before.slice(8), after.slice(8));
}));
}

{
const buf = new Uint32Array(4);
const before = Buffer.from(buf.buffer).toString('hex');
crypto.randomFill(buf, 1, 1, common.mustSucceed((buf) => {
const after = Buffer.from(buf.buffer).toString('hex');
assert.notStrictEqual(before, after);
assert.deepStrictEqual(before.slice(0, 8), after.slice(0, 8));
assert.deepStrictEqual(before.slice(16), after.slice(16));
}));
}

{
[
Buffer.alloc(10),
Expand Down
Loading