From f2711fc75ce828bcb02eacec80bf444439ee180b Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Thu, 7 Dec 2023 19:58:02 -0500 Subject: [PATCH 1/4] implement verification cancellation info in Rust crypto --- src/rust-crypto/verification.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/rust-crypto/verification.ts b/src/rust-crypto/verification.ts index bac4694441c..4206c106874 100644 --- a/src/rust-crypto/verification.ts +++ b/src/rust-crypto/verification.ts @@ -425,7 +425,7 @@ export class RustVerificationRequest * this verification. */ public get cancellationCode(): string | null { - throw new Error("not implemented"); + return this.inner.cancelInfo?.cancelCode().toString(); } /** @@ -434,7 +434,14 @@ export class RustVerificationRequest * Only defined when phase is Cancelled */ public get cancellingUserId(): string | undefined { - throw new Error("not implemented"); + const cancelInfo = this.inner.cancelInfo; + if (!cancelInfo) { + return undefined; + } else if (cancelInfo.cancelledbyUs()) { + return this.olmMachine.userId.toString(); + } else { + return this.inner.otherUserId.toString(); + } } } From c24f38fa1783862f361b2ee80e6c6698d7c7091c Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Thu, 7 Dec 2023 20:11:03 -0500 Subject: [PATCH 2/4] fix type info --- src/rust-crypto/verification.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/rust-crypto/verification.ts b/src/rust-crypto/verification.ts index 4206c106874..a4356755172 100644 --- a/src/rust-crypto/verification.ts +++ b/src/rust-crypto/verification.ts @@ -425,7 +425,12 @@ export class RustVerificationRequest * this verification. */ public get cancellationCode(): string | null { - return this.inner.cancelInfo?.cancelCode().toString(); + const cancelInfo = this.inner.cancelInfo; + if (cancelInfo) { + return cancelInfo.cancelCode().toString(); + } else { + return null; + } } /** From 7e3c5c5d293f7adb2241c2cccf58f30848557935 Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Tue, 12 Dec 2023 17:14:38 -0500 Subject: [PATCH 3/4] use string cancel code and add test --- spec/integ/crypto/verification.spec.ts | 2 ++ src/rust-crypto/verification.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/integ/crypto/verification.spec.ts b/spec/integ/crypto/verification.spec.ts index d95097fcfd8..3422220916a 100644 --- a/spec/integ/crypto/verification.spec.ts +++ b/spec/integ/crypto/verification.spec.ts @@ -743,6 +743,8 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st expect(toDeviceMessage.transaction_id).toEqual(transactionId); expect(toDeviceMessage.code).toEqual("m.user"); expect(request.phase).toEqual(VerificationPhase.Cancelled); + expect(request.cancellationCode).toEqual("m.user"); + expect(request.cancellingUserId).toEqual("@alice:localhost"); }); it("can cancel during the SAS phase", async () => { diff --git a/src/rust-crypto/verification.ts b/src/rust-crypto/verification.ts index a4356755172..c851111a0e5 100644 --- a/src/rust-crypto/verification.ts +++ b/src/rust-crypto/verification.ts @@ -427,7 +427,7 @@ export class RustVerificationRequest public get cancellationCode(): string | null { const cancelInfo = this.inner.cancelInfo; if (cancelInfo) { - return cancelInfo.cancelCode().toString(); + return cancelInfo.cancelCode(); } else { return null; } From a3b609714d2b6fd2f6a14ec6ae0da769ad74c8d0 Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Wed, 24 Jan 2024 22:32:03 -0500 Subject: [PATCH 4/4] simplify code Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> --- src/rust-crypto/verification.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/rust-crypto/verification.ts b/src/rust-crypto/verification.ts index ec4535ccf20..a8b733c5fe0 100644 --- a/src/rust-crypto/verification.ts +++ b/src/rust-crypto/verification.ts @@ -426,12 +426,7 @@ export class RustVerificationRequest * this verification. */ public get cancellationCode(): string | null { - const cancelInfo = this.inner.cancelInfo; - if (cancelInfo) { - return cancelInfo.cancelCode(); - } else { - return null; - } + return this.inner.cancelInfo?.cancelCode() ?? null; } /**