-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crypto: add randomFill and randomFillSync
crypto.randomFill and crypto.randomFillSync are similar to crypto.randomBytes, but allow passing in a buffer as the first argument. This allows us to reuse buffers to prevent having to create a new one on every call. PR-URL: #10209 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net>
- Loading branch information
1 parent
7af1ad0
commit 4caab6d
Showing
7 changed files
with
461 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
const ReflectApply = Reflect.apply; | ||
|
||
// This function is borrowed from the function with the same name on V8 Extras' | ||
// `utils` object. V8 implements Reflect.apply very efficiently in conjunction | ||
// with the spread syntax, such that no additional special case is needed for | ||
// function calls w/o arguments. | ||
// Refs: https://github.com/v8/v8/blob/d6ead37d265d7215cf9c5f768f279e21bd170212/src/js/prologue.js#L152-L156 | ||
function uncurryThis(func) { | ||
return (thisArg, ...args) => ReflectApply(func, thisArg, args); | ||
} | ||
|
||
const TypedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype); | ||
|
||
const TypedArrayProto_toStringTag = | ||
uncurryThis( | ||
Object.getOwnPropertyDescriptor(TypedArrayPrototype, | ||
Symbol.toStringTag).get); | ||
|
||
function isUint8Array(value) { | ||
return TypedArrayProto_toStringTag(value) === 'Uint8Array'; | ||
} | ||
|
||
module.exports = { | ||
isUint8Array | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.