From 08e5606c3400d3a993c0ce6748901c56fc3db35b Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Fri, 5 Jul 2024 10:10:22 +0200 Subject: fix(ext/node): rewrite digest handling (#24392) Previously we had many different code paths all handling digests in different places, all with wildly different digest support. This commit rewrites this to use a single digest handling mechanism for all digest operations. It adds various aliases for digest algorithms, like node does. For example `sha1WithRSAEncryption` is an alias for `sha1`. It also adds support for `md5-sha1` digests in various places. --- tests/unit_node/crypto/crypto_hkdf_test.ts | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/unit_node/crypto/crypto_hkdf_test.ts (limited to 'tests/unit_node/crypto/crypto_hkdf_test.ts') diff --git a/tests/unit_node/crypto/crypto_hkdf_test.ts b/tests/unit_node/crypto/crypto_hkdf_test.ts new file mode 100644 index 000000000..be5d99086 --- /dev/null +++ b/tests/unit_node/crypto/crypto_hkdf_test.ts @@ -0,0 +1,36 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +import { hkdfSync } from "node:crypto"; +import { assertEquals } from "@std/assert/mod.ts"; +import { Buffer } from "node:buffer"; +import nodeFixtures from "../testdata/crypto_digest_fixtures.json" with { + type: "json", +}; + +Deno.test("crypto.hkdfSync - compare with node", async (t) => { + const DATA = "Hello, world!"; + const SALT = "salt"; + const INFO = "info"; + const KEY_LEN = 64; + + for (const { digest, hkdf } of nodeFixtures) { + await t.step({ + name: digest, + ignore: digest.includes("blake"), + fn() { + let actual: string | null; + try { + actual = Buffer.from(hkdfSync( + digest, + DATA, + SALT, + INFO, + KEY_LEN, + )).toString("hex"); + } catch { + actual = null; + } + assertEquals(actual, hkdf); + }, + }); + } +}); -- cgit v1.2.3