summaryrefslogtreecommitdiff
path: root/tests/unit_node/crypto/crypto_sign_test.ts
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2024-07-05 10:10:22 +0200
committerGitHub <noreply@github.com>2024-07-05 10:10:22 +0200
commit08e5606c3400d3a993c0ce6748901c56fc3db35b (patch)
tree032d3a09c6d22763ceb703e7908ca159d3d7a809 /tests/unit_node/crypto/crypto_sign_test.ts
parentb290fd01f3f5d32f9d010fc719ced0240759c049 (diff)
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.
Diffstat (limited to 'tests/unit_node/crypto/crypto_sign_test.ts')
-rw-r--r--tests/unit_node/crypto/crypto_sign_test.ts41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/unit_node/crypto/crypto_sign_test.ts b/tests/unit_node/crypto/crypto_sign_test.ts
index 2ca0af943..77c5caf75 100644
--- a/tests/unit_node/crypto/crypto_sign_test.ts
+++ b/tests/unit_node/crypto/crypto_sign_test.ts
@@ -3,6 +3,9 @@
import { assert, assertEquals } from "@std/testing/asserts.ts";
import { createSign, createVerify, sign, verify } from "node:crypto";
import { Buffer } from "node:buffer";
+import fixtures from "../testdata/crypto_digest_fixtures.json" with {
+ type: "json",
+};
const rsaPrivatePem = Buffer.from(
await Deno.readFile(
@@ -138,3 +141,41 @@ AwEH
createSign("SHA256").update("test").sign(pem, "base64");
},
});
+
+Deno.test("crypto.createSign|sign - compare with node", async (t) => {
+ const DATA = "Hello, world!";
+ const privateKey = Deno.readTextFileSync(
+ new URL(import.meta.resolve("../testdata/rsa_private.pem")),
+ );
+ for (const { digest, signature } of fixtures) {
+ await t.step(digest, () => {
+ let actual: string | null;
+ try {
+ const s = createSign(digest);
+ s.update(DATA);
+ actual = s.sign(privateKey).toString("hex");
+ } catch {
+ actual = null;
+ }
+ assertEquals(actual, signature);
+ });
+ }
+});
+
+Deno.test("crypto.createVerify|verify - compare with node", async (t) => {
+ const DATA = "Hello, world!";
+ const publicKey = Deno.readTextFileSync(
+ new URL(import.meta.resolve("../testdata/rsa_public.pem")),
+ );
+ for (const { digest, signature } of fixtures) {
+ await t.step({
+ name: digest,
+ ignore: signature === null,
+ fn: () => {
+ const s = createVerify(digest);
+ s.update(DATA);
+ s.verify(publicKey, signature!);
+ },
+ });
+ }
+});