Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: Remove inner mutable shared state from Account #2710

Merged
merged 19 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
47e8b5b
crypto: introduce `StoreCache::account()` function
bnjbvr Oct 9, 2023
0cb0df0
crypto: get rid of test-only `OlmMachine::account`
bnjbvr Oct 9, 2023
02851f2
crypto: make `StoreCache::account` fallible and async
bnjbvr Oct 9, 2023
621c831
crypto: make `Account` not clonable and the `Account` in the cache op…
bnjbvr Oct 10, 2023
b591f69
crypto: remove inner mutable shared state from `Account`
bnjbvr Oct 12, 2023
5f0cb97
crypto: introduce a RwLock on the StoreCache
bnjbvr Oct 12, 2023
0d80ffd
crypto: move `Store::ensure_sync_tracked_users` to the `StoreCache`
bnjbvr Oct 13, 2023
46de942
crypto: move `Store::mark_tracked_users_as_changed` to `StoreCache`
bnjbvr Oct 13, 2023
0473411
crypto: fix test failure
bnjbvr Oct 13, 2023
79dd48b
crypto: move `Store::mark_user_as_changed` to the `StoreCache` too
bnjbvr Oct 16, 2023
b825d5b
crypto: remove useless call to `self.cache` in Store::users_for_key_q…
bnjbvr Oct 16, 2023
1c0814e
crypto: move `Store::update_tracked_users` to the `StoreCache`
bnjbvr Oct 16, 2023
0b958c8
crypto: remove useless parameter in `receive_device_changes`
bnjbvr Oct 16, 2023
e15e761
crypto: move `Store::tracked_users` to `StoreCache`
bnjbvr Oct 16, 2023
7eb71f9
crypto: move `Store::mark_tracked_users_as_up_to_date` to the `StoreC…
bnjbvr Oct 16, 2023
b369d4a
test: use unwrap() instead of `Result` in a test
bnjbvr Oct 20, 2023
3f4ce43
store cache: copy the account back into the cache if there were pendi…
bnjbvr Oct 20, 2023
7354dba
account: make it more obvious what `Account::clone_internal` is, so i…
bnjbvr Oct 20, 2023
652ebed
style: use not().then() in one place
bnjbvr Oct 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions bindings/matrix-sdk-crypto-ffi/src/dehydrated_devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ impl Drop for DehydratedDevices {

#[uniffi::export]
impl DehydratedDevices {
pub fn create(&self) -> Arc<DehydratedDevice> {
DehydratedDevice {
inner: ManuallyDrop::new(self.inner.create()),
pub fn create(&self) -> Result<Arc<DehydratedDevice>, DehydrationError> {
let inner = self.runtime.block_on(self.inner.create())?;

Ok(Arc::new(DehydratedDevice {
inner: ManuallyDrop::new(inner),
runtime: self.runtime.to_owned(),
}
.into()
}))
}

pub fn rehydrate(
Expand Down
22 changes: 12 additions & 10 deletions crates/matrix-sdk-crypto/src/dehydrated_devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub struct DehydratedDevices {

impl DehydratedDevices {
/// Create a new [`DehydratedDevice`] which can be uploaded to the server.
pub fn create(&self) -> DehydratedDevice {
pub async fn create(&self) -> Result<DehydratedDevice, DehydrationError> {
let user_id = self.inner.user_id();
let user_identity = self.inner.store().private_identity();

Expand All @@ -104,9 +104,11 @@ impl DehydratedDevices {
store.clone(),
);

let store = Store::new(account, user_identity, store, verification_machine);
let store =
Store::new(account.static_data().clone(), user_identity, store, verification_machine);
store.save_pending_changes(crate::store::PendingChanges { account: Some(account) }).await?;

DehydratedDevice { store }
Ok(DehydratedDevice { store })
}

/// Rehydrate the dehydrated device.
Expand Down Expand Up @@ -289,7 +291,7 @@ impl DehydratedDevice {
/// let pickle_key = [0u8; 32];
///
/// // Create the dehydrated device.
/// let device = machine.dehydrated_devices().create();
/// let device = machine.dehydrated_devices().create().await?;
///
/// // Create the request that should upload the device.
/// let request = device
Expand All @@ -316,9 +318,9 @@ impl DehydratedDevice {
let mut transaction = self.store.transaction().await?;

let account = transaction.account().await?;
account.generate_fallback_key_helper().await;
account.generate_fallback_key_helper();

let (device_keys, one_time_keys, fallback_keys) = account.keys_for_upload().await;
let (device_keys, one_time_keys, fallback_keys) = account.keys_for_upload();

let mut device_keys = device_keys
.expect("We should always try to upload device keys for a dehydrated device.");
Expand All @@ -329,7 +331,7 @@ impl DehydratedDevice {

let pickle_key = expand_pickle_key(pickle_key, &self.store.static_account().device_id);
let device_id = self.store.static_account().device_id.clone();
let device_data = account.dehydrate(&pickle_key).await;
let device_data = account.dehydrate(&pickle_key);
let initial_device_display_name = Some(initial_device_display_name);

transaction.commit().await?;
Expand Down Expand Up @@ -456,10 +458,10 @@ mod tests {
}

#[async_test]
async fn dehydrated_device_creation() {
async fn test_dehydrated_device_creation() {
let olm_machine = get_olm_machine().await;

let dehydrated_device = olm_machine.dehydrated_devices().create();
let dehydrated_device = olm_machine.dehydrated_devices().create().await.unwrap();

let request = dehydrated_device
.keys_for_upload("Foo".to_owned(), PICKLE_KEY)
Expand All @@ -482,7 +484,7 @@ mod tests {
let room_id = room_id!("!test:example.org");
let alice = get_olm_machine().await;

let dehydrated_device = alice.dehydrated_devices().create();
let dehydrated_device = alice.dehydrated_devices().create().await.unwrap();

let mut request = dehydrated_device
.keys_for_upload("Foo".to_owned(), PICKLE_KEY)
Expand Down
Loading