diff options
Diffstat (limited to 'cli/tests/unit_node/crypto/crypto_sign_test.ts')
-rw-r--r-- | cli/tests/unit_node/crypto/crypto_sign_test.ts | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/cli/tests/unit_node/crypto/crypto_sign_test.ts b/cli/tests/unit_node/crypto/crypto_sign_test.ts index 58107b563..b04cae407 100644 --- a/cli/tests/unit_node/crypto/crypto_sign_test.ts +++ b/cli/tests/unit_node/crypto/crypto_sign_test.ts @@ -1,6 +1,9 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../../../../test_util/std/assert/mod.ts"; +import { + assert, + assertEquals, +} from "../../../../test_util/std/testing/asserts.ts"; import { createSign, createVerify, sign, verify } from "node:crypto"; import { Buffer } from "node:buffer"; @@ -9,6 +12,11 @@ const rsaPrivatePem = Buffer.from( new URL("../testdata/rsa_private.pem", import.meta.url), ), ); +const rsaPrivatePkcs1Pem = Buffer.from( + await Deno.readFile( + new URL("../testdata/rsa_private_pkcs1.pem", import.meta.url), + ), +); const rsaPublicPem = Buffer.from( await Deno.readFile( new URL("../testdata/rsa_public.pem", import.meta.url), @@ -86,3 +94,39 @@ Deno.test({ } }, }); + +Deno.test({ + name: "crypto.createPrivateKey|sign - RSA PEM", + fn() { + for (const testCase of table) { + for (const algorithm of testCase.algorithms) { + assertEquals( + createSign(algorithm).update(data).sign(rsaPrivatePem, "hex"), + testCase.signature, + ); + assertEquals( + sign(algorithm, data, rsaPrivatePem), + Buffer.from(testCase.signature, "hex"), + ); + } + } + }, +}); + +Deno.test({ + name: "crypto.createPrivateKey|sign - RSA PKCS1 PEM", + fn() { + for (const testCase of table) { + for (const algorithm of testCase.algorithms) { + assertEquals( + createSign(algorithm).update(data).sign(rsaPrivatePkcs1Pem, "hex"), + testCase.signature, + ); + assertEquals( + sign(algorithm, data, rsaPrivatePkcs1Pem), + Buffer.from(testCase.signature, "hex"), + ); + } + } + }, +}); |