summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2021-10-03 18:54:46 +0530
committerGitHub <noreply@github.com>2021-10-03 15:24:46 +0200
commit8884141c3f08a04ff3315555c62d120c7647efbe (patch)
tree2e5eec064ee71db7e04f778ac7b6683289306467
parent198f5b95140b52b5a3aad343e62fc0c9b03b9ae7 (diff)
fix(ext/crypto): missing Aes key typings (#12307)
-rw-r--r--cli/tests/unit/webcrypto_test.ts21
-rw-r--r--ext/crypto/lib.deno_crypto.d.ts10
2 files changed, 30 insertions, 1 deletions
diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts
index 493cf9517..1c4788f87 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 3dd66d59a..673e8f9cb 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<CryptoKeyPair>;
generateKey(
- algorithm: HmacKeyGenParams,
+ algorithm: AesKeyGenParams | HmacKeyGenParams,
extractable: boolean,
keyUsages: KeyUsage[],
): Promise<CryptoKey>;