From 9270cad67cffefa4c7ced8361580834d92a00732 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Thu, 16 Sep 2021 12:42:38 +0530 Subject: fix(ext/crypto): don't use core.decode for encoding jwk keys (#12088) --- cli/tests/unit/webcrypto_test.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'cli/tests/unit') diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts index 2dda71e6f..7a2bed758 100644 --- a/cli/tests/unit/webcrypto_test.ts +++ b/cli/tests/unit/webcrypto_test.ts @@ -357,6 +357,30 @@ unitTest(async function subtleCryptoHmacImportExport() { assertEquals(exportedKey2, jwk); }); +// https://github.com/denoland/deno/issues/12085 +unitTest(async function generateImportHmacJwk() { + const key = await crypto.subtle.generateKey( + { + name: "HMAC", + hash: "SHA-512", + }, + true, + ["sign"], + ); + assert(key); + assertEquals(key.type, "secret"); + assertEquals(key.extractable, true); + assertEquals(key.usages, ["sign"]); + + const exportedKey = await crypto.subtle.exportKey("jwk", key); + assertEquals(exportedKey.kty, "oct"); + assertEquals(exportedKey.alg, "HS512"); + assertEquals(exportedKey.key_ops, ["sign"]); + assertEquals(exportedKey.ext, true); + assert(typeof exportedKey.k == "string"); + assertEquals(exportedKey.k.length, 171); +}); + // 2048-bits publicExponent=65537 const pkcs8TestVectors = [ // rsaEncryption -- cgit v1.2.3