@@ -55,6 +55,7 @@ pub struct MemoryStore {
55
55
sessions : SessionStore ,
56
56
inbound_group_sessions : GroupSessionStore ,
57
57
outbound_group_sessions : StdRwLock < BTreeMap < OwnedRoomId , OutboundGroupSession > > ,
58
+ private_identity : StdRwLock < Option < PrivateCrossSigningIdentity > > ,
58
59
tracked_users : StdRwLock < Vec < TrackedUser > > ,
59
60
olm_hashes : StdRwLock < HashMap < String , HashSet < String > > > ,
60
61
devices : DeviceStore ,
@@ -77,6 +78,7 @@ impl Default for MemoryStore {
77
78
sessions : SessionStore :: new ( ) ,
78
79
inbound_group_sessions : GroupSessionStore :: new ( ) ,
79
80
outbound_group_sessions : Default :: default ( ) ,
81
+ private_identity : Default :: default ( ) ,
80
82
tracked_users : Default :: default ( ) ,
81
83
olm_hashes : Default :: default ( ) ,
82
84
devices : DeviceStore :: new ( ) ,
@@ -130,6 +132,10 @@ impl MemoryStore {
130
132
. unwrap ( )
131
133
. extend ( sessions. into_iter ( ) . map ( |s| ( s. room_id ( ) . to_owned ( ) , s) ) ) ;
132
134
}
135
+
136
+ fn save_private_identity ( & self , private_identity : Option < PrivateCrossSigningIdentity > ) {
137
+ * self . private_identity . write ( ) . unwrap ( ) = private_identity;
138
+ }
133
139
}
134
140
135
141
type Result < T > = std:: result:: Result < T , Infallible > ;
@@ -144,7 +150,7 @@ impl CryptoStore for MemoryStore {
144
150
}
145
151
146
152
async fn load_identity ( & self ) -> Result < Option < PrivateCrossSigningIdentity > > {
147
- Ok ( None )
153
+ Ok ( self . private_identity . read ( ) . unwrap ( ) . clone ( ) )
148
154
}
149
155
150
156
async fn next_batch_token ( & self ) -> Result < Option < String > > {
@@ -163,6 +169,7 @@ impl CryptoStore for MemoryStore {
163
169
self . save_sessions ( changes. sessions ) . await ;
164
170
self . save_inbound_group_sessions ( changes. inbound_group_sessions ) ;
165
171
self . save_outbound_group_sessions ( changes. outbound_group_sessions ) ;
172
+ self . save_private_identity ( changes. private_identity ) ;
166
173
167
174
self . save_devices ( changes. devices . new ) ;
168
175
self . save_devices ( changes. devices . changed ) ;
@@ -482,7 +489,10 @@ mod tests {
482
489
483
490
use crate :: {
484
491
identities:: device:: testing:: get_device,
485
- olm:: { tests:: get_account_and_session_test_helper, InboundGroupSession , OlmMessageHash } ,
492
+ olm:: {
493
+ tests:: get_account_and_session_test_helper, InboundGroupSession , OlmMessageHash ,
494
+ PrivateCrossSigningIdentity ,
495
+ } ,
486
496
store:: { memorystore:: MemoryStore , Changes , CryptoStore , PendingChanges } ,
487
497
} ;
488
498
@@ -568,6 +578,22 @@ mod tests {
568
578
assert_eq ! ( loaded_tracked_users. len( ) , 2 ) ;
569
579
}
570
580
581
+ #[ async_test]
582
+ async fn test_private_identity_store ( ) {
583
+ // Given a private identity
584
+ let private_identity = PrivateCrossSigningIdentity :: empty ( user_id ! ( "@u:s" ) ) ;
585
+
586
+ // When we save it to the store
587
+ let store = MemoryStore :: new ( ) ;
588
+ store. save_private_identity ( Some ( private_identity. clone ( ) ) ) ;
589
+
590
+ // Then we can get it out again
591
+ let loaded_identity =
592
+ store. load_identity ( ) . await . expect ( "failed to load private identity" ) . unwrap ( ) ;
593
+
594
+ assert_eq ! ( loaded_identity. user_id( ) , user_id!( "@u:s" ) ) ;
595
+ }
596
+
571
597
#[ async_test]
572
598
async fn test_device_store ( ) {
573
599
let device = get_device ( ) ;
0 commit comments