From 65b0d2316d9c05c12eccd4bb7821598af3085ad0 Mon Sep 17 00:00:00 2001 From: Levente Kurusa Date: Wed, 12 Apr 2023 02:57:57 +0200 Subject: refactor(node/crypto): port polyfill to Rust for randomInt, randomFill, randomFillSync (#18658) Pretty much as per the title, I'd welcome some feedback especially around the array/buffer handling in the two randomFill functions. --- cli/tests/unit_node/internal/_randomFill_test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'cli/tests') diff --git a/cli/tests/unit_node/internal/_randomFill_test.ts b/cli/tests/unit_node/internal/_randomFill_test.ts index 00ff029cc..5e2e154c8 100644 --- a/cli/tests/unit_node/internal/_randomFill_test.ts +++ b/cli/tests/unit_node/internal/_randomFill_test.ts @@ -6,6 +6,7 @@ import { assertNotEquals, assertThrows, } from "../../../../test_util/std/testing/asserts.ts"; +import { deferred } from "../../../../test_util/std/async/deferred.ts"; const validateNonZero = (buf: Buffer) => { if (!buf.some((ch) => ch > 0)) throw new Error("Error"); @@ -15,14 +16,18 @@ const validateZero = (buf: Buffer) => { buf.forEach((val) => assertEquals(val, 0)); }; -Deno.test("[node/crypto.randomFill]", () => { +Deno.test("[node/crypto.randomFill]", async () => { + const promise = deferred(); const buf = Buffer.alloc(10); const before = buf.toString("hex"); randomFill(buf, 5, 5, (_err, bufTwo) => { const after = bufTwo?.toString("hex"); assertEquals(before.slice(0, 10), after?.slice(0, 10)); + promise.resolve(true); }); + + await promise; }); Deno.test("[node/crypto.randomFillSync]", () => { -- cgit v1.2.3