fix(ext/crypto): exportKey() for HMAC (#11737)

Fixes typings and innerKey processing (WPT doesn't test 
exportKey for HMAC so this wasn't caught earlier).
This commit is contained in:
Divy Srivastava 2021-08-17 14:59:32 +05:30 committed by GitHub
parent c67f6c13cd
commit af97535b7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 3 deletions

View file

@ -577,16 +577,17 @@
const handle = key[_handle];
// 2.
const bits = WeakMapPrototypeGet(KEY_STORE, handle);
const innerKey = WeakMapPrototypeGet(KEY_STORE, handle);
switch (key[_algorithm].name) {
case "HMAC": {
if (bits == null) {
if (innerKey == null) {
throw new DOMException("Key is not available", "OperationError");
}
switch (format) {
// 3.
case "raw": {
const bits = innerKey.data;
for (let _i = 7 & (8 - bits.length % 8); _i > 0; _i--) {
bits.push(0);
}

View file

@ -107,6 +107,7 @@ interface SubtleCrypto {
extractable: boolean,
keyUsages: KeyUsage[],
): Promise<CryptoKey>;
exportKey(format: "raw", key: CryptoKey): Promise<ArrayBuffer>;
sign(
algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams,
key: CryptoKey,