Files
bun.sh/test/regression/issue/01466.test.ts
2024-08-31 02:29:16 -07:00

19 lines
779 B
TypeScript

async function doTest(additionalData) {
const name = "AES-GCM";
const key = await crypto.subtle.generateKey({ name, length: 128 }, false, ["encrypt", "decrypt"]);
const plaintext = new Uint8Array();
const iv = crypto.getRandomValues(new Uint8Array(16));
const algorithm = { name, iv, tagLength: 128, additionalData };
const ciphertext = await crypto.subtle.encrypt(algorithm, key, plaintext);
const decrypted = await crypto.subtle.decrypt(algorithm, key, ciphertext);
expect(new TextDecoder().decode(decrypted)).toBe("");
}
it("crypto.subtle.encrypt AES-GCM empty data", async () => {
doTest(undefined);
});
it("crypto.subtle.encrypt AES-GCM empty data with additional associated data", async () => {
doTest(crypto.getRandomValues(new Uint8Array(16)));
});