feat: Serialise the Double Ratchet
This commit is contained in:
@@ -2,7 +2,7 @@ import 'package:omemo_dart/omemo_dart.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
test('Test serialising and deserialising Device', () async {
|
||||
test('Test serialising and deserialising the Device', () async {
|
||||
// Generate a random session
|
||||
final oldSession = await OmemoSessionManager.generateNewIdentity(opkAmount: 1);
|
||||
final oldDevice = await oldSession.getDevice();
|
||||
@@ -21,4 +21,50 @@ void main() {
|
||||
expect(await newDevice.opks[entry.key]!.equals(entry.value), true);
|
||||
}
|
||||
});
|
||||
|
||||
test('Test serialising and deserialising the OmemoDoubleRatchet', () async {
|
||||
// Generate a random ratchet
|
||||
const aliceJid = 'alice@server.example';
|
||||
const bobJid = 'bob@other.server.example';
|
||||
final aliceSession = await OmemoSessionManager.generateNewIdentity(opkAmount: 1);
|
||||
final bobSession = await OmemoSessionManager.generateNewIdentity(opkAmount: 1);
|
||||
final aliceMessage = await aliceSession.encryptToJid(
|
||||
bobJid,
|
||||
'Hello Bob!',
|
||||
newSessions: [
|
||||
await (await bobSession.getDevice()).toBundle(),
|
||||
],
|
||||
);
|
||||
await bobSession.decryptMessage(
|
||||
aliceMessage.ciphertext,
|
||||
aliceJid,
|
||||
(await aliceSession.getDevice()).id,
|
||||
aliceMessage.encryptedKeys,
|
||||
);
|
||||
final aliceOld = aliceSession.getRatchet((await bobSession.getDevice()).id);
|
||||
final aliceSerialised = await aliceOld.toJson();
|
||||
final aliceNew = OmemoDoubleRatchet.fromJson(aliceSerialised);
|
||||
|
||||
expect(await aliceOld.dhs.equals(aliceNew.dhs), true);
|
||||
if (aliceOld.dhr == null) {
|
||||
expect(aliceNew.dhr, null);
|
||||
} else {
|
||||
expect(await aliceOld.dhr!.equals(aliceNew.dhr!), true);
|
||||
}
|
||||
expect(listsEqual(aliceOld.rk, aliceNew.rk), true);
|
||||
if (aliceOld.cks == null) {
|
||||
expect(aliceNew.cks, null);
|
||||
} else {
|
||||
expect(listsEqual(aliceOld.cks!, aliceNew.cks!), true);
|
||||
}
|
||||
if (aliceOld.ckr == null) {
|
||||
expect(aliceNew.ckr, null);
|
||||
} else {
|
||||
expect(listsEqual(aliceOld.ckr!, aliceNew.ckr!), true);
|
||||
}
|
||||
expect(aliceOld.ns, aliceNew.ns);
|
||||
expect(aliceOld.nr, aliceNew.nr);
|
||||
expect(aliceOld.pn, aliceNew.pn);
|
||||
expect(listsEqual(aliceOld.sessionAd, aliceNew.sessionAd), true);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user