From 1e8a6b94b1dcf98a2ae4de97b3e98e7b3e4e8f7f Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 24 Jun 2024 11:47:12 +0200 Subject: fix(ext/node): rewrite crypto.Hash (#24302) Changes in this PR: - Added new fixed size hash algorithms (blake2b512, blake2s256, sha512-224, sha512-256, sha3-224, sha3-256, sha3-384, sha3-512, sm3) - Added variable size hash algorithms (the concept), with the algorithms shake128 and shake256 - Use cppgc instead of resources for the hasher - Enable Node's crypto.Hash tests and fix found bugs --- tests/unit_node/crypto/crypto_misc_test.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/unit_node/crypto/crypto_misc_test.ts (limited to 'tests/unit_node/crypto/crypto_misc_test.ts') diff --git a/tests/unit_node/crypto/crypto_misc_test.ts b/tests/unit_node/crypto/crypto_misc_test.ts new file mode 100644 index 000000000..8132f2e99 --- /dev/null +++ b/tests/unit_node/crypto/crypto_misc_test.ts @@ -0,0 +1,18 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +import { randomFillSync, randomUUID } from "node:crypto"; +import { assert, assertEquals } from "../../unit/test_util.ts"; + +Deno.test("[node/crypto.getRandomUUID] works the same way as Web Crypto API", () => { + assertEquals(randomUUID().length, crypto.randomUUID().length); + assertEquals(typeof randomUUID(), typeof crypto.randomUUID()); +}); + +Deno.test("[node/crypto.randomFillSync] supported arguments", () => { + const buf = new Uint8Array(10); + + assert(randomFillSync(buf)); + assert(randomFillSync(buf, 0)); + // @ts-ignore: arraybuffer arguments are valid. + assert(randomFillSync(buf.buffer)); + assert(randomFillSync(new DataView(buf.buffer))); +}); -- cgit v1.2.3