This repository has been archived on 2023-04-04. You can view files and clone it, but cannot push or open issues or pull requests.
webcrypto/packages/pkcs11/test/hmac.ts

46 lines
1.3 KiB
TypeScript

import * as assert from "assert";
import { HmacCryptoKey } from "../src/mechs";
import { Pkcs11HmacKeyGenParams, Pkcs11HmacKeyImportParams } from "../src/types";
import { crypto } from "./config";
context("HMAC", () => {
context("token", () => {
it("generate", async () => {
const alg: Pkcs11HmacKeyGenParams = {
name: "HMAC",
hash: "SHA-256",
label: "custom",
token: true,
sensitive: true,
};
const key = await crypto.subtle.generateKey(alg, false, ["sign", "verify"]);
assert.strictEqual(key.algorithm.token, true);
assert.strictEqual(key.algorithm.label, alg.label);
assert.strictEqual(key.algorithm.sensitive, true);
});
it("import", async () => {
const alg: Pkcs11HmacKeyImportParams = {
name: "HMAC",
hash: "SHA-256",
label: "custom",
token: true,
sensitive: true,
};
const raw = Buffer.from("1234567890abcdef1234567809abcdef");
const key = await crypto.subtle.importKey("raw", raw, alg, false, ["sign", "verify"]) as HmacCryptoKey;
assert.strictEqual(key.algorithm.token, true);
assert.strictEqual(key.algorithm.label, alg.label);
assert.strictEqual(key.algorithm.sensitive, true);
});
});
});