This commit is contained in:
Bruno Windels 2022-02-17 17:55:51 +01:00
parent e3e90ed167
commit c114eab26d

View file

@ -15,35 +15,31 @@ limitations under the License.
*/ */
import {DecryptionError} from "../../common.js"; import {DecryptionError} from "../../common.js";
import type {DecryptionResult} from "../../DecryptionResult";
import type {ReplayDetectionEntry} from "./ReplayDetectionEntry";
export class DecryptionChanges { export class DecryptionChanges {
constructor(roomId, results, errors, replayEntries) { constructor(
this._roomId = roomId; private readonly roomId: string,
this._results = results; private readonly results: Map<string, DecryptionResult>,
this._errors = errors; private readonly errors: Map<string, Error> | undefined,
this._replayEntries = replayEntries; private readonly replayEntries: ReplayDetectionEntry[]
} ) {}
/** /**
* @type MegolmBatchDecryptionResult
* @property {Map<string, DecryptionResult>} results a map of event id to decryption result
* @property {Map<string, Error>} errors event id -> errors
*
* Handle replay attack detection, and return result * Handle replay attack detection, and return result
* @param {[type]} txn [description]
* @return {MegolmBatchDecryptionResult}
*/ */
async write(txn) { async write(txn): Promise<{results: Map<string, DecryptionResult>, errors: Map<string, Error>}> {
await Promise.all(this._replayEntries.map(async replayEntry => { await Promise.all(this.replayEntries.map(async replayEntry => {
try { try {
this._handleReplayAttack(this._roomId, replayEntry, txn); this._handleReplayAttack(this.roomId, replayEntry, txn);
} catch (err) { } catch (err) {
this._errors.set(replayEntry.eventId, err); this.errors.set(replayEntry.eventId, err);
} }
})); }));
return { return {
results: this._results, results: this.results,
errors: this._errors errors: this.errors
}; };
} }