feat: Remove toJson and fromJson from OmemoSessionManager
This commit is contained in:
		
							parent
							
								
									cf5331a026
								
							
						
					
					
						commit
						49c847a96b
					
				| @ -35,23 +35,6 @@ class OmemoSessionManager { | ||||
|       _eventStreamController = StreamController<OmemoEvent>.broadcast(), | ||||
|       _log = Logger('OmemoSessionManager'); | ||||
| 
 | ||||
|   /// Deserialise the OmemoSessionManager from JSON data [data]. | ||||
|   factory OmemoSessionManager.fromJson(Map<String, dynamic> data, TrustManager trustManager) { | ||||
|     final ratchetMap = <RatchetMapKey, OmemoDoubleRatchet>{}; | ||||
|     for (final rawRatchet in data['sessions']! as List<Map<String, dynamic>>) { | ||||
|       final key = RatchetMapKey(rawRatchet['jid']! as String, rawRatchet['deviceId']! as int); | ||||
|       final ratchet = OmemoDoubleRatchet.fromJson(rawRatchet['ratchet']! as Map<String, dynamic>); | ||||
|       ratchetMap[key] = ratchet; | ||||
|     } | ||||
| 
 | ||||
|     return OmemoSessionManager( | ||||
|       Device.fromJson(data['device']! as Map<String, dynamic>), | ||||
|       data['devices']! as Map<String, List<int>>, | ||||
|       ratchetMap, | ||||
|       trustManager, | ||||
|     ); | ||||
|   } | ||||
| 
 | ||||
|   /// 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) { | ||||
| @ -566,42 +549,6 @@ class OmemoSessionManager { | ||||
|   @visibleForTesting | ||||
|   Map<RatchetMapKey, OmemoDoubleRatchet> getRatchetMap() => _ratchetMap; | ||||
| 
 | ||||
|   /// Serialise the entire session manager into a JSON object. | ||||
|   Future<Map<String, dynamic>> toJson() async { | ||||
|     /* | ||||
|     { | ||||
|       'devices': { | ||||
|         'alice@...': [1, 2, ...], | ||||
|         'bob@...': [1], | ||||
|         ... | ||||
|       }, | ||||
|       'device': { ... }, | ||||
|       'sessions': [ | ||||
|         { | ||||
|           'jid': 'alice@...', | ||||
|           'deviceId': 1, | ||||
|           'ratchet': { ... }, | ||||
|         }, | ||||
|         ... | ||||
|       ], | ||||
|     } | ||||
|     */ | ||||
| 
 | ||||
|     final sessions = List<Map<String, dynamic>>.empty(growable: true); | ||||
|     for (final entry in _ratchetMap.entries) { | ||||
|       sessions.add({ | ||||
|         'jid': entry.key.jid, | ||||
|         'deviceId': entry.key.deviceId, | ||||
|         'ratchet': await entry.value.toJson(), | ||||
|       }); | ||||
|     } | ||||
|     return { | ||||
|       'devices': _deviceMap, | ||||
|       'device': await (await getDevice()).toJson(), | ||||
|       'sessions': sessions, | ||||
|     }; | ||||
|   } | ||||
| 
 | ||||
|   /// Serialise the entire session manager into a JSON object. | ||||
|   Future<Map<String, dynamic>> toJsonWithoutSessions() async { | ||||
|     /* | ||||
|  | ||||
| @ -85,9 +85,11 @@ void main() { | ||||
|     ); | ||||
| 
 | ||||
|     // Serialise and deserialise | ||||
|     final serialised = await oldSession.toJson(); | ||||
|     final newSession = OmemoSessionManager.fromJson( | ||||
|     final serialised = await oldSession.toJsonWithoutSessions(); | ||||
|     final newSession = OmemoSessionManager.fromJsonWithoutSessions( | ||||
|       serialised, | ||||
|       // NOTE: At this point, we don't care about this attribute | ||||
|       {}, | ||||
|       AlwaysTrustingTrustManager(), | ||||
|     ); | ||||
| 
 | ||||
| @ -95,15 +97,6 @@ void main() { | ||||
|     final newDevice = await newSession.getDevice(); | ||||
|     expect(await oldDevice.equals(newDevice), true); | ||||
|     expect(await oldSession.getDeviceMap(), await newSession.getDeviceMap()); | ||||
| 
 | ||||
|     expect(oldSession.getRatchetMap().length, newSession.getRatchetMap().length); | ||||
|     for (final session in oldSession.getRatchetMap().entries) { | ||||
|       expect(newSession.getRatchetMap().containsKey(session.key), true); | ||||
| 
 | ||||
|       final oldRatchet = oldSession.getRatchetMap()[session.key]!; | ||||
|       final newRatchet = newSession.getRatchetMap()[session.key]!; | ||||
|       expect(await oldRatchet.equals(newRatchet), true); | ||||
|     } | ||||
|   }); | ||||
| 
 | ||||
|   test('Test serialising and deserialising the BlindTrustBeforeVerificationTrustManager', () async { | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user