@@ -99,13 +99,13 @@ impl IdentityUpdates {
99
99
/// [`Encryption::bootstrap_cross_signing()`]: crate::encryption::Encryption::bootstrap_cross_signing
100
100
#[ derive( Debug , Clone ) ]
101
101
pub struct UserIdentity {
102
- inner : UserIdentities ,
102
+ client : Client ,
103
+ inner : CryptoUserIdentities ,
103
104
}
104
105
105
106
impl UserIdentity {
106
107
pub ( crate ) fn new ( client : Client , identity : CryptoUserIdentities ) -> Self {
107
- let inner = UserIdentities { client, identity } ;
108
- Self { inner }
108
+ Self { inner : identity, client }
109
109
}
110
110
111
111
/// The ID of the user this identity belongs to.
@@ -128,7 +128,7 @@ impl UserIdentity {
128
128
/// # anyhow::Ok(()) };
129
129
/// ```
130
130
pub fn user_id ( & self ) -> & UserId {
131
- match & self . inner . identity {
131
+ match & self . inner {
132
132
CryptoUserIdentities :: Own ( identity) => identity. user_id ( ) ,
133
133
CryptoUserIdentities :: Other ( identity) => identity. user_id ( ) ,
134
134
}
@@ -185,7 +185,7 @@ impl UserIdentity {
185
185
pub async fn request_verification (
186
186
& self ,
187
187
) -> Result < VerificationRequest , RequestVerificationError > {
188
- self . inner . request_verification ( None ) . await
188
+ self . request_verification_impl ( None ) . await
189
189
}
190
190
191
191
/// Request an interactive verification with this `UserIdentity` using the
@@ -244,8 +244,56 @@ impl UserIdentity {
244
244
methods : Vec < VerificationMethod > ,
245
245
) -> Result < VerificationRequest , RequestVerificationError > {
246
246
assert ! ( !methods. is_empty( ) , "The list of verification methods can't be non-empty" ) ;
247
+ self . request_verification_impl ( Some ( methods) ) . await
248
+ }
249
+
250
+ async fn request_verification_impl (
251
+ & self ,
252
+ methods : Option < Vec < VerificationMethod > > ,
253
+ ) -> Result < VerificationRequest , RequestVerificationError > {
254
+ match & self . inner {
255
+ CryptoUserIdentities :: Own ( identity) => {
256
+ let ( verification, request) = if let Some ( methods) = methods {
257
+ identity
258
+ . request_verification_with_methods ( methods)
259
+ . await
260
+ . map_err ( crate :: Error :: from) ?
261
+ } else {
262
+ identity. request_verification ( ) . await . map_err ( crate :: Error :: from) ?
263
+ } ;
247
264
248
- self . inner . request_verification ( Some ( methods) ) . await
265
+ self . client . send_verification_request ( request) . await ?;
266
+
267
+ Ok ( VerificationRequest { inner : verification, client : self . client . clone ( ) } )
268
+ }
269
+ CryptoUserIdentities :: Other ( i) => {
270
+ let content = i. verification_request_content ( methods. clone ( ) ) ;
271
+
272
+ let room = if let Some ( room) = self . client . get_dm_room ( i. user_id ( ) ) {
273
+ // Make sure that the user, to be verified, is still in the room
274
+ if !room
275
+ . members ( RoomMemberships :: ACTIVE )
276
+ . await ?
277
+ . iter ( )
278
+ . any ( |member| member. user_id ( ) == i. user_id ( ) )
279
+ {
280
+ room. invite_user_by_id ( i. user_id ( ) ) . await ?;
281
+ }
282
+ room. clone ( )
283
+ } else {
284
+ self . client . create_dm ( i. user_id ( ) ) . await ?
285
+ } ;
286
+
287
+ let response = room
288
+ . send ( RoomMessageEventContent :: new ( MessageType :: VerificationRequest ( content) ) )
289
+ . await ?;
290
+
291
+ let verification =
292
+ i. request_verification ( room. room_id ( ) , & response. event_id , methods) ;
293
+
294
+ Ok ( VerificationRequest { inner : verification, client : self . client . clone ( ) } )
295
+ }
296
+ }
249
297
}
250
298
251
299
/// Manually verify this [`UserIdentity`].
@@ -308,7 +356,14 @@ impl UserIdentity {
308
356
/// ```
309
357
/// [`Encryption::cross_signing_status()`]: crate::encryption::Encryption::cross_signing_status
310
358
pub async fn verify ( & self ) -> Result < ( ) , ManualVerifyError > {
311
- self . inner . verify ( ) . await
359
+ let request = match & self . inner {
360
+ CryptoUserIdentities :: Own ( identity) => identity. verify ( ) . await ?,
361
+ CryptoUserIdentities :: Other ( identity) => identity. verify ( ) . await ?,
362
+ } ;
363
+
364
+ self . client . send ( request, None ) . await ?;
365
+
366
+ Ok ( ( ) )
312
367
}
313
368
314
369
/// Is the user identity considered to be verified.
@@ -350,7 +405,7 @@ impl UserIdentity {
350
405
/// # anyhow::Ok(()) };
351
406
/// ```
352
407
pub fn is_verified ( & self ) -> bool {
353
- self . inner . identity . is_verified ( )
408
+ self . inner . is_verified ( )
354
409
}
355
410
356
411
/// Remove the requirement for this identity to be verified.
@@ -359,7 +414,7 @@ impl UserIdentity {
359
414
/// reported to the user. In order to remove this notice users have to
360
415
/// verify again or to withdraw the verification requirement.
361
416
pub async fn withdraw_verification ( & self ) -> Result < ( ) , CryptoStoreError > {
362
- self . inner . identity . withdraw_verification ( ) . await
417
+ self . inner . withdraw_verification ( ) . await
363
418
}
364
419
365
420
/// Get the public part of the Master key of this user identity.
@@ -404,75 +459,9 @@ impl UserIdentity {
404
459
/// # anyhow::Ok(()) };
405
460
/// ```
406
461
pub fn master_key ( & self ) -> & MasterPubkey {
407
- match & self . inner . identity {
462
+ match & self . inner {
408
463
CryptoUserIdentities :: Own ( identity) => identity. master_key ( ) ,
409
464
CryptoUserIdentities :: Other ( identity) => identity. master_key ( ) ,
410
465
}
411
466
}
412
467
}
413
-
414
- #[ derive( Debug , Clone ) ]
415
- struct UserIdentities {
416
- client : Client ,
417
- identity : CryptoUserIdentities ,
418
- }
419
-
420
- impl UserIdentities {
421
- async fn request_verification (
422
- & self ,
423
- methods : Option < Vec < VerificationMethod > > ,
424
- ) -> Result < VerificationRequest , RequestVerificationError > {
425
- match & self . identity {
426
- CryptoUserIdentities :: Own ( identity) => {
427
- let ( verification, request) = if let Some ( methods) = methods {
428
- identity
429
- . request_verification_with_methods ( methods)
430
- . await
431
- . map_err ( crate :: Error :: from) ?
432
- } else {
433
- identity. request_verification ( ) . await . map_err ( crate :: Error :: from) ?
434
- } ;
435
-
436
- self . client . send_verification_request ( request) . await ?;
437
-
438
- Ok ( VerificationRequest { inner : verification, client : self . client . clone ( ) } )
439
- }
440
- CryptoUserIdentities :: Other ( i) => {
441
- let content = i. verification_request_content ( methods. clone ( ) ) ;
442
-
443
- let room = if let Some ( room) = self . client . get_dm_room ( i. user_id ( ) ) {
444
- // Make sure that the user, to be verified, is still in the room
445
- if !room
446
- . members ( RoomMemberships :: ACTIVE )
447
- . await ?
448
- . iter ( )
449
- . any ( |member| member. user_id ( ) == i. user_id ( ) )
450
- {
451
- room. invite_user_by_id ( i. user_id ( ) ) . await ?;
452
- }
453
- room. clone ( )
454
- } else {
455
- self . client . create_dm ( i. user_id ( ) ) . await ?
456
- } ;
457
-
458
- let response = room
459
- . send ( RoomMessageEventContent :: new ( MessageType :: VerificationRequest ( content) ) )
460
- . await ?;
461
-
462
- let verification =
463
- i. request_verification ( room. room_id ( ) , & response. event_id , methods) ;
464
-
465
- Ok ( VerificationRequest { inner : verification, client : self . client . clone ( ) } )
466
- }
467
- }
468
- }
469
-
470
- async fn verify ( & self ) -> Result < ( ) , ManualVerifyError > {
471
- let request = match & self . identity {
472
- CryptoUserIdentities :: Own ( identity) => identity. verify ( ) . await ?,
473
- CryptoUserIdentities :: Other ( identity) => identity. verify ( ) . await ?,
474
- } ;
475
- self . client . send ( request, None ) . await ?;
476
- Ok ( ( ) )
477
- }
478
- }
0 commit comments