From fecf3f61d505abb136be329518eff2c44c8045f3 Mon Sep 17 00:00:00 2001 From: microshine Date: Mon, 1 Feb 2021 17:17:31 +0300 Subject: [PATCH] test: Add test for HMAC key derivation --- test/crypto.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/crypto.ts b/test/crypto.ts index e5d51b0..246b496 100644 --- a/test/crypto.ts +++ b/test/crypto.ts @@ -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); + }); + });