crypto: Implement storage for the user identities in the memory store.
parent
38cf771f1f
commit
37a7f69e03
|
@ -15,7 +15,7 @@
|
||||||
use std::{collections::HashSet, sync::Arc};
|
use std::{collections::HashSet, sync::Arc};
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use dashmap::DashSet;
|
use dashmap::{DashMap, DashSet};
|
||||||
use matrix_sdk_common::{
|
use matrix_sdk_common::{
|
||||||
identifiers::{DeviceId, RoomId, UserId},
|
identifiers::{DeviceId, RoomId, UserId},
|
||||||
locks::Mutex,
|
locks::Mutex,
|
||||||
|
@ -34,6 +34,7 @@ pub struct MemoryStore {
|
||||||
tracked_users: Arc<DashSet<UserId>>,
|
tracked_users: Arc<DashSet<UserId>>,
|
||||||
users_for_key_query: Arc<DashSet<UserId>>,
|
users_for_key_query: Arc<DashSet<UserId>>,
|
||||||
devices: DeviceStore,
|
devices: DeviceStore,
|
||||||
|
identities: Arc<DashMap<UserId, UserIdentities>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MemoryStore {
|
impl MemoryStore {
|
||||||
|
@ -44,6 +45,7 @@ impl MemoryStore {
|
||||||
tracked_users: Arc::new(DashSet::new()),
|
tracked_users: Arc::new(DashSet::new()),
|
||||||
users_for_key_query: Arc::new(DashSet::new()),
|
users_for_key_query: Arc::new(DashSet::new()),
|
||||||
devices: DeviceStore::new(),
|
devices: DeviceStore::new(),
|
||||||
|
identities: Arc::new(DashMap::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,8 +135,18 @@ impl CryptoStore for MemoryStore {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_user_identity(&self, _user_id: &UserId) -> Result<Option<UserIdentities>> {
|
async fn get_user_identity(&self, user_id: &UserId) -> Result<Option<UserIdentities>> {
|
||||||
Ok(None)
|
#[allow(clippy::map_clone)]
|
||||||
|
Ok(self.identities.get(user_id).map(|i| i.clone()))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn save_user_identities(&self, identities: &[UserIdentities]) -> Result<()> {
|
||||||
|
for identity in identities {
|
||||||
|
let _ = self
|
||||||
|
.identities
|
||||||
|
.insert(identity.user_id().to_owned(), identity.clone());
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -199,6 +199,13 @@ pub trait CryptoStore: Debug {
|
||||||
/// * `user_id` - The user for which we should get all the devices.
|
/// * `user_id` - The user for which we should get all the devices.
|
||||||
async fn get_user_devices(&self, user_id: &UserId) -> Result<ReadOnlyUserDevices>;
|
async fn get_user_devices(&self, user_id: &UserId) -> Result<ReadOnlyUserDevices>;
|
||||||
|
|
||||||
|
/// Save the given user identities in the store.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `identities` - The identities that should be saved in the store.
|
||||||
|
async fn save_user_identities(&self, identities: &[UserIdentities]) -> Result<()>;
|
||||||
|
|
||||||
/// Get the user identity that is attached to the given user id.
|
/// Get the user identity that is attached to the given user id.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
|
|
@ -888,6 +888,10 @@ impl CryptoStore for SqliteStore {
|
||||||
async fn get_user_identity(&self, _user_id: &UserId) -> Result<Option<UserIdentities>> {
|
async fn get_user_identity(&self, _user_id: &UserId) -> Result<Option<UserIdentities>> {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn save_user_identities(&self, _users: &[UserIdentities]) -> Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
#[cfg(not(tarpaulin_include))]
|
||||||
|
|
|
@ -153,6 +153,13 @@ pub enum UserIdentities {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UserIdentities {
|
impl UserIdentities {
|
||||||
|
pub fn user_id(&self) -> &UserId {
|
||||||
|
match self {
|
||||||
|
UserIdentities::Own(i) => i.user_id(),
|
||||||
|
UserIdentities::Other(i) => i.user_id(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn master_key(&self) -> &BTreeMap<String, String> {
|
pub fn master_key(&self) -> &BTreeMap<String, String> {
|
||||||
match self {
|
match self {
|
||||||
UserIdentities::Own(i) => i.master_key(),
|
UserIdentities::Own(i) => i.master_key(),
|
||||||
|
@ -182,6 +189,10 @@ impl UserIdentity {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn user_id(&self) -> &UserId {
|
||||||
|
&self.user_id
|
||||||
|
}
|
||||||
|
|
||||||
pub fn master_key(&self) -> &BTreeMap<String, String> {
|
pub fn master_key(&self) -> &BTreeMap<String, String> {
|
||||||
&self.master_key.0.keys
|
&self.master_key.0.keys
|
||||||
}
|
}
|
||||||
|
@ -231,6 +242,10 @@ impl OwnUserIdentity {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn user_id(&self) -> &UserId {
|
||||||
|
&self.user_id
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update(
|
pub fn update(
|
||||||
&mut self,
|
&mut self,
|
||||||
master_key: MasterPubkey,
|
master_key: MasterPubkey,
|
||||||
|
|
Loading…
Reference in New Issue