You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
/* global libsignal, libloki, textsecure, StringView */
|
|
|
|
'use strict';
|
|
|
|
describe('Crypto', () => {
|
|
describe('FallBackSessionCipher', () => {
|
|
let fallbackCipher;
|
|
let identityKey;
|
|
let address;
|
|
const store = textsecure.storage.protocol;
|
|
|
|
before(async () => {
|
|
clearDatabase();
|
|
identityKey = await libsignal.KeyHelper.generateIdentityKeyPair();
|
|
store.put('identityKey', identityKey);
|
|
const key = libsignal.crypto.getRandomBytes(32);
|
|
const pubKeyString = StringView.arrayBufferToHex(key);
|
|
address = new libsignal.SignalProtocolAddress(pubKeyString, 1);
|
|
fallbackCipher = new libloki.crypto.FallBackSessionCipher(address);
|
|
});
|
|
|
|
it('should encrypt fallback cipher messages as friend requests', async () => {
|
|
const buffer = new ArrayBuffer(10);
|
|
const { type } = await fallbackCipher.encrypt(buffer);
|
|
assert.strictEqual(
|
|
type,
|
|
textsecure.protobuf.Envelope.Type.FRIEND_REQUEST
|
|
);
|
|
});
|
|
|
|
it('should encrypt and then decrypt a message with the same result', async () => {
|
|
const arr = new Uint8Array([1, 2, 3, 4, 5]);
|
|
const { body } = await fallbackCipher.encrypt(arr.buffer);
|
|
const result = await fallbackCipher.decrypt(body);
|
|
assert.deepEqual(result, arr.buffer);
|
|
});
|
|
});
|
|
});
|