Add byte serialization
This commit is contained in:
+14
-1
@@ -1,6 +1,6 @@
|
||||
import {expect, test} from 'bun:test'
|
||||
import {PrivateBox, PrivateWrap, SecretBox, signature} from '..'
|
||||
import {pubkey_fromString, pubkey_toString, Usage} from '../src/misc'
|
||||
import {pubkey_fromBytes, pubkey_fromString, pubkey_toBytes, pubkey_toString, Usage} from '../src/misc'
|
||||
|
||||
test('Private box', async () => {
|
||||
const message = crypto.getRandomValues(new Uint8Array(8))
|
||||
@@ -48,3 +48,16 @@ test('Signature', async () => {
|
||||
const verification = await signature.verify(message, de!, signed!)
|
||||
expect(verification).toBeTrue()
|
||||
})
|
||||
test('Byte serialization', async () => {
|
||||
const k = await signature.gen(false)
|
||||
const message = crypto.getRandomValues(new Uint8Array(8))
|
||||
const signed = await signature.sign(message, k.privateKey)
|
||||
expect(signed).not.toBeNull()
|
||||
|
||||
const ser = await pubkey_toBytes(k.publicKey)
|
||||
const de = await pubkey_fromBytes(ser, Usage.sign)
|
||||
expect(de).not.toBeNull()
|
||||
|
||||
const verification = await signature.verify(message, de!, signed!)
|
||||
expect(verification).toBeTrue()
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
+15
-1
@@ -39,7 +39,7 @@ test("Encryption doesn't work with different context", async () => {
|
||||
expect(unboxed).toBeNull()
|
||||
})
|
||||
|
||||
test('serialization', async () => {
|
||||
test('String serialization', async () => {
|
||||
const box = await PwdBox.encrypt(message, k1)
|
||||
expect(box).not.toBeNull()
|
||||
|
||||
@@ -53,3 +53,17 @@ test('serialization', async () => {
|
||||
expect(unboxed).not.toBeNull()
|
||||
expect(unboxed).toEqual(message)
|
||||
})
|
||||
test('Byte serialization', async () => {
|
||||
const box = await PwdBox.encrypt(message, k1)
|
||||
expect(box).not.toBeNull()
|
||||
|
||||
const ser = box!.toBytes()
|
||||
const de = PwdBox.fromBytes(ser)
|
||||
|
||||
expect(de).not.toBeNull()
|
||||
expect(de).toEqual(box)
|
||||
|
||||
const unboxed = await de!.decrypt(k1)
|
||||
expect(unboxed).not.toBeNull()
|
||||
expect(unboxed).toEqual(message)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user