convert DecryptionResult

This commit is contained in:
Bruno Windels 2022-02-15 18:19:49 +01:00
parent dea1e7eaf3
commit 7aeda70ff6
2 changed files with 26 additions and 20 deletions

View file

@ -26,35 +26,41 @@ limitations under the License.
* see DeviceTracker * see DeviceTracker
*/ */
import type {DeviceIdentity} from "../storage/idb/stores/DeviceIdentityStore";
type DecryptedEvent = {
type?: string,
content?: Record<string, any>
}
export class DecryptionResult { export class DecryptionResult {
constructor(event, senderCurve25519Key, claimedEd25519Key) { private device?: DeviceIdentity;
this.event = event; private roomTracked: boolean = true;
this.senderCurve25519Key = senderCurve25519Key;
this.claimedEd25519Key = claimedEd25519Key; constructor(
this._device = null; public readonly event: DecryptedEvent,
this._roomTracked = true; public readonly senderCurve25519Key: string,
public readonly claimedEd25519Key: string
) {}
setDevice(device: DeviceIdentity) {
this.device = device;
} }
setDevice(device) { setRoomNotTrackedYet(): void {
this._device = device; this.roomTracked = false;
} }
setRoomNotTrackedYet() { get isVerified(): boolean {
this._roomTracked = false; if (this.device) {
} const comesFromDevice = this.device.ed25519Key === this.claimedEd25519Key;
get isVerified() {
if (this._device) {
const comesFromDevice = this._device.ed25519Key === this.claimedEd25519Key;
return comesFromDevice; return comesFromDevice;
} }
return false; return false;
} }
get isUnverified() { get isUnverified(): boolean {
if (this._device) { if (this.device) {
return !this.isVerified; return !this.isVerified;
} else if (this.isVerificationUnknown) { } else if (this.isVerificationUnknown) {
return false; return false;
@ -63,8 +69,8 @@ export class DecryptionResult {
} }
} }
get isVerificationUnknown() { get isVerificationUnknown(): boolean {
// verification is unknown if we haven't yet fetched the devices for the room // verification is unknown if we haven't yet fetched the devices for the room
return !this._device && !this._roomTracked; return !this.device && !this.roomTracked;
} }
} }

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import {DecryptionResult} from "../../DecryptionResult.js"; import {DecryptionResult} from "../../DecryptionResult";
import {DecryptionError} from "../../common.js"; import {DecryptionError} from "../../common.js";
import {ReplayDetectionEntry} from "./ReplayDetectionEntry"; import {ReplayDetectionEntry} from "./ReplayDetectionEntry";
import type {RoomKey} from "./RoomKey"; import type {RoomKey} from "./RoomKey";