From e18c59643e9a811bca6f655f6ae5cf85a331789e Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 20 Oct 2023 18:29:38 +0100 Subject: [PATCH] Element-R: silence log errors when viewing a decryption failure --- spec/unit/rust-crypto/rust-crypto.spec.ts | 20 ++++++++++++++++++++ src/rust-crypto/rust-crypto.ts | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/spec/unit/rust-crypto/rust-crypto.spec.ts b/spec/unit/rust-crypto/rust-crypto.spec.ts index e7cbdb2c659..d8eae7f4d48 100644 --- a/spec/unit/rust-crypto/rust-crypto.spec.ts +++ b/spec/unit/rust-crypto/rust-crypto.spec.ts @@ -505,6 +505,26 @@ describe("RustCrypto", () => { expect(olmMachine.getRoomEventEncryptionInfo).not.toHaveBeenCalled(); }); + it("should handle decryption failures", async () => { + const event = mkEvent({ + event: true, + type: "m.room.encrypted", + content: { algorithm: "fake_alg" }, + room: "!room:id", + }); + event.event.event_id = "$event:id"; + const mockCryptoBackend = { + decryptEvent: () => { + throw new Error("UISI"); + }, + }; + await event.attemptDecryption(mockCryptoBackend as unknown as CryptoBackend); + + const res = await rustCrypto.getEncryptionInfoForEvent(event); + expect(res).toBe(null); + expect(olmMachine.getRoomEventEncryptionInfo).not.toHaveBeenCalled(); + }); + it("passes the event into the OlmMachine", async () => { const encryptedEvent = await makeEncryptedEvent(); const res = await rustCrypto.getEncryptionInfoForEvent(encryptedEvent); diff --git a/src/rust-crypto/rust-crypto.ts b/src/rust-crypto/rust-crypto.ts index cc7dc3bfda8..371b2c7218d 100644 --- a/src/rust-crypto/rust-crypto.ts +++ b/src/rust-crypto/rust-crypto.ts @@ -1650,7 +1650,7 @@ class EventDecryptor { } public async getEncryptionInfoForEvent(event: MatrixEvent): Promise { - if (!event.getClearContent()) { + if (!event.getClearContent() || event.isDecryptionFailure()) { // not successfully decrypted return null; }