summaryrefslogtreecommitdiff
path: root/cli/tests/unit/webcrypto_test.ts
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-01-06 16:48:31 +0530
committerGitHub <noreply@github.com>2024-01-06 16:48:31 +0530
commitbfd5f1598cc462b460791fdfca9bb6c2c69fec9b (patch)
tree93dfa9f650d07351d76e2202b7a4f7930727271b /cli/tests/unit/webcrypto_test.ts
parent1d46ee5129dc5c674a7a4b6ad3a40243de4de2a0 (diff)
feat(ext/crypto): initial support for p521 in `generateKey` and `importKey` (#21815)
Part 1 of a potential 3 part series. Ref #13449 The current implementation passes key material back and forth RustCrypto group of crates and ring. ring does not implement p521 yet. This PR adds support for P521 named curve in `generateKey` and `importKey` where we use RustCrypto. Other parts should be moved over to the RustGroup group of crates for consistency.
Diffstat (limited to 'cli/tests/unit/webcrypto_test.ts')
-rw-r--r--cli/tests/unit/webcrypto_test.ts39
1 files changed, 39 insertions, 0 deletions
diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts
index 4e1a31eaa..829330eba 100644
--- a/cli/tests/unit/webcrypto_test.ts
+++ b/cli/tests/unit/webcrypto_test.ts
@@ -2006,3 +2006,42 @@ Deno.test(async function testHmacJwkImport() {
["sign", "verify"],
);
});
+
+Deno.test(async function p521Import() {
+ const jwk = {
+ "crv": "P-521",
+ "ext": true,
+ "key_ops": [
+ "verify",
+ ],
+ "kty": "EC",
+ "x":
+ "AXkSI8nfkc6bu3fifXGuKKbu08g5LKPfxUNQJJYzzPgmN8XLDzx0C9Sdeejl1XoWGrheKPHl0k4tUmHw0cdInpfj",
+ "y":
+ "AT4vjsO0bzVRlN3Wthv9DewncDXS2tlTob5QojV8WX1GzOAikRfWFEP3nspoSv88U447acZAsk5IvgGJuVjgMDlx",
+ };
+ const algorithm = { name: "ECDSA", namedCurve: "P-521" };
+
+ const key = await crypto.subtle.importKey(
+ "jwk",
+ jwk,
+ algorithm,
+ true,
+ ["verify"],
+ );
+
+ assert(key instanceof CryptoKey);
+});
+
+Deno.test(async function p521Generate() {
+ const algorithm = { name: "ECDSA", namedCurve: "P-521" };
+
+ const key = await crypto.subtle.generateKey(
+ algorithm,
+ true,
+ ["sign", "verify"],
+ );
+
+ assert(key.privateKey instanceof CryptoKey);
+ assert(key.publicKey instanceof CryptoKey);
+});