@@ -27,10 +27,7 @@ use matrix_sdk_crypto::{
27
27
IdentityKeys , InboundGroupSession , OutboundGroupSession , PickledInboundGroupSession ,
28
28
PrivateCrossSigningIdentity , Session ,
29
29
} ,
30
- store:: {
31
- caches:: SessionStore , BackupKeys , Changes , CryptoStore , CryptoStoreError ,
32
- Result as StoreResult , RoomKeyCounts ,
33
- } ,
30
+ store:: { caches:: SessionStore , BackupKeys , Changes , CryptoStore , RoomKeyCounts } ,
34
31
GossipRequest , ReadOnlyAccount , ReadOnlyDevice , ReadOnlyUserIdentities , SecretInfo ,
35
32
TrackedUser ,
36
33
} ;
@@ -525,14 +522,14 @@ impl SqliteObjectCryptoStoreExt for deadpool_sqlite::Object {}
525
522
526
523
#[ async_trait]
527
524
impl CryptoStore for SqliteCryptoStore {
528
- type Error = CryptoStoreError ;
525
+ type Error = Error ;
529
526
530
- async fn load_account ( & self ) -> StoreResult < Option < ReadOnlyAccount > > {
527
+ async fn load_account ( & self ) -> Result < Option < ReadOnlyAccount > > {
531
528
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 ? {
533
530
let pickle = self . deserialize_value ( & pickle) ?;
534
531
535
- let account = ReadOnlyAccount :: from_pickle ( pickle) ?;
532
+ let account = ReadOnlyAccount :: from_pickle ( pickle) . map_err ( |_| Error :: Unpickle ) ?;
536
533
537
534
let account_info = AccountInfo {
538
535
user_id : account. user_id . clone ( ) ,
@@ -548,7 +545,7 @@ impl CryptoStore for SqliteCryptoStore {
548
545
}
549
546
}
550
547
551
- async fn save_account ( & self , account : ReadOnlyAccount ) -> StoreResult < ( ) > {
548
+ async fn save_account ( & self , account : ReadOnlyAccount ) -> Result < ( ) > {
552
549
let account_info = AccountInfo {
553
550
user_id : account. user_id . clone ( ) ,
554
551
device_id : account. device_id . clone ( ) ,
@@ -558,29 +555,25 @@ impl CryptoStore for SqliteCryptoStore {
558
555
559
556
let pickled_account = account. pickle ( ) . await ;
560
557
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 ?;
566
559
Ok ( ( ) )
567
560
}
568
561
569
- async fn load_identity ( & self ) -> StoreResult < Option < PrivateCrossSigningIdentity > > {
562
+ async fn load_identity ( & self ) -> Result < Option < PrivateCrossSigningIdentity > > {
570
563
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 ? {
572
565
let pickle = self . deserialize_value ( & i) ?;
573
566
Ok ( Some (
574
567
PrivateCrossSigningIdentity :: from_pickle ( pickle)
575
568
. await
576
- . map_err ( |_| CryptoStoreError :: UnpicklingError ) ?,
569
+ . map_err ( |_| Error :: Unpickle ) ?,
577
570
) )
578
571
} else {
579
572
Ok ( None )
580
573
}
581
574
}
582
575
583
- async fn save_changes ( & self , changes : Changes ) -> StoreResult < ( ) > {
576
+ async fn save_changes ( & self , changes : Changes ) -> Result < ( ) > {
584
577
let pickled_account = if let Some ( account) = changes. account {
585
578
let account_info = AccountInfo {
586
579
user_id : account. user_id . clone ( ) ,
@@ -704,11 +697,8 @@ impl CryptoStore for SqliteCryptoStore {
704
697
Ok ( ( ) )
705
698
}
706
699
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 ) ?;
712
702
713
703
if self . session_cache . get ( sender_key) . is_none ( ) {
714
704
let sessions = self
@@ -739,7 +729,7 @@ impl CryptoStore for SqliteCryptoStore {
739
729
& self ,
740
730
room_id : & RoomId ,
741
731
session_id : & str ,
742
- ) -> StoreResult < Option < InboundGroupSession > > {
732
+ ) -> Result < Option < InboundGroupSession > > {
743
733
let session_id = self . encode_key ( "inbound_group_session" , session_id) ;
744
734
let Some ( ( room_id_from_db, value) ) =
745
735
self . acquire ( ) . await ?. get_inbound_group_session ( session_id) . await ?
@@ -758,7 +748,7 @@ impl CryptoStore for SqliteCryptoStore {
758
748
Ok ( Some ( InboundGroupSession :: from_pickle ( pickle) ?) )
759
749
}
760
750
761
- async fn get_inbound_group_sessions ( & self ) -> StoreResult < Vec < InboundGroupSession > > {
751
+ async fn get_inbound_group_sessions ( & self ) -> Result < Vec < InboundGroupSession > > {
762
752
self . acquire ( )
763
753
. await ?
764
754
. get_inbound_group_sessions ( )
@@ -771,14 +761,14 @@ impl CryptoStore for SqliteCryptoStore {
771
761
. collect ( )
772
762
}
773
763
774
- async fn inbound_group_session_counts ( & self ) -> StoreResult < RoomKeyCounts > {
764
+ async fn inbound_group_session_counts ( & self ) -> Result < RoomKeyCounts > {
775
765
Ok ( self . acquire ( ) . await ?. get_inbound_group_session_counts ( ) . await ?)
776
766
}
777
767
778
768
async fn inbound_group_sessions_for_backup (
779
769
& self ,
780
770
limit : usize ,
781
- ) -> StoreResult < Vec < InboundGroupSession > > {
771
+ ) -> Result < Vec < InboundGroupSession > > {
782
772
self . acquire ( )
783
773
. await ?
784
774
. get_inbound_group_sessions_for_backup ( limit)
@@ -791,24 +781,22 @@ impl CryptoStore for SqliteCryptoStore {
791
781
. collect ( )
792
782
}
793
783
794
- async fn reset_backup_state ( & self ) -> StoreResult < ( ) > {
784
+ async fn reset_backup_state ( & self ) -> Result < ( ) > {
795
785
Ok ( self . acquire ( ) . await ?. reset_inbound_group_session_backup_state ( ) . await ?)
796
786
}
797
787
798
- async fn load_backup_keys ( & self ) -> StoreResult < BackupKeys > {
788
+ async fn load_backup_keys ( & self ) -> Result < BackupKeys > {
799
789
let conn = self . acquire ( ) . await ?;
800
790
801
791
let backup_version = conn
802
792
. get_kv ( "backup_version_v1" )
803
- . await
804
- . map_err ( CryptoStoreError :: backend) ?
793
+ . await ?
805
794
. map ( |value| self . deserialize_value ( & value) )
806
795
. transpose ( ) ?;
807
796
808
797
let recovery_key = conn
809
798
. get_kv ( "recovery_key_v1" )
810
- . await
811
- . map_err ( CryptoStoreError :: backend) ?
799
+ . await ?
812
800
. map ( |value| self . deserialize_value ( & value) )
813
801
. transpose ( ) ?;
814
802
@@ -818,35 +806,36 @@ impl CryptoStore for SqliteCryptoStore {
818
806
async fn get_outbound_group_session (
819
807
& self ,
820
808
room_id : & RoomId ,
821
- ) -> StoreResult < Option < OutboundGroupSession > > {
809
+ ) -> Result < Option < OutboundGroupSession > > {
822
810
let room_id = self . encode_key ( "outbound_group_session" , room_id. as_bytes ( ) ) ;
823
811
let Some ( value) = self . acquire ( ) . await ?. get_outbound_group_session ( room_id) . await ? else {
824
812
return Ok ( None ) ;
825
813
} ;
826
814
827
- let account_info = self . get_account_info ( ) . ok_or ( CryptoStoreError :: AccountUnset ) ?;
815
+ let account_info = self . get_account_info ( ) . ok_or ( Error :: AccountUnset ) ?;
828
816
829
817
let pickle = self . deserialize_value ( & value) ?;
830
818
let session = OutboundGroupSession :: from_pickle (
831
819
account_info. device_id ,
832
820
account_info. identity_keys ,
833
821
pickle,
834
- ) ?;
822
+ )
823
+ . map_err ( |_| Error :: Unpickle ) ?;
835
824
836
825
return Ok ( Some ( session) ) ;
837
826
}
838
827
839
- async fn load_tracked_users ( & self ) -> StoreResult < Vec < TrackedUser > > {
828
+ async fn load_tracked_users ( & self ) -> Result < Vec < TrackedUser > > {
840
829
self . acquire ( )
841
830
. await ?
842
831
. get_tracked_users ( )
843
832
. await ?
844
833
. iter ( )
845
- . map ( |value| Ok ( self . deserialize_value ( value) ? ) )
834
+ . map ( |value| self . deserialize_value ( value) )
846
835
. collect ( )
847
836
}
848
837
849
- async fn save_tracked_users ( & self , tracked_users : & [ ( & UserId , bool ) ] ) -> StoreResult < ( ) > {
838
+ async fn save_tracked_users ( & self , tracked_users : & [ ( & UserId , bool ) ] ) -> Result < ( ) > {
850
839
let users: Vec < ( Key , Vec < u8 > ) > = tracked_users
851
840
. iter ( )
852
841
. map ( |( u, d) | {
@@ -864,7 +853,7 @@ impl CryptoStore for SqliteCryptoStore {
864
853
& self ,
865
854
user_id : & UserId ,
866
855
device_id : & DeviceId ,
867
- ) -> StoreResult < Option < ReadOnlyDevice > > {
856
+ ) -> Result < Option < ReadOnlyDevice > > {
868
857
let user_id = self . encode_key ( "device" , user_id. as_bytes ( ) ) ;
869
858
let device_id = self . encode_key ( "device" , device_id. as_bytes ( ) ) ;
870
859
Ok ( self
@@ -879,7 +868,7 @@ impl CryptoStore for SqliteCryptoStore {
879
868
async fn get_user_devices (
880
869
& self ,
881
870
user_id : & UserId ,
882
- ) -> StoreResult < HashMap < OwnedDeviceId , ReadOnlyDevice > > {
871
+ ) -> Result < HashMap < OwnedDeviceId , ReadOnlyDevice > > {
883
872
let user_id = self . encode_key ( "device" , user_id. as_bytes ( ) ) ;
884
873
self . acquire ( )
885
874
. await ?
@@ -893,10 +882,7 @@ impl CryptoStore for SqliteCryptoStore {
893
882
. collect ( )
894
883
}
895
884
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 > > {
900
886
let user_id = self . encode_key ( "identity" , user_id. as_bytes ( ) ) ;
901
887
Ok ( self
902
888
. acquire ( )
@@ -910,15 +896,15 @@ impl CryptoStore for SqliteCryptoStore {
910
896
async fn is_message_known (
911
897
& self ,
912
898
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) ?;
915
901
Ok ( self . acquire ( ) . await ?. has_olm_hash ( value) . await ?)
916
902
}
917
903
918
904
async fn get_outgoing_secret_requests (
919
905
& self ,
920
906
request_id : & TransactionId ,
921
- ) -> StoreResult < Option < GossipRequest > > {
907
+ ) -> Result < Option < GossipRequest > > {
922
908
let request_id = self . encode_key ( "key_requests" , request_id. as_bytes ( ) ) ;
923
909
Ok ( self
924
910
. acquire ( )
@@ -932,7 +918,7 @@ impl CryptoStore for SqliteCryptoStore {
932
918
async fn get_secret_request_by_info (
933
919
& self ,
934
920
key_info : & SecretInfo ,
935
- ) -> StoreResult < Option < GossipRequest > > {
921
+ ) -> Result < Option < GossipRequest > > {
936
922
let requests = self . acquire ( ) . await ?. get_outgoing_secret_requests ( ) . await ?;
937
923
for ( request, sent_out) in requests {
938
924
let request = self . deserialize_key_request ( & request, sent_out) ?;
@@ -943,7 +929,7 @@ impl CryptoStore for SqliteCryptoStore {
943
929
Ok ( None )
944
930
}
945
931
946
- async fn get_unsent_secret_requests ( & self ) -> StoreResult < Vec < GossipRequest > > {
932
+ async fn get_unsent_secret_requests ( & self ) -> Result < Vec < GossipRequest > > {
947
933
self . acquire ( )
948
934
. await ?
949
935
. get_unsent_secret_requests ( )
@@ -956,7 +942,7 @@ impl CryptoStore for SqliteCryptoStore {
956
942
. collect ( )
957
943
}
958
944
959
- async fn delete_outgoing_secret_requests ( & self , request_id : & TransactionId ) -> StoreResult < ( ) > {
945
+ async fn delete_outgoing_secret_requests ( & self , request_id : & TransactionId ) -> Result < ( ) > {
960
946
let request_id = self . encode_key ( "key_requests" , request_id. as_bytes ( ) ) ;
961
947
Ok ( self . acquire ( ) . await ?. delete_key_request ( request_id) . await ?)
962
948
}
0 commit comments