diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts index 493cf95172..1c4788f87d 100644 --- a/cli/tests/unit/webcrypto_test.ts +++ b/cli/tests/unit/webcrypto_test.ts @@ -536,3 +536,24 @@ unitTest(async function testWrapKey() { assert(wrappedKey instanceof ArrayBuffer); assertEquals(wrappedKey.byteLength, 512); }); + +// Doesn't need to cover all cases. +// Only for testing types. +unitTest(async function testAesKeyGen() { + const key = await crypto.subtle.generateKey( + { + name: "AES-GCM", + length: 256, + }, + true, + ["encrypt", "decrypt"], + ); + + assert(key); + assertEquals(key.type, "secret"); + assertEquals(key.extractable, true); + assertEquals(key.usages, ["encrypt", "decrypt"]); + const algorithm = key.algorithm as AesKeyAlgorithm; + assertEquals(algorithm.name, "AES-GCM"); + assertEquals(algorithm.length, 256); +}); diff --git a/ext/crypto/lib.deno_crypto.d.ts b/ext/crypto/lib.deno_crypto.d.ts index 3dd66d59a3..673e8f9cb8 100644 --- a/ext/crypto/lib.deno_crypto.d.ts +++ b/ext/crypto/lib.deno_crypto.d.ts @@ -125,6 +125,14 @@ interface Pbkdf2Params extends Algorithm { salt: BufferSource; } +interface AesKeyGenParams extends Algorithm { + length: number; +} + +interface AesKeyAlgorithm extends KeyAlgorithm { + length: number; +} + /** The CryptoKey dictionary of the Web Crypto API represents a cryptographic key. */ interface CryptoKey { readonly algorithm: KeyAlgorithm; @@ -157,7 +165,7 @@ interface SubtleCrypto { keyUsages: KeyUsage[], ): Promise; generateKey( - algorithm: HmacKeyGenParams, + algorithm: AesKeyGenParams | HmacKeyGenParams, extractable: boolean, keyUsages: KeyUsage[], ): Promise;