crypto: Allow Sas objects to be canceled.

master
Damir Jelić 2020-07-29 13:53:33 +02:00
parent 2b124d98bc
commit a726ebab39
1 changed files with 30 additions and 0 deletions

View File

@ -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<ToDeviceRequest> {
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<AnyToDeviceEventContent>) {
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<MacEventContent>) {
match self {
InnerSas::KeyRecieved(s) => {