From 404cc410ccc74c7cffe185a3072c7dd0400799b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Sat, 17 Oct 2020 14:39:19 +0200 Subject: [PATCH] crypto: Fix the docs and return value of the import_keys method. --- matrix_sdk/src/client.rs | 19 +++++++++++++++---- matrix_sdk_crypto/src/machine.rs | 5 +++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index a0018e1e..63b37bc5 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -1879,6 +1879,8 @@ impl Client { /// /// # Panics /// + /// This method will panic if it isn't run on a Tokio runtime. + /// /// This method will panic if it can't get enough randomness from the OS to /// encrypt the exported keys securely. /// @@ -1947,6 +1949,17 @@ impl Client { /// Import E2EE keys from the given file path. /// + /// # Arguments + /// + /// * `path` - The file path where the exported key file will can be found. + /// + /// * `passphrase` - The passphrase that should be used to decrypt the + /// exported room keys. + /// + /// # Panics + /// + /// This method will panic if it isn't run on a Tokio runtime. + /// /// ```no_run /// # use std::{path::PathBuf, time::Duration}; /// # use matrix_sdk::{ @@ -1972,7 +1985,7 @@ impl Client { feature = "docs", doc(cfg(all(encryption, not(target_arch = "wasm32")))) )] - pub async fn import_keys(&self, path: PathBuf, passphrase: &str) -> Result<()> { + pub async fn import_keys(&self, path: PathBuf, passphrase: &str) -> Result { let olm = self .base_client .olm_machine() @@ -1988,9 +2001,7 @@ impl Client { let task = tokio::task::spawn_blocking(decrypt); let import = task.await.expect("Task join error").unwrap(); - olm.import_keys(import).await.unwrap(); - - Ok(()) + Ok(olm.import_keys(import).await?) } } diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index a2b270d9..8206daff 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -906,6 +906,7 @@ impl OlmMachine { // Only import the session if we didn't have this session or if it's // a better version of the same session, that is the first known // index is lower. + // TODO load all sessions so we don't do a thousand small loads. if let Some(existing_session) = self .store .get_inbound_group_session( @@ -929,6 +930,10 @@ impl OlmMachine { let num_sessions = sessions.len(); self.store.save_inbound_group_sessions(&sessions).await?; + info!( + "Successfully imported {} inbound group sessions", + num_sessions + ); Ok(num_sessions) }