diff --git a/matrix_sdk_crypto/src/verification/sas.rs b/matrix_sdk_crypto/src/verification/sas.rs index 28cdf4e5..ad82dd3e 100644 --- a/matrix_sdk_crypto/src/verification/sas.rs +++ b/matrix_sdk_crypto/src/verification/sas.rs @@ -165,6 +165,21 @@ impl Sas { }) } + /// Cancel the verification. + /// + /// This cancels the verification with the `CancelCode::User`. + /// + /// Returns None if the `Sas` object is already in a canceled state, + /// otherwise it returns a request that needs to be sent out. + pub fn cancel(&self) -> Option { + let mut guard = self.inner.lock().unwrap(); + let sas: InnerSas = (*guard).clone(); + let (sas, content) = sas.cancel(); + *guard = sas; + + content.map(|c| self.content_to_request(c)) + } + /// Are we in a state where we can show the short auth string. pub fn can_be_presented(&self) -> bool { self.inner.lock().unwrap().can_be_presented() @@ -251,6 +266,21 @@ impl InnerSas { } } + fn cancel(self) -> (InnerSas, Option) { + let sas = match self { + InnerSas::Created(s) => s.cancel(CancelCode::User), + InnerSas::Started(s) => s.cancel(CancelCode::User), + InnerSas::Accepted(s) => s.cancel(CancelCode::User), + InnerSas::KeyRecieved(s) => s.cancel(CancelCode::User), + InnerSas::MacReceived(s) => s.cancel(CancelCode::User), + _ => return (self, None), + }; + + let content = sas.as_content(); + + (InnerSas::Canceled(sas), Some(content)) + } + fn confirm(self) -> (InnerSas, Option) { match self { InnerSas::KeyRecieved(s) => {