diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2023-04-19 23:24:26 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-19 23:24:26 +0900 |
commit | fdebb7e7930b175b5dd80f891253000a29c82a4a (patch) | |
tree | 7035fe982f41b6b8e64de20b790c57379cd2851a /cli/tests/unit_node/crypto_sign_test.ts | |
parent | 5a77bb884416753b85f2acecd4895c75f1c53187 (diff) |
fix(ext/node): add crypto.sign|verify methods (#18765)
Diffstat (limited to 'cli/tests/unit_node/crypto_sign_test.ts')
-rw-r--r-- | cli/tests/unit_node/crypto_sign_test.ts | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/cli/tests/unit_node/crypto_sign_test.ts b/cli/tests/unit_node/crypto_sign_test.ts index 1016d0f3e..9d346e7d0 100644 --- a/cli/tests/unit_node/crypto_sign_test.ts +++ b/cli/tests/unit_node/crypto_sign_test.ts @@ -4,7 +4,7 @@ import { assert, assertEquals, } from "../../../test_util/std/testing/asserts.ts"; -import { createSign, createVerify } from "node:crypto"; +import { createSign, createVerify, sign, verify } from "node:crypto"; import { Buffer } from "node:buffer"; const rsaPrivatePem = Buffer.from( @@ -41,32 +41,50 @@ const table = [ }, ]; +const data = Buffer.from("some data to sign"); + Deno.test({ - name: "crypto.Sign - RSA PEM with SHA224, SHA256, SHA384, SHA512 digests", + name: + "crypto.Sign|sign - RSA PEM with SHA224, SHA256, SHA384, SHA512 digests", fn() { for (const testCase of table) { for (const algorithm of testCase.algorithms) { - const signature = createSign(algorithm) - .update("some data to sign") - .sign(rsaPrivatePem, "hex"); - assertEquals(signature, testCase.signature); + assertEquals( + createSign(algorithm) + .update(data) + .sign(rsaPrivatePem, "hex"), + testCase.signature, + ); + assertEquals( + sign(algorithm, data, rsaPrivatePem), + Buffer.from(testCase.signature, "hex"), + ); } } }, }); Deno.test({ - name: "crypto.Verify - RSA PEM with SHA224, SHA256, SHA384, SHA512 digests", + name: + "crypto.Verify|verify - RSA PEM with SHA224, SHA256, SHA384, SHA512 digests", fn() { for (const testCase of table) { for (const algorithm of testCase.algorithms) { assert( - createVerify(algorithm).update("some data to sign").verify( + createVerify(algorithm).update(data).verify( rsaPublicPem, testCase.signature, "hex", ), ); + assert( + verify( + algorithm, + data, + rsaPublicPem, + Buffer.from(testCase.signature, "hex"), + ), + ); } } }, |