summaryrefslogtreecommitdiff
path: root/tests/unit_node/crypto/crypto_sign_test.ts
diff options
context:
space:
mode:
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!);
+ },
+ });
+ }
+});