Skip to content

Commit 1faf4a0

Browse files
committed
add test
1 parent bd278d1 commit 1faf4a0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

test/encrypt&decrypt.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ describe("Functions: encrypt & decrypt", () => {
2828
});
2929

3030
describe("encrypt", () => {
31+
it("should encrypt message with encOpts undefined", async () => {
32+
const enc = await eccrypto.encrypt(publicKey, Buffer.from("test"));
33+
expect(enc.iv).toBeDefined();
34+
expect(enc.ephemPublicKey).toBeDefined();
35+
expect(enc.ciphertext).toBeDefined();
36+
expect(enc.mac).toBeDefined();
37+
});
38+
3139
it("should encrypt message when let encOpts empty", async () => {
3240
const enc = await eccrypto.encrypt(publicKey, Buffer.from("test"), {});
3341
expect(enc.iv).toBeDefined();
@@ -44,6 +52,15 @@ describe("Functions: encrypt & decrypt", () => {
4452
expect(Buffer.compare(enc.mac, mac)).toBe(0);
4553
});
4654

55+
it("should encrypt with padding", async () => {
56+
const encOptsLocal = { ...encOpts, padding: true };
57+
const enc = await eccrypto.encrypt(publicKey, Buffer.from("test"), encOptsLocal);
58+
expect(Buffer.compare(enc.iv, iv)).toBe(0);
59+
expect(Buffer.compare(enc.ephemPublicKey, ephemPublicKey)).toBe(0);
60+
expect(Buffer.compare(enc.ciphertext, ciphertext)).toBe(0);
61+
expect(Buffer.compare(enc.mac, mac)).toBe(0);
62+
});
63+
4764
it("should encrypt with compressed public key", async () => {
4865
const enc = await eccrypto.encrypt(publicKeyCompressed, Buffer.from("test"), encOpts);
4966
expect(Buffer.compare(enc.iv, iv)).toBe(0);

0 commit comments

Comments
 (0)