Add byte serialization
This commit is contained in:
@@ -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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user