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 34ceec27208..378d79b579f 100644 --- a/src/rust-crypto/rust-crypto.ts +++ b/src/rust-crypto/rust-crypto.ts @@ -1649,7 +1649,7 @@ class EventDecryptor { } public async getEncryptionInfoForEvent(event: MatrixEvent): Promise { - if (!event.getClearContent()) { + if (!event.getClearContent() || event.isDecryptionFailure()) { // not successfully decrypted return null; }