91 lines
3.1 KiB
TypeScript
91 lines
3.1 KiB
TypeScript
/**
|
|
* Native-impl stubs currently throw `PrimitiveNotImplemented`. They ship
|
|
* alongside the noble impls so `crypto.config.ts` can be flipped to
|
|
* `'native'` per primitive once in-house implementations land. Until then
|
|
* this suite holds the stubs at the documented throw-contract and keeps
|
|
* them off the 0%-coverage list without silencing them via istanbul
|
|
* excludes.
|
|
*/
|
|
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
import { argon2id } from "../src/primitives/argon2id/impl/argon2id.native/argon2id.native.js";
|
|
import { hkdf } from "../src/primitives/hkdf/impl/hkdf.native/hkdf.native.js";
|
|
import { hmac } from "../src/primitives/hmac/impl/hmac.native/hmac.native.js";
|
|
import { pbkdf2 } from "../src/primitives/pbkdf2/impl/pbkdf2.native/pbkdf2.native.js";
|
|
import { sha256 } from "../src/primitives/sha256/impl/sha256.native/sha256.native.js";
|
|
import { sha384 } from "../src/primitives/sha384/impl/sha384.native/sha384.native.js";
|
|
import { sha512 } from "../src/primitives/sha512/impl/sha512.native/sha512.native.js";
|
|
|
|
const NOT_IMPLEMENTED_CODE = "CRYPTO.UTILS.PRIMITIVE_NOT_IMPLEMENTED";
|
|
const data = new Uint8Array([1, 2, 3]);
|
|
const salt = new Uint8Array([4, 5, 6]);
|
|
|
|
function assertNotImplemented(fn: () => unknown, id: string): void {
|
|
try {
|
|
fn();
|
|
throw new Error(`${id}.native did not throw`);
|
|
} catch (err) {
|
|
expect((err as { code?: string }).code).toBe(NOT_IMPLEMENTED_CODE);
|
|
}
|
|
}
|
|
|
|
describe("crypto-hash native stubs", () => {
|
|
it("sha256.native throws PrimitiveNotImplemented", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
assertNotImplemented(() => sha256(data), "sha256");
|
|
});
|
|
|
|
it("sha384.native throws PrimitiveNotImplemented", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
assertNotImplemented(() => sha384(data), "sha384");
|
|
});
|
|
|
|
it("sha512.native throws PrimitiveNotImplemented", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
assertNotImplemented(() => sha512(data), "sha512");
|
|
});
|
|
|
|
it("hmac.native throws PrimitiveNotImplemented", { timeout: 5000 }, () => {
|
|
assertNotImplemented(() => hmac("SHA-256", data, data), "hmac");
|
|
});
|
|
|
|
it("hkdf.native throws PrimitiveNotImplemented", { timeout: 5000 }, () => {
|
|
assertNotImplemented(
|
|
() => hkdf("SHA-256", data, { salt, info: data, length: 32 }),
|
|
"hkdf"
|
|
);
|
|
});
|
|
|
|
it("pbkdf2.native throws PrimitiveNotImplemented", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
assertNotImplemented(
|
|
() =>
|
|
pbkdf2("SHA-256", data, {
|
|
salt,
|
|
iterations: 1000,
|
|
length: 32,
|
|
}),
|
|
"pbkdf2"
|
|
);
|
|
});
|
|
|
|
it("argon2id.native throws PrimitiveNotImplemented", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
assertNotImplemented(
|
|
() =>
|
|
argon2id(data, {
|
|
salt,
|
|
timeCost: 2,
|
|
memoryCost: 4096,
|
|
parallelism: 1,
|
|
length: 32,
|
|
}),
|
|
"argon2id"
|
|
);
|
|
});
|
|
});
|