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/helper.ts

31 lines
803 B
TypeScript
Raw Normal View History

2022-05-23 21:09:26 +00:00
import { CryptoKey } from "../src";
import { config } from "./config";
/**
* Returns true if blobs from keys are equal
* @param a Crypto key
* @param b Crypto key
*/
export function isKeyEqual(a: CryptoKey, b: CryptoKey) {
if (a instanceof CryptoKey && b instanceof CryptoKey) {
return (a as any).data.equals((b as any).data);
}
return false;
}
function testManufacturer(manufacturerID: string, message: string) {
if (config.name === manufacturerID) {
console.warn(" \x1b[33mWARN:\x1b[0m Test is not supported for %s. %s", manufacturerID, message || "");
return true;
}
return false;
}
export function isSoftHSM(message: string) {
return testManufacturer("SoftHSMv2", message);
}
export function isNSS(message: string) {
return testManufacturer("NSS", message);
}