@@ -317,7 +317,38 @@ impl IndexeddbCryptoStore {
317
317
fn get_account_info ( & self ) -> Option < AccountInfo > {
318
318
self . account_info . read ( ) . unwrap ( ) . clone ( )
319
319
}
320
+ }
321
+
322
+ // Small hack to have the following macro invocation act as the appropriate
323
+ // trait impl block on wasm, but still be compiled on non-wasm as a regular
324
+ // impl block otherwise.
325
+ //
326
+ // The trait impl doesn't compile on non-wasm due to unfulfilled trait bounds,
327
+ // this hack allows us to still have most of rust-analyzer's IDE functionality
328
+ // within the impl block without having to set it up to check things against
329
+ // the wasm target (which would disable many other parts of the codebase).
330
+ #[ cfg( target_arch = "wasm32" ) ]
331
+ macro_rules! impl_crypto_store {
332
+ ( $( $body: tt) * ) => {
333
+ #[ async_trait( ?Send ) ]
334
+ impl CryptoStore for IndexeddbCryptoStore {
335
+ type Error = IndexeddbCryptoStoreError ;
336
+
337
+ $( $body) *
338
+ }
339
+ } ;
340
+ }
320
341
342
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
343
+ macro_rules! impl_crypto_store {
344
+ ( $( $body: tt) * ) => {
345
+ impl IndexeddbCryptoStore {
346
+ $( $body) *
347
+ }
348
+ } ;
349
+ }
350
+
351
+ impl_crypto_store ! {
321
352
async fn save_changes( & self , changes: Changes ) -> Result <( ) > {
322
353
let mut stores: Vec <& str > = [
323
354
( changes. account. is_some( ) || changes. private_identity. is_some( ) , KEYS :: CORE ) ,
@@ -538,7 +569,7 @@ impl IndexeddbCryptoStore {
538
569
Ok ( users)
539
570
}
540
571
541
- async fn load_outbound_group_session (
572
+ async fn get_outbound_group_session (
542
573
& self ,
543
574
room_id: & RoomId ,
544
575
) -> Result <Option <OutboundGroupSession >> {
@@ -565,9 +596,13 @@ impl IndexeddbCryptoStore {
565
596
Ok ( None )
566
597
}
567
598
}
568
- async fn get_outgoing_key_request_helper ( & self , key : & str ) -> Result < Option < GossipRequest > > {
599
+
600
+ async fn get_outgoing_secret_requests(
601
+ & self ,
602
+ request_id: & TransactionId ,
603
+ ) -> Result <Option <GossipRequest >> {
569
604
// in this internal we expect key to already be escaped or encrypted
570
- let jskey = JsValue :: from_str ( key ) ;
605
+ let jskey = JsValue :: from_str( request_id . as_str ( ) ) ;
571
606
let dbs = [ KEYS :: OUTGOING_SECRET_REQUESTS , KEYS :: UNSENT_SECRET_REQUESTS ] ;
572
607
let tx = self . inner. transaction_on_multi_with_mode( & dbs, IdbTransactionMode :: Readonly ) ?;
573
608
@@ -615,6 +650,11 @@ impl IndexeddbCryptoStore {
615
650
}
616
651
}
617
652
653
+ async fn save_account( & self , account: ReadOnlyAccount ) -> Result <( ) > {
654
+ self . save_changes( Changes { account: Some ( account) , ..Default :: default ( ) } )
655
+ . await
656
+ }
657
+
618
658
async fn load_identity( & self ) -> Result <Option <PrivateCrossSigningIdentity >> {
619
659
if let Some ( pickle) = self
620
660
. inner
@@ -829,7 +869,7 @@ impl IndexeddbCryptoStore {
829
869
. await ?
830
870
. and_then( |i| i. as_string( ) ) ;
831
871
if let Some ( id) = id {
832
- self . get_outgoing_key_request_helper ( & id ) . await
872
+ self . get_outgoing_secret_requests ( id . as_str ( ) . into ( ) ) . await
833
873
} else {
834
874
Ok ( None )
835
875
}
@@ -921,136 +961,6 @@ impl Drop for IndexeddbCryptoStore {
921
961
}
922
962
}
923
963
924
- #[ cfg( target_arch = "wasm32" ) ]
925
- #[ async_trait( ?Send ) ]
926
- impl CryptoStore for IndexeddbCryptoStore {
927
- type Error = CryptoStoreError ;
928
-
929
- async fn load_account ( & self ) -> Result < Option < ReadOnlyAccount > , CryptoStoreError > {
930
- self . load_account ( ) . await . map_err ( |e| e. into ( ) )
931
- }
932
-
933
- async fn save_account ( & self , account : ReadOnlyAccount ) -> Result < ( ) , CryptoStoreError > {
934
- self . save_changes ( Changes { account : Some ( account) , ..Default :: default ( ) } )
935
- . await
936
- . map_err ( |e| e. into ( ) )
937
- }
938
-
939
- async fn load_identity ( & self ) -> Result < Option < PrivateCrossSigningIdentity > , CryptoStoreError > {
940
- self . load_identity ( ) . await . map_err ( |e| e. into ( ) )
941
- }
942
-
943
- async fn save_changes ( & self , changes : Changes ) -> Result < ( ) , CryptoStoreError > {
944
- self . save_changes ( changes) . await . map_err ( |e| e. into ( ) )
945
- }
946
-
947
- async fn get_sessions (
948
- & self ,
949
- sender_key : & str ,
950
- ) -> Result < Option < Arc < Mutex < Vec < Session > > > > , CryptoStoreError > {
951
- self . get_sessions ( sender_key) . await . map_err ( |e| e. into ( ) )
952
- }
953
-
954
- async fn get_inbound_group_session (
955
- & self ,
956
- room_id : & RoomId ,
957
- session_id : & str ,
958
- ) -> Result < Option < InboundGroupSession > , CryptoStoreError > {
959
- self . get_inbound_group_session ( room_id, session_id) . await . map_err ( |e| e. into ( ) )
960
- }
961
-
962
- async fn get_inbound_group_sessions (
963
- & self ,
964
- ) -> Result < Vec < InboundGroupSession > , CryptoStoreError > {
965
- self . get_inbound_group_sessions ( ) . await . map_err ( |e| e. into ( ) )
966
- }
967
-
968
- async fn get_outbound_group_session (
969
- & self ,
970
- room_id : & RoomId ,
971
- ) -> Result < Option < OutboundGroupSession > , CryptoStoreError > {
972
- self . load_outbound_group_session ( room_id) . await . map_err ( |e| e. into ( ) )
973
- }
974
-
975
- async fn inbound_group_session_counts ( & self ) -> Result < RoomKeyCounts , CryptoStoreError > {
976
- self . inbound_group_session_counts ( ) . await . map_err ( |e| e. into ( ) )
977
- }
978
-
979
- async fn inbound_group_sessions_for_backup (
980
- & self ,
981
- limit : usize ,
982
- ) -> Result < Vec < InboundGroupSession > , CryptoStoreError > {
983
- self . inbound_group_sessions_for_backup ( limit) . await . map_err ( |e| e. into ( ) )
984
- }
985
-
986
- async fn reset_backup_state ( & self ) -> Result < ( ) , CryptoStoreError > {
987
- self . reset_backup_state ( ) . await . map_err ( |e| e. into ( ) )
988
- }
989
-
990
- async fn load_backup_keys ( & self ) -> Result < BackupKeys , CryptoStoreError > {
991
- self . load_backup_keys ( ) . await . map_err ( |e| e. into ( ) )
992
- }
993
-
994
- async fn save_tracked_users ( & self , users : & [ ( & UserId , bool ) ] ) -> Result < ( ) , CryptoStoreError > {
995
- self . save_tracked_users ( users) . await . map_err ( Into :: into)
996
- }
997
-
998
- async fn load_tracked_users ( & self ) -> Result < Vec < TrackedUser > , CryptoStoreError > {
999
- self . load_tracked_users ( ) . await . map_err ( Into :: into)
1000
- }
1001
-
1002
- async fn get_device (
1003
- & self ,
1004
- user_id : & UserId ,
1005
- device_id : & DeviceId ,
1006
- ) -> Result < Option < ReadOnlyDevice > , CryptoStoreError > {
1007
- self . get_device ( user_id, device_id) . await . map_err ( |e| e. into ( ) )
1008
- }
1009
-
1010
- async fn get_user_devices (
1011
- & self ,
1012
- user_id : & UserId ,
1013
- ) -> Result < HashMap < OwnedDeviceId , ReadOnlyDevice > , CryptoStoreError > {
1014
- self . get_user_devices ( user_id) . await . map_err ( |e| e. into ( ) )
1015
- }
1016
-
1017
- async fn get_user_identity (
1018
- & self ,
1019
- user_id : & UserId ,
1020
- ) -> Result < Option < ReadOnlyUserIdentities > , CryptoStoreError > {
1021
- self . get_user_identity ( user_id) . await . map_err ( |e| e. into ( ) )
1022
- }
1023
-
1024
- async fn is_message_known ( & self , hash : & OlmMessageHash ) -> Result < bool , CryptoStoreError > {
1025
- self . is_message_known ( hash) . await . map_err ( |e| e. into ( ) )
1026
- }
1027
-
1028
- async fn get_outgoing_secret_requests (
1029
- & self ,
1030
- request_id : & TransactionId ,
1031
- ) -> Result < Option < GossipRequest > , CryptoStoreError > {
1032
- self . get_outgoing_key_request_helper ( request_id. as_str ( ) ) . await . map_err ( |e| e. into ( ) )
1033
- }
1034
-
1035
- async fn get_secret_request_by_info (
1036
- & self ,
1037
- key_info : & SecretInfo ,
1038
- ) -> Result < Option < GossipRequest > , CryptoStoreError > {
1039
- self . get_secret_request_by_info ( key_info) . await . map_err ( |e| e. into ( ) )
1040
- }
1041
-
1042
- async fn get_unsent_secret_requests ( & self ) -> Result < Vec < GossipRequest > , CryptoStoreError > {
1043
- self . get_unsent_secret_requests ( ) . await . map_err ( |e| e. into ( ) )
1044
- }
1045
-
1046
- async fn delete_outgoing_secret_requests (
1047
- & self ,
1048
- request_id : & TransactionId ,
1049
- ) -> Result < ( ) , CryptoStoreError > {
1050
- self . delete_outgoing_secret_requests ( request_id) . await . map_err ( |e| e. into ( ) )
1051
- }
1052
- }
1053
-
1054
964
#[ cfg( all( test, target_arch = "wasm32" ) ) ]
1055
965
mod tests {
1056
966
use matrix_sdk_crypto:: cryptostore_integration_tests;
0 commit comments