Test contexts

This commit is contained in:
2024-09-14 14:24:53 +02:00
parent 76cf4632e4
commit f2f39fd318
5 changed files with 80 additions and 1 deletions
+16 -1
View File
@@ -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)
})