Add byte serialization

This commit is contained in:
2024-09-14 15:05:07 +02:00
parent f2f39fd318
commit dc66f8ee73
7 changed files with 135 additions and 7 deletions
+15 -1
View File
@@ -52,7 +52,7 @@ test('Encrypt with different context', async () => {
expect(unboxed).toBeNull()
})
test('serialization', async () => {
test('String serialization', async () => {
const box = await PrivateBox.encrypt(message, k1.publicKey)
expect(box).not.toBeNull()
@@ -66,3 +66,17 @@ test('serialization', async () => {
expect(unboxed).not.toBeNull()
expect(unboxed).toEqual(message)
})
test('Byte serialization', async () => {
const box = await PrivateBox.encrypt(message, k1.publicKey)
expect(box).not.toBeNull()
const ser = await box!.toBytes()
const de = await PrivateBox.fromBytes(ser)
expect(de).not.toBeNull()
expect(de).toEqual(box)
const unboxed = await de!.decrypt(k1.privateKey)
expect(unboxed).not.toBeNull()
expect(unboxed).toEqual(message)
})