test: Add test for HMAC key derivation

This commit is contained in:
microshine 2021-02-01 17:17:31 +03:00
parent 4746eb565d
commit fecf3f61d5
1 changed files with 18 additions and 0 deletions

View File

@ -39,4 +39,22 @@ context("Crypto", () => {
["verify"]), core.CryptoError);
});
it("HKDF derive HMAC key", async () => {
const hkdf = await crypto.subtle.importKey("raw", new Uint8Array([1, 2, 3, 4, 5]), { name: "HKDF" }, false, ["deriveKey"]);
const hmac = await crypto.subtle.deriveKey({
name: "HKDF",
hash: "SHA-256",
info: new Uint8Array([1, 2, 3, 4, 5]),
salt: new Uint8Array([1, 2, 3, 4, 5]),
} as globalThis.HkdfParams,
hkdf,
{
name: "HMAC",
hash: "SHA-1",
} as globalThis.HmacImportParams,
false,
["sign"]);
assert.strictEqual((hmac.algorithm as globalThis.HmacKeyAlgorithm).length, 512);
});
});