import { expect } from "@std/expect"; import { generateKeys } from "./keys.ts"; import { encryptText } from "./encrypt.ts"; import { decryptText } from "./decrypt.ts"; import { sha3_512 } from "@noble/hashes/sha3.js"; Deno.test({ name: "decrypts an encrypted value", fn() { const keys = generateKeys(); const text = "Hello, world!"; const encrypted = encryptText(keys.publicKey, text); const decrypted = decryptText(keys.secretKey, encrypted); expect(decrypted).toEqual(text); }, }); Deno.test({ name: "errors when provided an incorrect hash", fn() { const keys = generateKeys(); const text = "Hello, world!"; const encrypted = encryptText(keys.publicKey, text); encrypted.hash = sha3_512(new Uint8Array(24)).toBase64(); expect(() => decryptText(keys.secretKey, encrypted)).toThrow(); }, }); Deno.test({ name: "errors when provided an incorrect content length", fn() { const keys = generateKeys(); const text = "Hello, world!"; const encrypted = encryptText(keys.publicKey, text); encrypted.length = Math.round(Math.random() * 1000); expect(() => decryptText(keys.secretKey, encrypted)).toThrow(); }, });