From 5e2acb558b40059c833e0a094bd28236790c544b Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Wed, 24 Jan 2024 22:43:50 -0500 Subject: [PATCH] Implement getting verification cancellation info in Rust crypto (#3947) * implement verification cancellation info in Rust crypto * fix type info * use string cancel code and add test * simplify code Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> --------- Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> --- spec/integ/crypto/verification.spec.ts | 2 ++ src/rust-crypto/verification.ts | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/spec/integ/crypto/verification.spec.ts b/spec/integ/crypto/verification.spec.ts index 243fd510d58..ae9ebcd5961 100644 --- a/spec/integ/crypto/verification.spec.ts +++ b/spec/integ/crypto/verification.spec.ts @@ -744,6 +744,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 cca1b4aa6b4..a8b733c5fe0 100644 --- a/src/rust-crypto/verification.ts +++ b/src/rust-crypto/verification.ts @@ -426,7 +426,7 @@ export class RustVerificationRequest * this verification. */ public get cancellationCode(): string | null { - throw new Error("not implemented"); + return this.inner.cancelInfo?.cancelCode() ?? null; } /** @@ -435,7 +435,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(); + } } }