diff --git a/test/private-box.test.ts b/test/private-box.test.ts index 7244432..77bde6c 100644 --- a/test/private-box.test.ts +++ b/test/private-box.test.ts @@ -36,6 +36,22 @@ test('Key generation', async () => { expect(k2.publicKey.extractable).toBeTrue() }) +test('Encrypt with context', async () => { + const context = 'Super context !' + const box = await PrivateBox.encrypt(message, k1.publicKey, context) + expect(box).not.toBeNull() + const unboxed = await box!.decrypt(k1.privateKey, context) + expect(unboxed).toEqual(message) +}) +test('Encrypt with different context', async () => { + const context1 = 'Super context !' + const context2 = 'Awesome context !' + const box = await PrivateBox.encrypt(message, k1.publicKey, context1) + expect(box).not.toBeNull() + const unboxed = await box!.decrypt(k1.privateKey, context2) + expect(unboxed).toBeNull() +}) + test('serialization', async () => { const box = await PrivateBox.encrypt(message, k1.publicKey) expect(box).not.toBeNull() diff --git a/test/private-wrap.test.ts b/test/private-wrap.test.ts index 8c9a47c..df16783 100644 --- a/test/private-wrap.test.ts +++ b/test/private-wrap.test.ts @@ -36,6 +36,22 @@ test('Key generation', async () => { expect(k2.publicKey.extractable).toBeTrue() }) +test("Encryption works with context", async () => { + const context = 'Super context !' + const box = await PrivateWrap.wrap(message, k1.publicKey, context) + expect(box).not.toBeNull() + const unboxed = await box!.unwrap(k1.privateKey, context) + expect(unboxed).not.toBeNull() +}) +test("Encryption doesn't work with different context", async () => { + const context1 = 'Super context !' + const context2 = 'Awesome context !' + const box = await PrivateWrap.wrap(message, k1.publicKey, context1) + expect(box).not.toBeNull() + const unboxed = await box!.unwrap(k1.privateKey, context2) + expect(unboxed).toBeNull() +}) + test('serialization', async () => { const box = await PrivateWrap.wrap(message, k1.publicKey) expect(box).not.toBeNull() diff --git a/test/pwd-box.test.ts b/test/pwd-box.test.ts index f7330df..e641f4f 100644 --- a/test/pwd-box.test.ts +++ b/test/pwd-box.test.ts @@ -23,6 +23,21 @@ test("Different key can't decrypt", async () => { const unboxed = await box!.decrypt(k2) expect(unboxed).toBeNull() }) +test("Encryption works with context", async () => { + const c1 = 'context1' + const box = await PwdBox.encrypt(message, k1, c1) + expect(box).not.toBeNull() + const unboxed = await box!.decrypt(k1, c1) + expect(unboxed).not.toBeNull() +}) +test("Encryption doesn't work with different context", async () => { + const c1 = 'context1' + const c2 = 'context2' + const box = await PwdBox.encrypt(message, k1, c1) + expect(box).not.toBeNull() + const unboxed = await box!.decrypt(k1, c2) + expect(unboxed).toBeNull() +}) test('serialization', async () => { const box = await PwdBox.encrypt(message, k1) diff --git a/test/pwd-wrap.test.ts b/test/pwd-wrap.test.ts index d569696..bcf840d 100644 --- a/test/pwd-wrap.test.ts +++ b/test/pwd-wrap.test.ts @@ -24,6 +24,23 @@ test("Different key can't decrypt", async () => { expect(unboxed).toBeNull() }) +test('Encryption works with context', async () => { + const context = 'awesome context !' + const box = await PwdWrap.wrap(message, k1, context) + expect(box).not.toBeNull() + const unboxed = await box!.unwrap(k1, context) + expect(unboxed).toEqual(message) +}) +test("Encryption doesn't work with different context", async () => { + const c1 = 'super context !' + const c2 = 'awesome context !' + const box = await PwdWrap.wrap(message, k1, c1) + expect(box).not.toBeNull() + const unboxed = await box!.unwrap(k1,c2) + expect(unboxed).toBeNull() + expect(unboxed).not.toEqual(message) +}) + test('serialization', async () => { const box = await PwdWrap.wrap(message, k1) expect(box).not.toBeNull() diff --git a/test/secret-box.test.ts b/test/secret-box.test.ts index 9789301..5ec111a 100644 --- a/test/secret-box.test.ts +++ b/test/secret-box.test.ts @@ -29,7 +29,7 @@ test('Key generation', async () => { expect(k2.extractable).toBeTrue() }) -test('serialization', async () => { +test('String serialization', async () => { const box = await SecretBox.encrypt(message, k1) expect(box).not.toBeNull() @@ -43,3 +43,18 @@ test('serialization', async () => { expect(unboxed).not.toBeNull() expect(unboxed).toEqual(message) }) + +test('Byte serialization', async () => { + const box = await SecretBox.encrypt(message, k1) + expect(box).not.toBeNull() + + const ser = box!.toBytes() + const de = SecretBox.fromBytes(ser) + + expect(de).not.toBeNull() + expect(de).toEqual(box) + + const unboxed = await de!.decrypt(k1) + expect(unboxed).not.toBeNull() + expect(unboxed).toEqual(message) +})