diff options
author | Kenta Moriuchi <moriken@kimamass.com> | 2024-01-11 07:37:25 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-10 15:37:25 -0700 |
commit | 515a34b4de222e35c7ade1b92614d746e73d4c2e (patch) | |
tree | 8284201fc826a33f12597959a8a8be14e0f524bd /ext/node/polyfills/internal/crypto/random.ts | |
parent | d4893eb51a01c5a692d8ca74a3b8ff95c5fd1d9f (diff) |
refactor: use `core.ensureFastOps()` (#21888)
Diffstat (limited to 'ext/node/polyfills/internal/crypto/random.ts')
-rw-r--r-- | ext/node/polyfills/internal/crypto/random.ts | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/ext/node/polyfills/internal/crypto/random.ts b/ext/node/polyfills/internal/crypto/random.ts index 450754734..52f6db272 100644 --- a/ext/node/polyfills/internal/crypto/random.ts +++ b/ext/node/polyfills/internal/crypto/random.ts @@ -4,6 +4,22 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials +import { core, primordials } from "ext:core/mod.js"; +const { + op_node_check_prime, + op_node_check_prime_async, + op_node_check_prime_bytes, + op_node_check_prime_bytes_async, + op_node_gen_prime_async, +} = core.ensureFastOps(); +const { + op_node_gen_prime, +} = core.ensureFastOps(true); +const { + StringPrototypePadStart, + StringPrototypeToString, +} = primordials; + import { notImplemented } from "ext:deno_node/_utils.ts"; import randomBytes from "ext:deno_node/internal/crypto/_randomBytes.ts"; import randomFill, { @@ -32,17 +48,6 @@ export { } from "ext:deno_node/internal/crypto/_randomFill.mjs"; export { default as randomInt } from "ext:deno_node/internal/crypto/_randomInt.ts"; -import { primordials } from "ext:core/mod.js"; -const { StringPrototypePadStart, StringPrototypeToString } = primordials; - -const { core } = globalThis.__bootstrap; -const { ops } = core; -const { - op_node_gen_prime_async, - op_node_check_prime_bytes_async, - op_node_check_prime_async, -} = Deno.core.ensureFastOps(); - export type LargeNumberLike = | ArrayBufferView | SharedArrayBuffer @@ -129,7 +134,7 @@ export function checkPrimeSync( validateInt32(checks, "options.checks", 0); if (typeof candidate === "bigint") { - return ops.op_node_check_prime(candidate, checks); + return op_node_check_prime(candidate, checks); } else if (!isAnyArrayBuffer(candidate) && !isArrayBufferView(candidate)) { throw new ERR_INVALID_ARG_TYPE( "candidate", @@ -144,7 +149,7 @@ export function checkPrimeSync( ); } - return ops.op_node_check_prime_bytes(candidate, checks); + return op_node_check_prime_bytes(candidate, checks); } export interface GeneratePrimeOptions { @@ -186,7 +191,7 @@ export function generatePrimeSync( bigint, } = validateRandomPrimeJob(size, options); - const prime = ops.op_node_gen_prime(size); + const prime = op_node_gen_prime(size); if (bigint) return arrayBufferToUnsignedBigInt(prime.buffer); return prime.buffer; } |