From 2ddb3fbf72a09dc61bedc6b133621e7b9a7f1179 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 22 Oct 2021 17:45:55 +0200 Subject: [PATCH] cleanup --- .../e2ee/megolm/decryption/KeyLoader.ts | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src/matrix/e2ee/megolm/decryption/KeyLoader.ts b/src/matrix/e2ee/megolm/decryption/KeyLoader.ts index bde3065f..d1741f30 100644 --- a/src/matrix/e2ee/megolm/decryption/KeyLoader.ts +++ b/src/matrix/e2ee/megolm/decryption/KeyLoader.ts @@ -14,10 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {SessionCache} from "./SessionCache"; import {IRoomKey, isBetterThan} from "./RoomKey"; import {BaseLRUCache} from "../../../../utils/LRUCache"; + +export declare class OlmDecryptionResult { + readonly plaintext: string; + readonly message_index: number; +} + export declare class OlmInboundGroupSession { constructor(); free(): void; @@ -25,34 +30,18 @@ export declare class OlmInboundGroupSession { unpickle(key: string | Uint8Array, pickle: string); create(session_key: string): string; import_session(session_key: string): string; - decrypt(message: string): object; + decrypt(message: string): OlmDecryptionResult; session_id(): string; first_known_index(): number; export_session(message_index: number): string; } -// this is what cache.get(...) should return -function findIndexBestForSession(ops: KeyOperation[], roomId: string, senderKey: string, sessionId: string): number { - return ops.reduce((bestIdx, op, i, arr) => { - const bestOp = bestIdx === -1 ? undefined : arr[bestIdx]; - if (op.isForSameSession(roomId, senderKey, sessionId)) { - if (!bestOp || op.isBetter(bestOp)) { - return i; - } - } - return bestIdx; - }, -1); -} - - /* Because Olm only has very limited memory available when compiled to wasm, we limit the amount of sessions held in memory. */ export class KeyLoader extends BaseLRUCache { - private runningOps: Set; - private unusedOps: Set; private pickleKey: string; private olm: any; private resolveUnusedOperation?: () => void;