From 048b7faba04a0016f1c836481de36e97af348314 Mon Sep 17 00:00:00 2001 From: Krille Fear Date: Wed, 10 Nov 2021 09:19:40 +0100 Subject: [PATCH] fix: JSON parsing in decryptRoomEvent method This makes the use of the event content null safe and type safe which fixes a regression when sessionId is null. --- lib/encryption/encryption.dart | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/encryption/encryption.dart b/lib/encryption/encryption.dart index 5df41a8d..b40a4d76 100644 --- a/lib/encryption/encryption.dart +++ b/lib/encryption/encryption.dart @@ -285,21 +285,34 @@ class Encryption { if (event.type != EventTypes.Encrypted) { return event; } + final content = event.parsedRoomEncryptedContent; + final sessionId = content.sessionId; try { if (client.database != null && + sessionId != null && !(keyManager - .getInboundGroupSession(roomId, event.content['session_id'], - event.content['sender_key']) + .getInboundGroupSession( + roomId, + sessionId, + content.senderKey, + ) ?.isValid ?? false)) { await keyManager.loadInboundGroupSession( - roomId, event.content['session_id'], event.content['sender_key']); + roomId, + sessionId, + content.senderKey, + ); } event = decryptRoomEventSync(roomId, event); if (event.type == EventTypes.Encrypted && - event.content['can_request_session'] == true) { + event.content['can_request_session'] == true && + sessionId != null) { keyManager.maybeAutoRequest( - roomId, event.content['session_id'], event.content['sender_key']); + roomId, + sessionId, + content.senderKey, + ); } if (event.type != EventTypes.Encrypted && store) { if (updateType != EventUpdateType.history) {