@@ -27,10 +27,7 @@ use matrix_sdk_crypto::{
2727 IdentityKeys , InboundGroupSession , OutboundGroupSession , PickledInboundGroupSession ,
2828 PrivateCrossSigningIdentity , Session ,
2929 } ,
30- store:: {
31- caches:: SessionStore , BackupKeys , Changes , CryptoStore , CryptoStoreError ,
32- Result as StoreResult , RoomKeyCounts ,
33- } ,
30+ store:: { caches:: SessionStore , BackupKeys , Changes , CryptoStore , RoomKeyCounts } ,
3431 GossipRequest , ReadOnlyAccount , ReadOnlyDevice , ReadOnlyUserIdentities , SecretInfo ,
3532 TrackedUser ,
3633} ;
@@ -525,14 +522,14 @@ impl SqliteObjectCryptoStoreExt for deadpool_sqlite::Object {}
525522
526523#[ async_trait]
527524impl CryptoStore for SqliteCryptoStore {
528- type Error = CryptoStoreError ;
525+ type Error = Error ;
529526
530- async fn load_account ( & self ) -> StoreResult < Option < ReadOnlyAccount > > {
527+ async fn load_account ( & self ) -> Result < Option < ReadOnlyAccount > > {
531528 let conn = self . acquire ( ) . await ?;
532- if let Some ( pickle) = conn. get_kv ( "account" ) . await . map_err ( CryptoStoreError :: backend ) ? {
529+ if let Some ( pickle) = conn. get_kv ( "account" ) . await ? {
533530 let pickle = self . deserialize_value ( & pickle) ?;
534531
535- let account = ReadOnlyAccount :: from_pickle ( pickle) ?;
532+ let account = ReadOnlyAccount :: from_pickle ( pickle) . map_err ( |_| Error :: Unpickle ) ?;
536533
537534 let account_info = AccountInfo {
538535 user_id : account. user_id . clone ( ) ,
@@ -548,7 +545,7 @@ impl CryptoStore for SqliteCryptoStore {
548545 }
549546 }
550547
551- async fn save_account ( & self , account : ReadOnlyAccount ) -> StoreResult < ( ) > {
548+ async fn save_account ( & self , account : ReadOnlyAccount ) -> Result < ( ) > {
552549 let account_info = AccountInfo {
553550 user_id : account. user_id . clone ( ) ,
554551 device_id : account. device_id . clone ( ) ,
@@ -558,29 +555,25 @@ impl CryptoStore for SqliteCryptoStore {
558555
559556 let pickled_account = account. pickle ( ) . await ;
560557 let serialized_account = self . serialize_value ( & pickled_account) ?;
561- self . acquire ( )
562- . await ?
563- . set_kv ( "account" , serialized_account)
564- . await
565- . map_err ( CryptoStoreError :: backend) ?;
558+ self . acquire ( ) . await ?. set_kv ( "account" , serialized_account) . await ?;
566559 Ok ( ( ) )
567560 }
568561
569- async fn load_identity ( & self ) -> StoreResult < Option < PrivateCrossSigningIdentity > > {
562+ async fn load_identity ( & self ) -> Result < Option < PrivateCrossSigningIdentity > > {
570563 let conn = self . acquire ( ) . await ?;
571- if let Some ( i) = conn. get_kv ( "identity" ) . await . map_err ( CryptoStoreError :: backend ) ? {
564+ if let Some ( i) = conn. get_kv ( "identity" ) . await ? {
572565 let pickle = self . deserialize_value ( & i) ?;
573566 Ok ( Some (
574567 PrivateCrossSigningIdentity :: from_pickle ( pickle)
575568 . await
576- . map_err ( |_| CryptoStoreError :: UnpicklingError ) ?,
569+ . map_err ( |_| Error :: Unpickle ) ?,
577570 ) )
578571 } else {
579572 Ok ( None )
580573 }
581574 }
582575
583- async fn save_changes ( & self , changes : Changes ) -> StoreResult < ( ) > {
576+ async fn save_changes ( & self , changes : Changes ) -> Result < ( ) > {
584577 let pickled_account = if let Some ( account) = changes. account {
585578 let account_info = AccountInfo {
586579 user_id : account. user_id . clone ( ) ,
@@ -704,11 +697,8 @@ impl CryptoStore for SqliteCryptoStore {
704697 Ok ( ( ) )
705698 }
706699
707- async fn get_sessions (
708- & self ,
709- sender_key : & str ,
710- ) -> StoreResult < Option < Arc < Mutex < Vec < Session > > > > > {
711- let account_info = self . get_account_info ( ) . ok_or ( CryptoStoreError :: AccountUnset ) ?;
700+ async fn get_sessions ( & self , sender_key : & str ) -> Result < Option < Arc < Mutex < Vec < Session > > > > > {
701+ let account_info = self . get_account_info ( ) . ok_or ( Error :: AccountUnset ) ?;
712702
713703 if self . session_cache . get ( sender_key) . is_none ( ) {
714704 let sessions = self
@@ -739,7 +729,7 @@ impl CryptoStore for SqliteCryptoStore {
739729 & self ,
740730 room_id : & RoomId ,
741731 session_id : & str ,
742- ) -> StoreResult < Option < InboundGroupSession > > {
732+ ) -> Result < Option < InboundGroupSession > > {
743733 let session_id = self . encode_key ( "inbound_group_session" , session_id) ;
744734 let Some ( ( room_id_from_db, value) ) =
745735 self . acquire ( ) . await ?. get_inbound_group_session ( session_id) . await ?
@@ -758,7 +748,7 @@ impl CryptoStore for SqliteCryptoStore {
758748 Ok ( Some ( InboundGroupSession :: from_pickle ( pickle) ?) )
759749 }
760750
761- async fn get_inbound_group_sessions ( & self ) -> StoreResult < Vec < InboundGroupSession > > {
751+ async fn get_inbound_group_sessions ( & self ) -> Result < Vec < InboundGroupSession > > {
762752 self . acquire ( )
763753 . await ?
764754 . get_inbound_group_sessions ( )
@@ -771,14 +761,14 @@ impl CryptoStore for SqliteCryptoStore {
771761 . collect ( )
772762 }
773763
774- async fn inbound_group_session_counts ( & self ) -> StoreResult < RoomKeyCounts > {
764+ async fn inbound_group_session_counts ( & self ) -> Result < RoomKeyCounts > {
775765 Ok ( self . acquire ( ) . await ?. get_inbound_group_session_counts ( ) . await ?)
776766 }
777767
778768 async fn inbound_group_sessions_for_backup (
779769 & self ,
780770 limit : usize ,
781- ) -> StoreResult < Vec < InboundGroupSession > > {
771+ ) -> Result < Vec < InboundGroupSession > > {
782772 self . acquire ( )
783773 . await ?
784774 . get_inbound_group_sessions_for_backup ( limit)
@@ -791,24 +781,22 @@ impl CryptoStore for SqliteCryptoStore {
791781 . collect ( )
792782 }
793783
794- async fn reset_backup_state ( & self ) -> StoreResult < ( ) > {
784+ async fn reset_backup_state ( & self ) -> Result < ( ) > {
795785 Ok ( self . acquire ( ) . await ?. reset_inbound_group_session_backup_state ( ) . await ?)
796786 }
797787
798- async fn load_backup_keys ( & self ) -> StoreResult < BackupKeys > {
788+ async fn load_backup_keys ( & self ) -> Result < BackupKeys > {
799789 let conn = self . acquire ( ) . await ?;
800790
801791 let backup_version = conn
802792 . get_kv ( "backup_version_v1" )
803- . await
804- . map_err ( CryptoStoreError :: backend) ?
793+ . await ?
805794 . map ( |value| self . deserialize_value ( & value) )
806795 . transpose ( ) ?;
807796
808797 let recovery_key = conn
809798 . get_kv ( "recovery_key_v1" )
810- . await
811- . map_err ( CryptoStoreError :: backend) ?
799+ . await ?
812800 . map ( |value| self . deserialize_value ( & value) )
813801 . transpose ( ) ?;
814802
@@ -818,35 +806,36 @@ impl CryptoStore for SqliteCryptoStore {
818806 async fn get_outbound_group_session (
819807 & self ,
820808 room_id : & RoomId ,
821- ) -> StoreResult < Option < OutboundGroupSession > > {
809+ ) -> Result < Option < OutboundGroupSession > > {
822810 let room_id = self . encode_key ( "outbound_group_session" , room_id. as_bytes ( ) ) ;
823811 let Some ( value) = self . acquire ( ) . await ?. get_outbound_group_session ( room_id) . await ? else {
824812 return Ok ( None ) ;
825813 } ;
826814
827- let account_info = self . get_account_info ( ) . ok_or ( CryptoStoreError :: AccountUnset ) ?;
815+ let account_info = self . get_account_info ( ) . ok_or ( Error :: AccountUnset ) ?;
828816
829817 let pickle = self . deserialize_value ( & value) ?;
830818 let session = OutboundGroupSession :: from_pickle (
831819 account_info. device_id ,
832820 account_info. identity_keys ,
833821 pickle,
834- ) ?;
822+ )
823+ . map_err ( |_| Error :: Unpickle ) ?;
835824
836825 return Ok ( Some ( session) ) ;
837826 }
838827
839- async fn load_tracked_users ( & self ) -> StoreResult < Vec < TrackedUser > > {
828+ async fn load_tracked_users ( & self ) -> Result < Vec < TrackedUser > > {
840829 self . acquire ( )
841830 . await ?
842831 . get_tracked_users ( )
843832 . await ?
844833 . iter ( )
845- . map ( |value| Ok ( self . deserialize_value ( value) ? ) )
834+ . map ( |value| self . deserialize_value ( value) )
846835 . collect ( )
847836 }
848837
849- async fn save_tracked_users ( & self , tracked_users : & [ ( & UserId , bool ) ] ) -> StoreResult < ( ) > {
838+ async fn save_tracked_users ( & self , tracked_users : & [ ( & UserId , bool ) ] ) -> Result < ( ) > {
850839 let users: Vec < ( Key , Vec < u8 > ) > = tracked_users
851840 . iter ( )
852841 . map ( |( u, d) | {
@@ -864,7 +853,7 @@ impl CryptoStore for SqliteCryptoStore {
864853 & self ,
865854 user_id : & UserId ,
866855 device_id : & DeviceId ,
867- ) -> StoreResult < Option < ReadOnlyDevice > > {
856+ ) -> Result < Option < ReadOnlyDevice > > {
868857 let user_id = self . encode_key ( "device" , user_id. as_bytes ( ) ) ;
869858 let device_id = self . encode_key ( "device" , device_id. as_bytes ( ) ) ;
870859 Ok ( self
@@ -879,7 +868,7 @@ impl CryptoStore for SqliteCryptoStore {
879868 async fn get_user_devices (
880869 & self ,
881870 user_id : & UserId ,
882- ) -> StoreResult < HashMap < OwnedDeviceId , ReadOnlyDevice > > {
871+ ) -> Result < HashMap < OwnedDeviceId , ReadOnlyDevice > > {
883872 let user_id = self . encode_key ( "device" , user_id. as_bytes ( ) ) ;
884873 self . acquire ( )
885874 . await ?
@@ -893,10 +882,7 @@ impl CryptoStore for SqliteCryptoStore {
893882 . collect ( )
894883 }
895884
896- async fn get_user_identity (
897- & self ,
898- user_id : & UserId ,
899- ) -> StoreResult < Option < ReadOnlyUserIdentities > > {
885+ async fn get_user_identity ( & self , user_id : & UserId ) -> Result < Option < ReadOnlyUserIdentities > > {
900886 let user_id = self . encode_key ( "identity" , user_id. as_bytes ( ) ) ;
901887 Ok ( self
902888 . acquire ( )
@@ -910,15 +896,15 @@ impl CryptoStore for SqliteCryptoStore {
910896 async fn is_message_known (
911897 & self ,
912898 message_hash : & matrix_sdk_crypto:: olm:: OlmMessageHash ,
913- ) -> StoreResult < bool > {
914- let value = rmp_serde:: to_vec ( message_hash) . map_err ( CryptoStoreError :: backend ) ?;
899+ ) -> Result < bool > {
900+ let value = rmp_serde:: to_vec ( message_hash) ?;
915901 Ok ( self . acquire ( ) . await ?. has_olm_hash ( value) . await ?)
916902 }
917903
918904 async fn get_outgoing_secret_requests (
919905 & self ,
920906 request_id : & TransactionId ,
921- ) -> StoreResult < Option < GossipRequest > > {
907+ ) -> Result < Option < GossipRequest > > {
922908 let request_id = self . encode_key ( "key_requests" , request_id. as_bytes ( ) ) ;
923909 Ok ( self
924910 . acquire ( )
@@ -932,7 +918,7 @@ impl CryptoStore for SqliteCryptoStore {
932918 async fn get_secret_request_by_info (
933919 & self ,
934920 key_info : & SecretInfo ,
935- ) -> StoreResult < Option < GossipRequest > > {
921+ ) -> Result < Option < GossipRequest > > {
936922 let requests = self . acquire ( ) . await ?. get_outgoing_secret_requests ( ) . await ?;
937923 for ( request, sent_out) in requests {
938924 let request = self . deserialize_key_request ( & request, sent_out) ?;
@@ -943,7 +929,7 @@ impl CryptoStore for SqliteCryptoStore {
943929 Ok ( None )
944930 }
945931
946- async fn get_unsent_secret_requests ( & self ) -> StoreResult < Vec < GossipRequest > > {
932+ async fn get_unsent_secret_requests ( & self ) -> Result < Vec < GossipRequest > > {
947933 self . acquire ( )
948934 . await ?
949935 . get_unsent_secret_requests ( )
@@ -956,7 +942,7 @@ impl CryptoStore for SqliteCryptoStore {
956942 . collect ( )
957943 }
958944
959- async fn delete_outgoing_secret_requests ( & self , request_id : & TransactionId ) -> StoreResult < ( ) > {
945+ async fn delete_outgoing_secret_requests ( & self , request_id : & TransactionId ) -> Result < ( ) > {
960946 let request_id = self . encode_key ( "key_requests" , request_id. as_bytes ( ) ) ;
961947 Ok ( self . acquire ( ) . await ?. delete_key_request ( request_id) . await ?)
962948 }
0 commit comments