mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-09 00:15:23 -04:00
crypto: Use new CryptoStore::save_inbound_group_sessions method
When we are importing a batch of room keys, use the newly-added `CryptoStore::save_inbound_group_sessions` method instead of `CryptoStore::save_changes`. To do this, we need to pass the backup version into `Store::import_room_keys` instead of just `from_backup` flag.
This commit is contained in:
@@ -619,7 +619,15 @@ impl BackupMachine {
|
||||
}
|
||||
}
|
||||
|
||||
self.store.import_room_keys(decrypted_room_keys, true, progress_listener).await
|
||||
// FIXME: This method is a bit flawed: we have no real idea which backup version
|
||||
// these keys came from. For example, we might have reset the backup
|
||||
// since the keys were downloaded. For now, let's assume they came from
|
||||
// the "current" backup version.
|
||||
let backup_version = self.backup_version().await;
|
||||
|
||||
self.store
|
||||
.import_room_keys(decrypted_room_keys, backup_version.as_deref(), progress_listener)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1823,7 +1823,11 @@ impl OlmMachine {
|
||||
from_backup: bool,
|
||||
progress_listener: impl Fn(usize, usize),
|
||||
) -> StoreResult<RoomKeyImportResult> {
|
||||
self.store().import_room_keys(exported_keys, from_backup, progress_listener).await
|
||||
let backup_version =
|
||||
if from_backup { self.backup_machine().backup_version().await } else { None };
|
||||
self.store()
|
||||
.import_room_keys(exported_keys, backup_version.as_deref(), progress_listener)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Get the status of the private cross signing keys.
|
||||
|
||||
@@ -1630,10 +1630,22 @@ impl Store {
|
||||
self.inner.store.secrets_stream()
|
||||
}
|
||||
|
||||
/// Import the given room keys into the store.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `exported_keys` - The keys to be imported.
|
||||
/// * `from_backup_version` - If the keys came from key backup, the key
|
||||
/// backup version. This will cause the keys to be marked as already
|
||||
/// backed up, and therefore not requiring another backup.
|
||||
/// * `progress_listener` - Callback which will be called after each key is
|
||||
/// processed. Called with arguments `(processed, total)` where
|
||||
/// `processed` is the number of keys processed so far, and `total` is the
|
||||
/// total number of keys (i.e., `exported_keys.len()`).
|
||||
pub(crate) async fn import_room_keys(
|
||||
&self,
|
||||
exported_keys: Vec<ExportedRoomKey>,
|
||||
from_backup: bool,
|
||||
from_backup_version: Option<&str>,
|
||||
progress_listener: impl Fn(usize, usize),
|
||||
) -> Result<RoomKeyImportResult> {
|
||||
let mut sessions = Vec::new();
|
||||
@@ -1664,7 +1676,7 @@ impl Store {
|
||||
// Only import the session if we didn't have this session or
|
||||
// if it's a better version of the same session.
|
||||
if new_session_better(&session, old_session).await {
|
||||
if from_backup {
|
||||
if from_backup_version.is_some() {
|
||||
session.mark_as_backed_up();
|
||||
}
|
||||
|
||||
@@ -1693,9 +1705,7 @@ impl Store {
|
||||
|
||||
let imported_count = sessions.len();
|
||||
|
||||
let changes = Changes { inbound_group_sessions: sessions, ..Default::default() };
|
||||
|
||||
self.save_changes(changes).await?;
|
||||
self.inner.store.save_inbound_group_sessions(sessions, from_backup_version).await?;
|
||||
|
||||
info!(total_count, imported_count, room_keys = ?keys, "Successfully imported room keys");
|
||||
|
||||
@@ -1733,7 +1743,7 @@ impl Store {
|
||||
exported_keys: Vec<ExportedRoomKey>,
|
||||
progress_listener: impl Fn(usize, usize),
|
||||
) -> Result<RoomKeyImportResult> {
|
||||
self.import_room_keys(exported_keys, false, progress_listener).await
|
||||
self.import_room_keys(exported_keys, None, progress_listener).await
|
||||
}
|
||||
|
||||
pub(crate) fn crypto_store(&self) -> Arc<CryptoStoreWrapper> {
|
||||
|
||||
Reference in New Issue
Block a user