1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

fix(ext/crypto): missing Aes key typings (#12307)

This commit is contained in:
Divy Srivastava 2021-10-03 18:54:46 +05:30 committed by Ryan Dahl
parent c9b0aaa8f0
commit aeab471bea
2 changed files with 30 additions and 1 deletions

View file

@ -499,3 +499,24 @@ unitTest(async function testHkdfDeriveBits() {
); );
assertEquals(result.byteLength, 128 / 8); assertEquals(result.byteLength, 128 / 8);
}); });
// 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);
});

View file

@ -125,6 +125,14 @@ interface Pbkdf2Params extends Algorithm {
salt: BufferSource; 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. */ /** The CryptoKey dictionary of the Web Crypto API represents a cryptographic key. */
interface CryptoKey { interface CryptoKey {
readonly algorithm: KeyAlgorithm; readonly algorithm: KeyAlgorithm;
@ -157,7 +165,7 @@ interface SubtleCrypto {
keyUsages: KeyUsage[], keyUsages: KeyUsage[],
): Promise<CryptoKeyPair>; ): Promise<CryptoKeyPair>;
generateKey( generateKey(
algorithm: HmacKeyGenParams, algorithm: AesKeyGenParams | HmacKeyGenParams,
extractable: boolean, extractable: boolean,
keyUsages: KeyUsage[], keyUsages: KeyUsage[],
): Promise<CryptoKey>; ): Promise<CryptoKey>;