Struct matrix_sdk::encryption::verification::SasVerification
source · 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,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§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