pub struct SasVerification { /* private fields */ }
e2e-encryption
only.Expand description
An object controlling the short auth string verification flow.
Implementations§
Source§impl SasVerification
impl SasVerification
Sourcepub async fn accept_with_settings(&self, settings: AcceptSettings) -> Result<()>
pub async fn accept_with_settings(&self, settings: AcceptSettings) -> Result<()>
Accept the interactive verification flow with specific settings.
§Arguments
settings
- specific customizations to the verification flow.
§Examples
use matrix_sdk::{
encryption::verification::{AcceptSettings, SasVerification},
ruma::events::key::verification::ShortAuthenticationString,
};
let sas = client
.encryption()
.get_verification(&user_id, flow_id)
.await
.and_then(|v| v.sas());
if let Some(sas) = sas {
let only_decimal = AcceptSettings::with_allowed_methods(vec![
ShortAuthenticationString::Decimal,
]);
sas.accept_with_settings(only_decimal).await?;
}
Sourcepub async fn confirm(&self) -> Result<()>
pub async fn confirm(&self) -> Result<()>
Confirm that the short auth strings match on both sides.
Sourcepub async fn mismatch(&self) -> Result<()>
pub async fn mismatch(&self) -> Result<()>
Cancel the interactive verification flow because the short auth strings didn’t match on both sides.
Sourcepub fn emoji(&self) -> Option<[Emoji; 7]>
pub fn emoji(&self) -> Option<[Emoji; 7]>
Get the emoji version of the short auth string.
§Examples
use matrix_sdk::{
encryption::verification::{AcceptSettings, SasVerification},
ruma::events::key::verification::ShortAuthenticationString,
};
let sas_verification = client
.encryption()
.get_verification(&user_id, flow_id)
.await
.and_then(|v| v.sas());
if let Some(emojis) = sas_verification.and_then(|s| s.emoji()) {
let emoji_string = emojis
.iter()
.map(|e| format!("{:^12}", e.symbol))
.collect::<Vec<_>>()
.join("");
let description = emojis
.iter()
.map(|e| format!("{:^12}", e.description))
.collect::<Vec<_>>()
.join("");
println!("Do the emojis match?\n{emoji_string}\n{description}");
}
Sourcepub fn decimals(&self) -> Option<(u16, u16, u16)>
pub fn decimals(&self) -> Option<(u16, u16, u16)>
Get the decimal version of the short auth string.
Sourcepub fn supports_emoji(&self) -> bool
pub fn supports_emoji(&self) -> bool
Does this verification flow support emoji for the short authentication string.
Sourcepub fn can_be_presented(&self) -> bool
pub fn can_be_presented(&self) -> bool
Are we in a state where we can show the short auth string.
Sourcepub fn we_started(&self) -> bool
pub fn we_started(&self) -> bool
Did we initiate the verification flow.
Sourcepub fn cancel_info(&self) -> Option<CancelInfo>
pub fn cancel_info(&self) -> Option<CancelInfo>
Get info about the cancellation if the verification flow has been cancelled.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Is the verification process canceled.
Sourcepub fn other_device(&self) -> &DeviceData
pub fn other_device(&self) -> &DeviceData
Get the other users device that we’re verifying.
Sourcepub fn started_from_request(&self) -> bool
pub fn started_from_request(&self) -> bool
Did this verification flow start from a verification request.
Sourcepub fn is_self_verification(&self) -> bool
pub fn is_self_verification(&self) -> bool
Is this a verification that is verifying one of our own devices.
Sourcepub fn own_user_id(&self) -> &UserId
pub fn own_user_id(&self) -> &UserId
Get our own user id.
Sourcepub fn other_user_id(&self) -> &UserId
pub fn other_user_id(&self) -> &UserId
Get the user id of the other user participating in this verification flow.
Sourcepub fn changes(&self) -> impl Stream<Item = SasState>
pub fn changes(&self) -> impl Stream<Item = SasState>
Listen for changes in the SAS verification process.
The changes are presented as a stream of SasState
values.
This method can be used to react to changes in the state of the verification process, or rather the method can be used to handle each step of the verification process.
§Flowchart
The flow of the verification process is pictured bellow. Please note that the process can be cancelled at each step of the process. Either side can cancel the process.
┌───────┐
│Created│
└───┬───┘
│
┌───⌄───┐
│Started│
└───┬───┘
│
┌────⌄───┐
│Accepted│
└────┬───┘
│
┌───────⌄──────┐
│Keys Exchanged│
└───────┬──────┘
│
________⌄________
╱ ╲ ┌─────────┐
╱ Does the short ╲______│Cancelled│
╲ auth string match ╱ no └─────────┘
╲_________________╱
│yes
│
┌────⌄────┐
│Confirmed│
└────┬────┘
│
┌───⌄───┐
│ Done │
└───────┘
§Examples
use futures_util::{Stream, StreamExt};
use matrix_sdk::encryption::verification::{SasState, SasVerification};
let mut stream = sas.changes();
while let Some(state) = stream.next().await {
match state {
SasState::KeysExchanged { emojis, decimals: _ } => {
let emojis =
emojis.expect("We only support emoji verification");
println!("Do these emojis match {emojis:#?}");
// Ask the user to confirm or cancel here.
if user_confirmed {
sas.confirm().await?;
} else {
sas.cancel().await?;
}
}
SasState::Done { .. } => {
let device = sas.other_device();
println!(
"Successfully verified device {} {} {:?}",
device.user_id(),
device.device_id(),
device.local_trust_state()
);
break;
}
SasState::Cancelled(cancel_info) => {
println!(
"The verification has been cancelled, reason: {}",
cancel_info.reason()
);
break;
}
SasState::Created { .. }
| SasState::Started { .. }
| SasState::Accepted { .. }
| SasState::Confirmed => (),
}
}
Sourcepub fn state(&self) -> SasState
pub fn state(&self) -> SasState
Get the current state the verification process is in.
To listen to changes to the SasState
use the
SasVerification::changes
method.
Trait Implementations§
Source§impl Clone for SasVerification
impl Clone for SasVerification
Source§fn clone(&self) -> SasVerification
fn clone(&self) -> SasVerification
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for SasVerification
impl Debug for SasVerification
Source§impl From<SasVerification> for Verification
impl From<SasVerification> for Verification
Source§fn from(sas: SasVerification) -> Self
fn from(sas: SasVerification) -> Self
Auto Trait Implementations§
impl Freeze for SasVerification
impl !RefUnwindSafe for SasVerification
impl Send for SasVerification
impl Sync for SasVerification
impl Unpin for SasVerification
impl !UnwindSafe for SasVerification
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§fn consume_handle(handle: Handle) -> Arc<T>
fn consume_handle(handle: Handle) -> Arc<T>
Arc<>
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more