Return ciphertext rather than decrypted content

This commit is contained in:
Jack Hadrill
2022-03-18 15:56:33 +00:00
parent 5c17b880cf
commit be39f7bae1
8 changed files with 11400 additions and 92 deletions

View File

@@ -1,15 +1,16 @@
import { MessageTypes } from '../../src/common'
import { packers, unpackers } from '../../src/mapping'
const KEY = new Uint8Array([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F])
const KEY = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
test('Create a basic message (0x0001) packet.', () => {
// Given
const message = 'Hello, World!'
const encoder = new TextEncoder()
const message = encoder.encode('Hello, World!')
// When
const packedPacket = packers[MessageTypes.Basic](
{ message: message },
message,
KEY
)
@@ -24,16 +25,12 @@ test('Create a basic message (0x0001) packet.', () => {
test('Parse a basic message (0x0001).', () => {
// Given
const ciphertext = new Uint8Array([
0x84, 0xa2, 0x3a, 0xe2, 0xa8, 0xff, 0x43, 0x56, 0x96, 0x94, 0xf6, 0xe5, 0x1a, 0x30, 0x53,
0x39, 0xb9, 0xc4, 0x2c, 0xab, 0x21, 0x52, 0x8f, 0xc2, 0xba, 0x6c, 0x8b, 0x96, 0x82, 0x9d,
0x51, 0x27, 0x0c, 0xb6, 0x3b, 0x7f, 0x3e, 0x2a, 0x7b, 0x70, 0xbe, 0x01, 0x7b, 0x71, 0x9d
])
const data = new Uint8Array([1, 2, 3, 4])
// When
const unpackedPacket = unpackers[MessageTypes.Basic](ciphertext, KEY)
const unpackedPacket = unpackers[MessageTypes.Basic](data)
// Then
expect(unpackedPacket.success).toBe(true)
expect(unpackedPacket.message).toBe('Hello, World!')
expect(unpackedPacket)
expect(unpackedPacket).toMatchObject(data)
})