crypto: Put a bunch of crypto store stuff behind atomic references.

master
Damir Jelić 2020-08-11 15:17:33 +02:00
parent 2437a92998
commit 707b4c1185
2 changed files with 13 additions and 13 deletions

View File

@ -30,8 +30,8 @@ use crate::{
pub struct MemoryStore { pub struct MemoryStore {
sessions: SessionStore, sessions: SessionStore,
inbound_group_sessions: GroupSessionStore, inbound_group_sessions: GroupSessionStore,
tracked_users: DashSet<UserId>, tracked_users: Arc<DashSet<UserId>>,
users_for_key_query: DashSet<UserId>, users_for_key_query: Arc<DashSet<UserId>>,
devices: DeviceStore, devices: DeviceStore,
} }
@ -40,8 +40,8 @@ impl MemoryStore {
MemoryStore { MemoryStore {
sessions: SessionStore::new(), sessions: SessionStore::new(),
inbound_group_sessions: GroupSessionStore::new(), inbound_group_sessions: GroupSessionStore::new(),
tracked_users: DashSet::new(), tracked_users: Arc::new(DashSet::new()),
users_for_key_query: DashSet::new(), users_for_key_query: Arc::new(DashSet::new()),
devices: DeviceStore::new(), devices: DeviceStore::new(),
} }
} }

View File

@ -45,16 +45,16 @@ pub struct SqliteStore {
user_id: Arc<UserId>, user_id: Arc<UserId>,
device_id: Arc<Box<DeviceId>>, device_id: Arc<Box<DeviceId>>,
account_info: Arc<SyncMutex<Option<AccountInfo>>>, account_info: Arc<SyncMutex<Option<AccountInfo>>>,
path: PathBuf, path: Arc<PathBuf>,
sessions: SessionStore, sessions: SessionStore,
inbound_group_sessions: GroupSessionStore, inbound_group_sessions: GroupSessionStore,
devices: DeviceStore, devices: DeviceStore,
tracked_users: DashSet<UserId>, tracked_users: Arc<DashSet<UserId>>,
users_for_key_query: DashSet<UserId>, users_for_key_query: Arc<DashSet<UserId>>,
connection: Arc<Mutex<SqliteConnection>>, connection: Arc<Mutex<SqliteConnection>>,
pickle_passphrase: Option<Zeroizing<String>>, pickle_passphrase: Arc<Option<Zeroizing<String>>>,
} }
#[derive(Clone)] #[derive(Clone)]
@ -136,11 +136,11 @@ impl SqliteStore {
sessions: SessionStore::new(), sessions: SessionStore::new(),
inbound_group_sessions: GroupSessionStore::new(), inbound_group_sessions: GroupSessionStore::new(),
devices: DeviceStore::new(), devices: DeviceStore::new(),
path: path.as_ref().to_owned(), path: Arc::new(path.as_ref().to_owned()),
connection: Arc::new(Mutex::new(connection)), connection: Arc::new(Mutex::new(connection)),
pickle_passphrase: passphrase, pickle_passphrase: Arc::new(passphrase),
tracked_users: DashSet::new(), tracked_users: Arc::new(DashSet::new()),
users_for_key_query: DashSet::new(), users_for_key_query: Arc::new(DashSet::new()),
}; };
store.create_tables().await?; store.create_tables().await?;
Ok(store) Ok(store)
@ -652,7 +652,7 @@ impl SqliteStore {
} }
fn get_pickle_mode(&self) -> PicklingMode { fn get_pickle_mode(&self) -> PicklingMode {
match &self.pickle_passphrase { match &*self.pickle_passphrase {
Some(p) => PicklingMode::Encrypted { Some(p) => PicklingMode::Encrypted {
key: p.as_bytes().to_vec(), key: p.as_bytes().to_vec(),
}, },