From e9c0ec851140b76b828fe4050202d8c559a8910c Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Mon, 23 Mar 2020 08:51:14 +0100 Subject: [PATCH] [Client] Enhanced error handling in decryptToDeviceEvent --- lib/src/client.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index c8d752e..e463e5d 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -1603,8 +1603,13 @@ class Client { /// Try to decrypt a ToDeviceEvent encrypted with olm. ToDeviceEvent decryptToDeviceEvent(ToDeviceEvent toDeviceEvent) { + if (toDeviceEvent.type != "m.room.encrypted") { + print( + "[LibOlm] Warning! Tried to decrypt a not-encrypted to-device-event"); + return toDeviceEvent; + } if (toDeviceEvent.content["algorithm"] != "m.olm.v1.curve25519-aes-sha2") { - throw ("Unknown algorithm: ${toDeviceEvent.content["algorithm"]}"); + throw ("Unknown algorithm: ${toDeviceEvent.content}"); } if (!toDeviceEvent.content["ciphertext"].containsKey(identityKey)) { throw ("The message isn't sent for this device");