From 4919f028c884a041da7ff098abb02389b4eac598 Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Tue, 18 Apr 2023 03:02:17 +0800 Subject: ✨add envshare docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- envshare/pkg/encoding.test.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 envshare/pkg/encoding.test.ts (limited to 'envshare/pkg/encoding.test.ts') diff --git a/envshare/pkg/encoding.test.ts b/envshare/pkg/encoding.test.ts new file mode 100644 index 0000000..be0a7f8 --- /dev/null +++ b/envshare/pkg/encoding.test.ts @@ -0,0 +1,23 @@ +import { describe, it, expect, beforeAll } from "@jest/globals"; +import { decodeCompositeKey, encodeCompositeKey } from "./encoding"; +import { generateKey } from "./encryption"; +import { generateId } from "./id"; +import crypto from "node:crypto"; + +beforeAll(() => { + global.crypto = crypto.webcrypto; +}); +describe("composite key encoding", () => { + it("encodes and decodes composite keys", async () => { + for (let i = 0; i < 10000; i++) { + const id = generateId(); + const key = new Uint8Array(await crypto.subtle.exportKey("raw", await generateKey())); + + const encoded = encodeCompositeKey(1, id, key); + + const decoded = decodeCompositeKey(encoded); + expect(decoded.id).toEqual(id); + expect(decoded.encryptionKey).toEqual(key); + } + }); +}); -- cgit v1.2.3-70-g09d2