Skip to content

Commit

Permalink
Implement getting verification cancellation info in Rust crypto (#3947)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

---------

Co-authored-by: Richard van der Hoff <[email protected]>
  • Loading branch information
uhoreg and richvdh authored Jan 25, 2024
1 parent 19494e0 commit 5e2acb5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions spec/integ/crypto/verification.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
11 changes: 9 additions & 2 deletions src/rust-crypto/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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();
}
}
}

Expand Down

0 comments on commit 5e2acb5

Please sign in to comment.