matrix_sdk/encryption/verification/
mod.rs1#[cfg(feature = "qrcode")]
33mod qrcode;
34mod requests;
35mod sas;
36
37use as_variant::as_variant;
38pub use matrix_sdk_base::crypto::{
39 format_emojis, AcceptSettings, AcceptedProtocols, CancelInfo, Emoji, EmojiShortAuthString,
40 SasState,
41};
42#[cfg(feature = "qrcode")]
43pub use matrix_sdk_base::crypto::{
44 matrix_sdk_qrcode::{DecodingError, EncodingError, QrVerificationData},
45 QrVerificationState, ScanError,
46};
47#[cfg(feature = "qrcode")]
48pub use qrcode::QrVerification;
49pub use requests::{VerificationRequest, VerificationRequestState};
50use ruma::RoomId;
51pub use sas::SasVerification;
52
53#[derive(Debug, Clone)]
55#[non_exhaustive]
56pub enum Verification {
57 SasV1(SasVerification),
59 #[cfg(feature = "qrcode")]
60 QrV1(QrVerification),
62}
63
64impl Verification {
65 pub fn sas(self) -> Option<SasVerification> {
67 as_variant!(self, Verification::SasV1)
68 }
69
70 #[cfg(feature = "qrcode")]
72 pub fn qr(self) -> Option<QrVerification> {
73 as_variant!(self, Verification::QrV1)
74 }
75
76 pub fn is_done(&self) -> bool {
78 match self {
79 Verification::SasV1(s) => s.is_done(),
80 #[cfg(feature = "qrcode")]
81 Verification::QrV1(qr) => qr.is_done(),
82 }
83 }
84
85 pub fn is_cancelled(&self) -> bool {
87 match self {
88 Verification::SasV1(s) => s.is_cancelled(),
89 #[cfg(feature = "qrcode")]
90 Verification::QrV1(qr) => qr.is_cancelled(),
91 }
92 }
93
94 pub fn cancel_info(&self) -> Option<CancelInfo> {
97 match self {
98 Verification::SasV1(s) => s.cancel_info(),
99 #[cfg(feature = "qrcode")]
100 Verification::QrV1(q) => q.cancel_info(),
101 }
102 }
103
104 pub fn own_user_id(&self) -> &ruma::UserId {
106 match self {
107 Verification::SasV1(v) => v.own_user_id(),
108 #[cfg(feature = "qrcode")]
109 Verification::QrV1(v) => v.own_user_id(),
110 }
111 }
112
113 pub fn other_user_id(&self) -> &ruma::UserId {
116 match self {
117 Verification::SasV1(v) => v.inner.other_user_id(),
118 #[cfg(feature = "qrcode")]
119 Verification::QrV1(v) => v.inner.other_user_id(),
120 }
121 }
122
123 pub fn is_self_verification(&self) -> bool {
125 match self {
126 Verification::SasV1(v) => v.is_self_verification(),
127 #[cfg(feature = "qrcode")]
128 Verification::QrV1(v) => v.is_self_verification(),
129 }
130 }
131
132 pub fn we_started(&self) -> bool {
134 match self {
135 Verification::SasV1(s) => s.we_started(),
136 #[cfg(feature = "qrcode")]
137 Verification::QrV1(q) => q.we_started(),
138 }
139 }
140
141 pub fn room_id(&self) -> Option<&RoomId> {
143 match self {
144 Verification::SasV1(s) => s.room_id(),
145 #[cfg(feature = "qrcode")]
146 Verification::QrV1(q) => q.room_id(),
147 }
148 }
149}
150
151impl From<SasVerification> for Verification {
152 fn from(sas: SasVerification) -> Self {
153 Self::SasV1(sas)
154 }
155}
156
157#[cfg(feature = "qrcode")]
158impl From<QrVerification> for Verification {
159 fn from(qr: QrVerification) -> Self {
160 Self::QrV1(qr)
161 }
162}