crypto: Add some more accessors to the sas structs
This commit is contained in:
parent
1c8081533d
commit
71aba433da
4 changed files with 51 additions and 4 deletions
|
@ -15,6 +15,7 @@
|
|||
use matrix_sdk_base::crypto::{
|
||||
AcceptSettings, OutgoingVerificationRequest, ReadOnlyDevice, Sas as BaseSas,
|
||||
};
|
||||
use ruma::UserId;
|
||||
|
||||
use crate::{error::Result, Client};
|
||||
|
||||
|
@ -43,14 +44,19 @@ impl Sas {
|
|||
/// # use matrix_sdk::Client;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use url::Url;
|
||||
/// # use ruma::identifiers::user_id;
|
||||
/// use matrix_sdk::Sas;
|
||||
/// use matrix_sdk_base::crypto::AcceptSettings;
|
||||
/// use matrix_sdk::events::key::verification::ShortAuthenticationString;
|
||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
/// # let client = Client::new(homeserver).unwrap();
|
||||
/// # let flow_id = "someID";
|
||||
/// # let user_id = user_id!("@alice:example");
|
||||
/// # block_on(async {
|
||||
/// let sas = client.get_verification(flow_id).await.unwrap();
|
||||
/// let sas = client
|
||||
/// .get_verification(&user_id, flow_id)
|
||||
/// .await
|
||||
/// .unwrap();
|
||||
///
|
||||
/// let only_decimal = AcceptSettings::with_allowed_methods(
|
||||
/// vec![ShortAuthenticationString::Decimal]
|
||||
|
@ -141,4 +147,19 @@ impl Sas {
|
|||
pub fn other_device(&self) -> &ReadOnlyDevice {
|
||||
self.inner.other_device()
|
||||
}
|
||||
|
||||
/// Did this verification flow start from a verification request.
|
||||
pub fn started_from_request(&self) -> bool {
|
||||
self.inner.started_from_request()
|
||||
}
|
||||
|
||||
/// Is this a verification that is veryfying one of our own devices.
|
||||
pub fn is_self_verification(&self) -> bool {
|
||||
self.inner.is_self_verification()
|
||||
}
|
||||
|
||||
/// Get our own user id.
|
||||
pub fn own_user_id(&self) -> &UserId {
|
||||
self.inner.user_id()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -240,6 +240,10 @@ impl IdentitiesBeingVerified {
|
|||
self.private_identity.user_id()
|
||||
}
|
||||
|
||||
fn is_self_verification(&self) -> bool {
|
||||
self.user_id() == self.other_user_id()
|
||||
}
|
||||
|
||||
fn other_user_id(&self) -> &UserId {
|
||||
self.device_being_verified.user_id()
|
||||
}
|
||||
|
@ -370,8 +374,6 @@ impl IdentitiesBeingVerified {
|
|||
return Ok(None);
|
||||
}
|
||||
|
||||
// TODO signal an error, e.g. when the identity got deleted so we don't
|
||||
// verify/save the device either.
|
||||
let identity = self.store.get_user_identity(self.other_user_id()).await?;
|
||||
|
||||
if let Some(identity) = identity {
|
||||
|
|
|
@ -61,6 +61,20 @@ impl InnerSas {
|
|||
(InnerSas::Created(sas), content.into())
|
||||
}
|
||||
|
||||
pub fn started_from_request(&self) -> bool {
|
||||
match self {
|
||||
InnerSas::Created(s) => s.started_from_request,
|
||||
InnerSas::Started(s) => s.started_from_request,
|
||||
InnerSas::Accepted(s) => s.started_from_request,
|
||||
InnerSas::KeyReceived(s) => s.started_from_request,
|
||||
InnerSas::Confirmed(s) => s.started_from_request,
|
||||
InnerSas::MacReceived(s) => s.started_from_request,
|
||||
InnerSas::WaitingForDone(s) => s.started_from_request,
|
||||
InnerSas::Done(s) => s.started_from_request,
|
||||
InnerSas::Cancelled(s) => s.started_from_request,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn supports_emoji(&self) -> bool {
|
||||
match self {
|
||||
InnerSas::Created(_) => false,
|
||||
|
|
|
@ -49,8 +49,8 @@ use crate::{
|
|||
ReadOnlyAccount, ToDeviceRequest,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
/// Short authentication string object.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Sas {
|
||||
inner: Arc<Mutex<InnerSas>>,
|
||||
account: ReadOnlyAccount,
|
||||
|
@ -95,6 +95,16 @@ impl Sas {
|
|||
self.inner.lock().unwrap().supports_emoji()
|
||||
}
|
||||
|
||||
/// Did this verification flow start from a verification request.
|
||||
pub fn started_from_request(&self) -> bool {
|
||||
self.inner.lock().unwrap().started_from_request()
|
||||
}
|
||||
|
||||
/// Is this a verification that is veryfying one of our own devices.
|
||||
pub fn is_self_verification(&self) -> bool {
|
||||
self.identities_being_verified.is_self_verification()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn set_creation_time(&self, time: Instant) {
|
||||
|
|
Loading…
Reference in a new issue