From e218d567d5af0f778541c4b81f171d4fb1427db1 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Tue, 8 Feb 2022 18:48:28 +0530 Subject: fix(ext/crypto): support EC p256 private key material in exportKey (#13547) Co-authored-by: Luca Casonato --- cli/tests/unit/webcrypto_test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'cli') diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts index ba6aaa327..0e7e2829a 100644 --- a/cli/tests/unit/webcrypto_test.ts +++ b/cli/tests/unit/webcrypto_test.ts @@ -1668,3 +1668,19 @@ Deno.test(async function testAesGcmTagLength() { ); }); }); + +Deno.test(async function ecPrivateKeyMaterialExportSpki() { + // `generateKey` generates a key pair internally stored as "private" key. + const keys = await crypto.subtle.generateKey( + { name: "ECDSA", namedCurve: "P-256" }, + true, + ["sign", "verify"], + ); + + assert(keys.privateKey instanceof CryptoKey); + assert(keys.publicKey instanceof CryptoKey); + + // `exportKey` should be able to perform necessary conversion to export spki. + const spki = await crypto.subtle.exportKey("spki", keys.publicKey); + assert(spki instanceof ArrayBuffer); +}); -- cgit v1.2.3