crypto: Add some more accessors for the fields in the verification types
parent
b14d754aed
commit
cc0388929a
|
@ -57,14 +57,6 @@ pub enum Verification {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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.
|
/// Try to deconstruct this verification enum into a SAS verification.
|
||||||
pub fn sas_v1(self) -> Option<Sas> {
|
pub fn sas_v1(self) -> Option<Sas> {
|
||||||
if let Verification::SasV1(sas) = self {
|
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.
|
/// Get the ID that uniquely identifies this verification flow.
|
||||||
pub fn flow_id(&self) -> &str {
|
pub fn flow_id(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
|
|
|
@ -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
|
/// The id of the other user that is participating in this verification
|
||||||
/// request.
|
/// request.
|
||||||
pub fn other_user(&self) -> &UserId {
|
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)]
|
#[allow(clippy::unnecessary_wraps)]
|
||||||
pub(crate) fn receive_ready(&self, sender: &UserId, content: &ReadyContent) -> Result<(), ()> {
|
pub(crate) fn receive_ready(&self, sender: &UserId, content: &ReadyContent) -> Result<(), ()> {
|
||||||
let mut inner = self.inner.lock().unwrap();
|
let mut inner = self.inner.lock().unwrap();
|
||||||
|
|
Loading…
Reference in New Issue