mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 19:08:15 +00:00
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:
parent
9a42d65fc7
commit
340764adec
2 changed files with 31 additions and 3 deletions
|
@ -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");
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue