@@ -2,11 +2,7 @@ use std::{fs, num::NonZeroUsize, path::Path, sync::Arc, time::Duration};
2
2
3
3
use futures_util:: StreamExt ;
4
4
use matrix_sdk:: {
5
- authentication:: oauth:: qrcode:: { self , DeviceCodeErrorResponseType , LoginFailureReason } ,
6
- crypto:: {
7
- types:: qr_login:: { LoginQrCodeDecodeError , QrCodeModeData } ,
8
- CollectStrategy , TrustRequirement ,
9
- } ,
5
+ crypto:: { types:: qr_login:: QrCodeModeData , CollectStrategy , TrustRequirement } ,
10
6
encryption:: { BackupDownloadStrategy , EncryptionSettings } ,
11
7
event_cache:: EventCacheError ,
12
8
reqwest:: Certificate ,
@@ -18,15 +14,19 @@ use matrix_sdk::{
18
14
Client as MatrixClient , ClientBuildError as MatrixClientBuildError , HttpError , IdParseError ,
19
15
RumaApiError , SqliteStoreConfig ,
20
16
} ;
21
- use matrix_sdk_common:: { SendOutsideWasm , SyncOutsideWasm } ;
22
17
use ruma:: api:: error:: { DeserializationError , FromHttpResponseError } ;
23
18
use tracing:: { debug, error} ;
24
19
use zeroize:: Zeroizing ;
25
20
26
21
use super :: client:: Client ;
27
22
use crate :: {
28
- authentication:: OidcConfiguration , client:: ClientSessionDelegate , error:: ClientError ,
29
- helpers:: unwrap_or_clone_arc, runtime:: get_runtime_handle, task_handle:: TaskHandle ,
23
+ authentication:: OidcConfiguration ,
24
+ client:: ClientSessionDelegate ,
25
+ error:: ClientError ,
26
+ helpers:: unwrap_or_clone_arc,
27
+ qr_code:: { HumanQrLoginError , QrCodeData , QrLoginProgressListener } ,
28
+ runtime:: get_runtime_handle,
29
+ task_handle:: TaskHandle ,
30
30
} ;
31
31
32
32
/// A list of bytes containing a certificate in DER or PEM form.
@@ -39,164 +39,6 @@ enum HomeserverConfig {
39
39
ServerNameOrUrl ( String ) ,
40
40
}
41
41
42
- /// Data for the QR code login mechanism.
43
- ///
44
- /// The [`QrCodeData`] can be serialized and encoded as a QR code or it can be
45
- /// decoded from a QR code.
46
- #[ derive( Debug , uniffi:: Object ) ]
47
- pub struct QrCodeData {
48
- inner : qrcode:: QrCodeData ,
49
- }
50
-
51
- #[ matrix_sdk_ffi_macros:: export]
52
- impl QrCodeData {
53
- /// Attempt to decode a slice of bytes into a [`QrCodeData`] object.
54
- ///
55
- /// The slice of bytes would generally be returned by a QR code decoder.
56
- #[ uniffi:: constructor]
57
- pub fn from_bytes ( bytes : Vec < u8 > ) -> Result < Arc < Self > , QrCodeDecodeError > {
58
- Ok ( Self { inner : qrcode:: QrCodeData :: from_bytes ( & bytes) ? } . into ( ) )
59
- }
60
-
61
- /// The server name contained within the scanned QR code data.
62
- ///
63
- /// Note: This value is only present when scanning a QR code the belongs to
64
- /// a logged in client. The mode where the new client shows the QR code
65
- /// will return `None`.
66
- pub fn server_name ( & self ) -> Option < String > {
67
- match & self . inner . mode_data {
68
- QrCodeModeData :: Reciprocate { server_name } => Some ( server_name. to_owned ( ) ) ,
69
- QrCodeModeData :: Login => None ,
70
- }
71
- }
72
- }
73
-
74
- /// Error type for the decoding of the [`QrCodeData`].
75
- #[ derive( Debug , thiserror:: Error , uniffi:: Error ) ]
76
- #[ uniffi( flat_error) ]
77
- pub enum QrCodeDecodeError {
78
- #[ error( "Error decoding QR code: {error:?}" ) ]
79
- Crypto {
80
- #[ from]
81
- error : LoginQrCodeDecodeError ,
82
- } ,
83
- }
84
-
85
- #[ derive( Debug , thiserror:: Error , uniffi:: Error ) ]
86
- pub enum HumanQrLoginError {
87
- #[ error( "Linking with this device is not supported." ) ]
88
- LinkingNotSupported ,
89
- #[ error( "The sign in was cancelled." ) ]
90
- Cancelled ,
91
- #[ error( "The sign in was not completed in the required time." ) ]
92
- Expired ,
93
- #[ error( "A secure connection could not have been established between the two devices." ) ]
94
- ConnectionInsecure ,
95
- #[ error( "The sign in was declined." ) ]
96
- Declined ,
97
- #[ error( "An unknown error has happened." ) ]
98
- Unknown ,
99
- #[ error( "The homeserver doesn't provide sliding sync in its configuration." ) ]
100
- SlidingSyncNotAvailable ,
101
- #[ error( "Unable to use OIDC as the supplied client metadata is invalid." ) ]
102
- OidcMetadataInvalid ,
103
- #[ error( "The other device is not signed in and as such can't sign in other devices." ) ]
104
- OtherDeviceNotSignedIn ,
105
- }
106
-
107
- impl From < qrcode:: QRCodeLoginError > for HumanQrLoginError {
108
- fn from ( value : qrcode:: QRCodeLoginError ) -> Self {
109
- use qrcode:: { QRCodeLoginError , SecureChannelError } ;
110
-
111
- match value {
112
- QRCodeLoginError :: LoginFailure { reason, .. } => match reason {
113
- LoginFailureReason :: UnsupportedProtocol => HumanQrLoginError :: LinkingNotSupported ,
114
- LoginFailureReason :: AuthorizationExpired => HumanQrLoginError :: Expired ,
115
- LoginFailureReason :: UserCancelled => HumanQrLoginError :: Cancelled ,
116
- _ => HumanQrLoginError :: Unknown ,
117
- } ,
118
-
119
- QRCodeLoginError :: OAuth ( e) => {
120
- if let Some ( e) = e. as_request_token_error ( ) {
121
- match e {
122
- DeviceCodeErrorResponseType :: AccessDenied => HumanQrLoginError :: Declined ,
123
- DeviceCodeErrorResponseType :: ExpiredToken => HumanQrLoginError :: Expired ,
124
- _ => HumanQrLoginError :: Unknown ,
125
- }
126
- } else {
127
- HumanQrLoginError :: Unknown
128
- }
129
- }
130
-
131
- QRCodeLoginError :: SecureChannel ( e) => match e {
132
- SecureChannelError :: Utf8 ( _)
133
- | SecureChannelError :: MessageDecode ( _)
134
- | SecureChannelError :: Json ( _)
135
- | SecureChannelError :: RendezvousChannel ( _) => HumanQrLoginError :: Unknown ,
136
- SecureChannelError :: SecureChannelMessage { .. }
137
- | SecureChannelError :: Ecies ( _)
138
- | SecureChannelError :: InvalidCheckCode => HumanQrLoginError :: ConnectionInsecure ,
139
- SecureChannelError :: InvalidIntent => HumanQrLoginError :: OtherDeviceNotSignedIn ,
140
- } ,
141
-
142
- QRCodeLoginError :: UnexpectedMessage { .. }
143
- | QRCodeLoginError :: CrossProcessRefreshLock ( _)
144
- | QRCodeLoginError :: DeviceKeyUpload ( _)
145
- | QRCodeLoginError :: SessionTokens ( _)
146
- | QRCodeLoginError :: UserIdDiscovery ( _)
147
- | QRCodeLoginError :: SecretImport ( _) => HumanQrLoginError :: Unknown ,
148
- }
149
- }
150
- }
151
-
152
- /// Enum describing the progress of the QR-code login.
153
- #[ derive( Debug , Default , Clone , uniffi:: Enum ) ]
154
- pub enum QrLoginProgress {
155
- /// The login process is starting.
156
- #[ default]
157
- Starting ,
158
- /// We established a secure channel with the other device.
159
- EstablishingSecureChannel {
160
- /// The check code that the device should display so the other device
161
- /// can confirm that the channel is secure as well.
162
- check_code : u8 ,
163
- /// The string representation of the check code, will be guaranteed to
164
- /// be 2 characters long, preserving the leading zero if the
165
- /// first digit is a zero.
166
- check_code_string : String ,
167
- } ,
168
- /// We are waiting for the login and for the OAuth 2.0 authorization server
169
- /// to give us an access token.
170
- WaitingForToken { user_code : String } ,
171
- /// The login has successfully finished.
172
- Done ,
173
- }
174
-
175
- #[ matrix_sdk_ffi_macros:: export( callback_interface) ]
176
- pub trait QrLoginProgressListener : SyncOutsideWasm + SendOutsideWasm {
177
- fn on_update ( & self , state : QrLoginProgress ) ;
178
- }
179
-
180
- impl From < qrcode:: LoginProgress > for QrLoginProgress {
181
- fn from ( value : qrcode:: LoginProgress ) -> Self {
182
- use qrcode:: LoginProgress ;
183
-
184
- match value {
185
- LoginProgress :: Starting => Self :: Starting ,
186
- LoginProgress :: EstablishingSecureChannel { check_code } => {
187
- let check_code = check_code. to_digit ( ) ;
188
-
189
- Self :: EstablishingSecureChannel {
190
- check_code,
191
- check_code_string : format ! ( "{check_code:02}" ) ,
192
- }
193
- }
194
- LoginProgress :: WaitingForToken { user_code } => Self :: WaitingForToken { user_code } ,
195
- LoginProgress :: Done => Self :: Done ,
196
- }
197
- }
198
- }
199
-
200
42
#[ derive( Debug , thiserror:: Error , uniffi:: Error ) ]
201
43
#[ uniffi( flat_error) ]
202
44
pub enum ClientBuildError {
0 commit comments