Remove buffer dependency.
This commit is contained in:
@@ -2,7 +2,7 @@ import { decrypt } from '../src/decrypt'
|
||||
|
||||
test('Test nonce parsing by public decrypt function.', () => {
|
||||
// Given
|
||||
const ciphertext = Buffer.from([
|
||||
const ciphertext = Uint8Array.from([
|
||||
// Nonce
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
// Ciphertext
|
||||
@@ -10,21 +10,21 @@ test('Test nonce parsing by public decrypt function.', () => {
|
||||
25, 202, 255, 201, 206, 49, 60, 58, 82, 216, 72, 116, 106, 129, 162, 142, 69, 40,
|
||||
167, 88, 94, 195, 174, 217, 242, 149, 224, 125, 196, 237, 172, 165, 116, 119, 128
|
||||
])
|
||||
const associatedData = Buffer.from('Some associated data.')
|
||||
const key = Buffer.from('\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f')
|
||||
const associatedData = new TextEncoder().encode('Some associated data.')
|
||||
const key = Uint8Array.from([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f])
|
||||
|
||||
// When
|
||||
const result = decrypt(ciphertext, associatedData, key)
|
||||
|
||||
// Then
|
||||
const expectedResult = Buffer.from('Hello, World! This is a test message.')
|
||||
const expectedResult = new TextEncoder().encode('Hello, World! This is a test message.')
|
||||
expect(result.success).toBe(true)
|
||||
expect(result.plaintext).toMatchObject(expectedResult)
|
||||
})
|
||||
|
||||
test('Test decryption with an invalid key.', () => {
|
||||
// Given
|
||||
const ciphertext = Buffer.from([
|
||||
const ciphertext = Uint8Array.from([
|
||||
// Nonce
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
// Ciphertext
|
||||
@@ -32,13 +32,13 @@ test('Test decryption with an invalid key.', () => {
|
||||
25, 202, 255, 201, 206, 49, 60, 58, 82, 216, 72, 116, 106, 129, 162, 142, 69, 40,
|
||||
167, 88, 94, 195, 174, 217, 242, 149, 224, 125, 196, 237, 172, 165, 116, 119, 128
|
||||
])
|
||||
const associatedData = Buffer.from('Some associated data.')
|
||||
const key = Buffer.from('\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x00')
|
||||
const associatedData = new TextEncoder().encode('Some associated data.')
|
||||
const key = Uint8Array.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
|
||||
|
||||
// When
|
||||
const result = decrypt(ciphertext, associatedData, key)
|
||||
|
||||
// Then
|
||||
expect(result.success).toBe(false)
|
||||
expect(result.plaintext).toMatchObject(Buffer.alloc(0))
|
||||
expect(result.plaintext).toMatchObject(new Uint8Array())
|
||||
})
|
||||
|
||||
@@ -3,9 +3,9 @@ import { encrypt } from '../src/encrypt'
|
||||
|
||||
test('Test nonce generation by public encrypt function.', () => {
|
||||
// Given
|
||||
const message = Buffer.from('Hello, World! This is a test message.')
|
||||
const associatedData = Buffer.from('Some associated data.')
|
||||
const key = Buffer.from('\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f')
|
||||
const message = new TextEncoder().encode('Hello, World! This is a test message.')
|
||||
const associatedData = new TextEncoder().encode('Some associated data.')
|
||||
const key = Uint8Array.from([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f])
|
||||
|
||||
// When
|
||||
const ciphertext = encrypt(message, associatedData, key)
|
||||
|
||||
Reference in New Issue
Block a user