crypto: Fix the docs and return value of the import_keys method.

master
Damir Jelić 2020-10-17 14:39:19 +02:00
parent 17cc4fcb81
commit 404cc410cc
2 changed files with 20 additions and 4 deletions

View File

@ -1879,6 +1879,8 @@ impl Client {
/// ///
/// # Panics /// # 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 /// This method will panic if it can't get enough randomness from the OS to
/// encrypt the exported keys securely. /// encrypt the exported keys securely.
/// ///
@ -1947,6 +1949,17 @@ impl Client {
/// Import E2EE keys from the given file path. /// 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 /// ```no_run
/// # use std::{path::PathBuf, time::Duration}; /// # use std::{path::PathBuf, time::Duration};
/// # use matrix_sdk::{ /// # use matrix_sdk::{
@ -1972,7 +1985,7 @@ impl Client {
feature = "docs", feature = "docs",
doc(cfg(all(encryption, not(target_arch = "wasm32")))) 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<usize> {
let olm = self let olm = self
.base_client .base_client
.olm_machine() .olm_machine()
@ -1988,9 +2001,7 @@ impl Client {
let task = tokio::task::spawn_blocking(decrypt); let task = tokio::task::spawn_blocking(decrypt);
let import = task.await.expect("Task join error").unwrap(); let import = task.await.expect("Task join error").unwrap();
olm.import_keys(import).await.unwrap(); Ok(olm.import_keys(import).await?)
Ok(())
} }
} }

View File

@ -906,6 +906,7 @@ impl OlmMachine {
// Only import the session if we didn't have this session or if it's // 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 // a better version of the same session, that is the first known
// index is lower. // index is lower.
// TODO load all sessions so we don't do a thousand small loads.
if let Some(existing_session) = self if let Some(existing_session) = self
.store .store
.get_inbound_group_session( .get_inbound_group_session(
@ -929,6 +930,10 @@ impl OlmMachine {
let num_sessions = sessions.len(); let num_sessions = sessions.len();
self.store.save_inbound_group_sessions(&sessions).await?; self.store.save_inbound_group_sessions(&sessions).await?;
info!(
"Successfully imported {} inbound group sessions",
num_sessions
);
Ok(num_sessions) Ok(num_sessions)
} }