fix(ext/crypto): use forgiving base64 encoding for JWK (#13240)

Implements "forgiving" in JWK decode passing suitable config to base64::decode_config
This commit is contained in:
Sean Michael Wykes 2022-01-03 09:24:45 -03:00 committed by GitHub
parent 9a42d65fc7
commit 340764adec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 3 deletions

View file

@ -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");
});