1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15- use std:: ops:: Deref ;
16-
17- use async_trait:: async_trait;
1815use ruma:: UserId ;
1916use tracing:: error;
2017use vodozemac:: Curve25519PublicKey ;
2118
2219use super :: { SenderData , SenderDataRetryDetails } ;
2320use crate :: {
2421 error:: OlmResult ,
25- identities:: Device ,
26- store:: { self , Store } ,
22+ store:: Store ,
2723 types:: { events:: olm_v1:: DecryptedRoomKeyEvent , DeviceKeys , MasterPubkey } ,
2824 EventError , OlmError , OlmMachine , ReadOnlyDevice , ReadOnlyOwnUserIdentity ,
2925 ReadOnlyUserIdentities ,
@@ -34,12 +30,12 @@ use crate::{
3430///
3531/// The letters A, B etc. in the documentation refer to the algorithm described
3632/// in https://github.com/matrix-org/matrix-rust-sdk/issues/3543
37- pub ( crate ) struct SenderDataFinder < ' a , S : FinderCryptoStore > {
38- own_crypto_store : & ' a S ,
33+ pub ( crate ) struct SenderDataFinder < ' a > {
34+ own_crypto_store : & ' a Store ,
3935 own_user_id : & ' a UserId ,
4036}
4137
42- impl < ' a > SenderDataFinder < ' a , Store > {
38+ impl < ' a > SenderDataFinder < ' a > {
4339 /// As described in https://github.com/matrix-org/matrix-rust-sdk/issues/3543
4440 /// and https://github.com/matrix-org/matrix-rust-sdk/issues/3544
4541 /// find the device info associated with the to-device message used to
@@ -70,9 +66,7 @@ impl<'a> SenderDataFinder<'a, Store> {
7066 } ;
7167 finder. have_device_keys ( & device_keys) . await
7268 }
73- }
7469
75- impl < ' a , S : FinderCryptoStore > SenderDataFinder < ' a , S > {
7670 async fn have_event (
7771 & self ,
7872 sender_curve_key : Curve25519PublicKey ,
@@ -347,56 +341,20 @@ impl<'a, S: FinderCryptoStore> SenderDataFinder<'a, S> {
347341 }
348342}
349343
350- #[ cfg_attr( target_arch = "wasm32" , async_trait( ?Send ) ) ]
351- #[ cfg_attr( not( target_arch = "wasm32" ) , async_trait) ]
352- pub ( crate ) trait FinderCryptoStore {
353- async fn get_device_from_curve_key (
354- & self ,
355- user_id : & UserId ,
356- curve_key : Curve25519PublicKey ,
357- ) -> store:: Result < Option < Device > > ;
358-
359- async fn get_user_identity (
360- & self ,
361- user_id : & UserId ,
362- ) -> OlmResult < Option < ReadOnlyUserIdentities > > ;
363- }
364-
365- #[ cfg_attr( target_arch = "wasm32" , async_trait( ?Send ) ) ]
366- #[ cfg_attr( not( target_arch = "wasm32" ) , async_trait) ]
367- impl FinderCryptoStore for Store {
368- async fn get_device_from_curve_key (
369- & self ,
370- user_id : & UserId ,
371- curve_key : Curve25519PublicKey ,
372- ) -> store:: Result < Option < Device > > {
373- self . get_device_from_curve_key ( user_id, curve_key) . await
374- }
375-
376- async fn get_user_identity (
377- & self ,
378- user_id : & UserId ,
379- ) -> OlmResult < Option < ReadOnlyUserIdentities > > {
380- Ok ( self . deref ( ) . get_user_identity ( user_id) . await ?)
381- }
382- }
383-
384344#[ cfg( test) ]
385345mod tests {
386346 use std:: { ops:: Deref as _, sync:: Arc } ;
387347
388348 use assert_matches2:: assert_let;
389- use async_trait:: async_trait;
390349 use matrix_sdk_test:: async_test;
391350 use ruma:: { device_id, owned_room_id, user_id, DeviceId , OwnedUserId , UserId } ;
392351 use tokio:: sync:: Mutex ;
393352 use vodozemac:: { megolm:: SessionKey , Curve25519PublicKey , Ed25519PublicKey } ;
394353
395- use super :: { FinderCryptoStore , SenderDataFinder } ;
354+ use super :: SenderDataFinder ;
396355 use crate :: {
397- error:: OlmResult ,
398356 olm:: { PrivateCrossSigningIdentity , SenderData } ,
399- store:: { self , Changes , CryptoStoreWrapper , MemoryStore , Store } ,
357+ store:: { Changes , CryptoStoreWrapper , MemoryStore , Store } ,
400358 types:: events:: {
401359 olm_v1:: DecryptedRoomKeyEvent ,
402360 room_key:: { MegolmV1AesSha2Content , RoomKeyContent } ,
@@ -406,7 +364,7 @@ mod tests {
406364 ReadOnlyUserIdentity ,
407365 } ;
408366
409- impl < ' a > SenderDataFinder < ' a , Store > {
367+ impl < ' a > SenderDataFinder < ' a > {
410368 fn new ( own_crypto_store : & ' a Store , own_user_id : & ' a UserId ) -> Self {
411369 Self { own_crypto_store, own_user_id }
412370 }
@@ -1001,35 +959,4 @@ mod tests {
1001959 . unwrap ( ) ,
1002960 )
1003961 }
1004-
1005- struct FakeCryptoStore {
1006- device : Option < Device > ,
1007- user_identities : Option < ReadOnlyUserIdentities > ,
1008- own_user_identities : Option < ReadOnlyUserIdentities > ,
1009- }
1010-
1011- #[ cfg_attr( target_arch = "wasm32" , async_trait( ?Send ) ) ]
1012- #[ cfg_attr( not( target_arch = "wasm32" ) , async_trait) ]
1013- impl FinderCryptoStore for FakeCryptoStore {
1014- async fn get_device_from_curve_key (
1015- & self ,
1016- _user_id : & UserId ,
1017- _curve_key : Curve25519PublicKey ,
1018- ) -> store:: Result < Option < Device > > {
1019- Ok ( self . device . clone ( ) )
1020- }
1021-
1022- async fn get_user_identity (
1023- & self ,
1024- user_id : & UserId ,
1025- ) -> OlmResult < Option < ReadOnlyUserIdentities > > {
1026- if user_id == user_id ! ( "@myself:s.co" ) {
1027- // We are being asked for our own user identity, different from
1028- // self.user_identities because that one was of Other type.
1029- Ok ( self . own_user_identities . clone ( ) )
1030- } else {
1031- Ok ( self . user_identities . clone ( ) )
1032- }
1033- }
1034- }
1035962}
0 commit comments