Merge branch 'client-enhance-error-handling' into 'master'

[Client] Enhanced error handling in decryptToDeviceEvent

See merge request famedly/famedlysdk!242
This commit is contained in:
Christian Pauly 2020-03-23 07:55:40 +00:00
commit 7146be2ca9
1 changed files with 6 additions and 1 deletions

View File

@ -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");