feat: Allow serialising and deserialising without the ratchets
This commit is contained in:
parent
f540a80ec2
commit
710b3c9497
@ -49,6 +49,17 @@ class OmemoSessionManager {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Deserialise the OmemoSessionManager from JSON data [data] that does not contain
|
||||||
|
/// the ratchet sessions.
|
||||||
|
factory OmemoSessionManager.fromJsonWithoutSessions(Map<String, dynamic> data, Map<RatchetMapKey, OmemoDoubleRatchet> ratchetMap, TrustManager trustManager) {
|
||||||
|
return OmemoSessionManager(
|
||||||
|
Device.fromJson(data['device']! as Map<String, dynamic>),
|
||||||
|
data['devices']! as Map<String, List<int>>,
|
||||||
|
ratchetMap,
|
||||||
|
trustManager,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Generate a new cryptographic identity.
|
/// Generate a new cryptographic identity.
|
||||||
static Future<OmemoSessionManager> generateNewIdentity(String jid, TrustManager trustManager, { int opkAmount = 100 }) async {
|
static Future<OmemoSessionManager> generateNewIdentity(String jid, TrustManager trustManager, { int opkAmount = 100 }) async {
|
||||||
assert(opkAmount > 0, 'opkAmount must be bigger than 0.');
|
assert(opkAmount > 0, 'opkAmount must be bigger than 0.');
|
||||||
@ -439,4 +450,23 @@ class OmemoSessionManager {
|
|||||||
'sessions': sessions,
|
'sessions': sessions,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Serialise the entire session manager into a JSON object.
|
||||||
|
Future<Map<String, dynamic>> toJsonWithoutSessions() async {
|
||||||
|
/*
|
||||||
|
{
|
||||||
|
'devices': {
|
||||||
|
'alice@...': [1, 2, ...],
|
||||||
|
'bob@...': [1],
|
||||||
|
...
|
||||||
|
},
|
||||||
|
'device': { ... },
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
return {
|
||||||
|
'devices': _deviceMap,
|
||||||
|
'device': await (await getDevice()).toJson(),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user