import { expect } from "@std/expect"; import { generateKeys } from "./keys.ts"; import { encryptText } from "./encrypt.ts"; import { decryptText } from "./decrypt.ts"; Deno.test({ name: "encrypts and decrypts multiple messages with the same keypair", fn() { const keys = generateKeys(); const text1 = "First message"; const text2 = "Second message"; const text3 = "Third message"; const encrypted1 = encryptText(keys.publicKey, text1); const encrypted2 = encryptText(keys.publicKey, text2); const encrypted3 = encryptText(keys.publicKey, text3); expect(encrypted1.content.length).toBeGreaterThan(0); expect(encrypted2.content.length).toBeGreaterThan(0); expect(encrypted3.content.length).toBeGreaterThan(0); const decrypted1 = decryptText(keys.secretKey, encrypted1); const decrypted2 = decryptText(keys.secretKey, encrypted2); const decrypted3 = decryptText(keys.secretKey, encrypted3); expect(decrypted1).toEqual(text1); expect(decrypted2).toEqual(text2); expect(decrypted3).toEqual(text3); }, }); Deno.test({ name: "encrypts messages with reused public key reference", fn() { const keys = generateKeys(); const publicKey = keys.publicKey; const encrypted1 = encryptText(publicKey, "Message 1"); const encrypted2 = encryptText(publicKey, "Message 2"); const encrypted3 = encryptText(publicKey, "Message 3"); expect(encrypted1.cipherText).not.toEqual(encrypted2.cipherText); expect(encrypted2.cipherText).not.toEqual(encrypted3.cipherText); expect(encrypted1.cipherText).not.toEqual(encrypted3.cipherText); expect(decryptText(keys.secretKey, encrypted1)).toEqual("Message 1"); expect(decryptText(keys.secretKey, encrypted2)).toEqual("Message 2"); expect(decryptText(keys.secretKey, encrypted3)).toEqual("Message 3"); }, });