mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
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:
parent
c67f6c13cd
commit
af97535b7c
3 changed files with 8 additions and 3 deletions
|
@ -160,7 +160,7 @@ unitTest(async function testSignRSASSAKey() {
|
||||||
assert(signature);
|
assert(signature);
|
||||||
});
|
});
|
||||||
|
|
||||||
unitTest(async function subtleCryptoHmacImport() {
|
unitTest(async function subtleCryptoHmacImportExport() {
|
||||||
// deno-fmt-ignore
|
// deno-fmt-ignore
|
||||||
const rawKey = new Uint8Array([
|
const rawKey = new Uint8Array([
|
||||||
1, 2, 3, 4, 5, 6, 7, 8,
|
1, 2, 3, 4, 5, 6, 7, 8,
|
||||||
|
@ -189,4 +189,7 @@ unitTest(async function subtleCryptoHmacImport() {
|
||||||
new Uint8Array(actual),
|
new Uint8Array(actual),
|
||||||
expected,
|
expected,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const exportedKey = await crypto.subtle.exportKey("raw", key);
|
||||||
|
assertEquals(new Uint8Array(exportedKey), rawKey);
|
||||||
});
|
});
|
||||||
|
|
|
@ -577,16 +577,17 @@
|
||||||
|
|
||||||
const handle = key[_handle];
|
const handle = key[_handle];
|
||||||
// 2.
|
// 2.
|
||||||
const bits = WeakMapPrototypeGet(KEY_STORE, handle);
|
const innerKey = WeakMapPrototypeGet(KEY_STORE, handle);
|
||||||
|
|
||||||
switch (key[_algorithm].name) {
|
switch (key[_algorithm].name) {
|
||||||
case "HMAC": {
|
case "HMAC": {
|
||||||
if (bits == null) {
|
if (innerKey == null) {
|
||||||
throw new DOMException("Key is not available", "OperationError");
|
throw new DOMException("Key is not available", "OperationError");
|
||||||
}
|
}
|
||||||
switch (format) {
|
switch (format) {
|
||||||
// 3.
|
// 3.
|
||||||
case "raw": {
|
case "raw": {
|
||||||
|
const bits = innerKey.data;
|
||||||
for (let _i = 7 & (8 - bits.length % 8); _i > 0; _i--) {
|
for (let _i = 7 & (8 - bits.length % 8); _i > 0; _i--) {
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
|
|
1
ext/crypto/lib.deno_crypto.d.ts
vendored
1
ext/crypto/lib.deno_crypto.d.ts
vendored
|
@ -107,6 +107,7 @@ interface SubtleCrypto {
|
||||||
extractable: boolean,
|
extractable: boolean,
|
||||||
keyUsages: KeyUsage[],
|
keyUsages: KeyUsage[],
|
||||||
): Promise<CryptoKey>;
|
): Promise<CryptoKey>;
|
||||||
|
exportKey(format: "raw", key: CryptoKey): Promise<ArrayBuffer>;
|
||||||
sign(
|
sign(
|
||||||
algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams,
|
algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams,
|
||||||
key: CryptoKey,
|
key: CryptoKey,
|
||||||
|
|
Loading…
Add table
Reference in a new issue