crypto: Add some more accessors for the fields in the verification types

master
Damir Jelić 2021-06-10 16:23:16 +02:00
parent b14d754aed
commit cc0388929a
2 changed files with 34 additions and 8 deletions

View File

@ -57,14 +57,6 @@ pub enum Verification {
}
impl Verification {
/// Has this verification finished.
pub fn is_done(&self) -> bool {
match self {
Verification::SasV1(s) => s.is_done(),
Verification::QrV1(qr) => qr.is_done(),
}
}
/// Try to deconstruct this verification enum into a SAS verification.
pub fn sas_v1(self) -> Option<Sas> {
if let Verification::SasV1(sas) = self {
@ -83,6 +75,14 @@ impl Verification {
}
}
/// Has this verification finished.
pub fn is_done(&self) -> bool {
match self {
Verification::SasV1(s) => s.is_done(),
Verification::QrV1(qr) => qr.is_done(),
}
}
/// Get the ID that uniquely identifies this verification flow.
pub fn flow_id(&self) -> &str {
match self {

View File

@ -166,6 +166,11 @@ impl VerificationRequest {
)
}
/// Our own user id.
pub fn own_user_id(&self) -> &UserId {
self.account.user_id()
}
/// The id of the other user that is participating in this verification
/// request.
pub fn other_user(&self) -> &UserId {
@ -275,6 +280,27 @@ impl VerificationRequest {
})
}
/// Cancel the verification request
pub fn cancel(&self) -> Option<OutgoingVerificationRequest> {
let mut inner = self.inner.lock().unwrap();
inner.cancel(&CancelCode::User);
let content = if let InnerRequest::Cancelled(c) = &*inner {
Some(c.state.as_content(self.flow_id()))
} else {
None
};
content.map(|c| match c {
OutgoingContent::ToDevice(content) => {
ToDeviceRequest::new(&self.other_user(), inner.other_device_id(), content).into()
}
OutgoingContent::Room(room_id, content) => {
RoomMessageRequest { room_id, txn_id: Uuid::new_v4(), content }.into()
}
})
}
#[allow(clippy::unnecessary_wraps)]
pub(crate) fn receive_ready(&self, sender: &UserId, content: &ReadyContent) -> Result<(), ()> {
let mut inner = self.inner.lock().unwrap();