rust: Mark room keys that are imported from the backup as backed up

This commit is contained in:
Damir Jelić 2021-11-25 11:24:47 +01:00
parent 3f710ef4c0
commit 00280ccb86
2 changed files with 8 additions and 6 deletions

View file

@ -29,11 +29,11 @@ features = ["lax_deserialize"]
[dependencies.matrix-sdk-common]
git = "https://github.com/matrix-org/matrix-rust-sdk/"
rev = "2e4d5f25cba03bd26415b91defd6e762e8c31b63"
rev = "fc74526699b82ba5be3349e810ded51138dae7fc"
[dependencies.matrix-sdk-crypto]
git = "https://github.com/matrix-org/matrix-rust-sdk/"
rev = "2e4d5f25cba03bd26415b91defd6e762e8c31b63"
rev = "fc74526699b82ba5be3349e810ded51138dae7fc"
features = ["sled_cryptostore", "qrcode", "backups_v1"]
[dependencies.tokio]

View file

@ -616,6 +616,7 @@ impl OlmMachine {
fn import_keys_helper(
&self,
keys: Vec<ExportedRoomKey>,
from_backup: bool,
progress_listener: Box<dyn ProgressListener>,
) -> Result<KeysImportResult, KeyImportError> {
let listener = |progress: usize, total: usize| {
@ -624,7 +625,7 @@ impl OlmMachine {
let result = self
.runtime
.block_on(self.inner.import_keys(keys, listener))?;
.block_on(self.inner.import_keys(keys, from_backup, listener))?;
Ok(KeysImportResult {
total: result.total_count as i64,
@ -650,14 +651,15 @@ impl OlmMachine {
) -> Result<KeysImportResult, KeyImportError> {
let keys = Cursor::new(keys);
let keys = decrypt_key_export(keys, passphrase)?;
self.import_keys_helper(keys, progress_listener)
self.import_keys_helper(keys, false, progress_listener)
}
/// Import room keys from the given serialized unencrypted key export.
///
/// This method is the same as [`OlmMachine::import_keys`] but the
/// decryption step is skipped and should be performed by the caller. This
/// may be useful for custom handling or for server-side key backups.
/// should be used if the room keys are comming from the server-side backup,
/// the method will mark all imported room keys as backed up.
///
/// # Arguments
///
@ -678,7 +680,7 @@ impl OlmMachine {
.filter_map(|k| k.ok())
.collect();
self.import_keys_helper(keys, progress_listener)
self.import_keys_helper(keys, true, progress_listener)
}
/// Discard the currently active room key for the given room if there is