1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-31 11:34:15 -05:00

fix(ext/crypto): add HkdfParams and Pkdf2Params types (#11991)

This commit is contained in:
Divy Srivastava 2021-09-13 02:32:49 +05:30 committed by GitHub
parent 13991e5995
commit 0520ae62dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View file

@ -356,3 +356,27 @@ unitTest(async function subtleCryptoHmacImportExport() {
const exportedKey2 = await crypto.subtle.exportKey("jwk", key2);
assertEquals(exportedKey2, jwk);
});
unitTest(async function testHkdfDeriveBits() {
const rawKey = await crypto.getRandomValues(new Uint8Array(16));
const key = await crypto.subtle.importKey(
"raw",
rawKey,
{ name: "HKDF", hash: "SHA-256" },
false,
["deriveBits"],
);
const salt = await crypto.getRandomValues(new Uint8Array(16));
const info = await crypto.getRandomValues(new Uint8Array(16));
const result = await crypto.subtle.deriveBits(
{
name: "HKDF",
hash: "SHA-256",
salt: salt,
info: info,
},
key,
128,
);
assertEquals(result.byteLength, 128 / 8);
});

View file

@ -109,6 +109,18 @@ interface RsaKeyAlgorithm extends KeyAlgorithm {
publicExponent: Uint8Array;
}
interface HkdfParams extends Algorithm {
hash: HashAlgorithmIdentifier;
info: BufferSource;
salt: BufferSource;
}
interface Pbkdf2Params extends Algorithm {
hash: HashAlgorithmIdentifier;
iterations: number;
salt: BufferSource;
}
/** The CryptoKey dictionary of the Web Crypto API represents a cryptographic key. */
interface CryptoKey {
readonly algorithm: KeyAlgorithm;
@ -194,6 +206,11 @@ interface SubtleCrypto {
key: CryptoKey,
data: BufferSource,
): Promise<ArrayBuffer>;
deriveBits(
algorithm: AlgorithmIdentifier | HkdfParams | Pbkdf2Params,
baseKey: CryptoKey,
length: number,
): Promise<ArrayBuffer>;
}
declare interface Crypto {