From 340764adec4fd613239d8280664361b3c1b9d350 Mon Sep 17 00:00:00 2001 From: Sean Michael Wykes <8363933+SeanWykes@users.noreply.github.com> Date: Mon, 3 Jan 2022 09:24:45 -0300 Subject: fix(ext/crypto): use forgiving base64 encoding for JWK (#13240) Implements "forgiving" in JWK decode passing suitable config to base64::decode_config --- cli/tests/unit/webcrypto_test.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'cli/tests/unit') diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts index c4958fbdf..2d101e975 100644 --- a/cli/tests/unit/webcrypto_test.ts +++ b/cli/tests/unit/webcrypto_test.ts @@ -1419,3 +1419,28 @@ Deno.test(async function testImportEcSpkiPkcs8() { assertEquals(new Uint8Array(expPrivateKeySPKI), spki);*/ } }); + +Deno.test(async function testBase64Forgiving() { + const keyData = `{ + "kty": "oct", + "k": "xxx", + "alg": "HS512", + "key_ops": ["sign", "verify"], + "ext": true + }`; + + const key = await crypto.subtle.importKey( + "jwk", + JSON.parse(keyData), + { name: "HMAC", hash: "SHA-512" }, + true, + ["sign", "verify"], + ); + + assert(key instanceof CryptoKey); + assertEquals(key.type, "secret"); + assertEquals((key.algorithm as HmacKeyAlgorithm).length, 16); + + const exportedKey = await crypto.subtle.exportKey("jwk", key); + assertEquals(exportedKey.k, "xxw"); +}); -- cgit v1.2.3