From dea3e4adf4abfe6597239fa05224ed2ffe19b556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Fri, 18 Sep 2020 14:04:39 +0200 Subject: [PATCH] crypto: Document when a key export may panic. --- matrix_sdk/src/client.rs | 5 +++++ matrix_sdk_crypto/src/file_encryption/key_export.rs | 5 +++++ matrix_sdk_crypto/src/machine.rs | 13 ++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index ddae21f2..456eb579 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -1727,6 +1727,11 @@ impl Client { /// returns `true` the `InboundGroupSessoin` will be included in the export, /// if the closure returns `false` it will not be included. /// + /// # Panics + /// + /// This method will panic if it can't get enough randomness from the OS to + /// encrypt the exported keys securely. + /// /// # Examples /// /// ```no_run diff --git a/matrix_sdk_crypto/src/file_encryption/key_export.rs b/matrix_sdk_crypto/src/file_encryption/key_export.rs index 08fd1b48..e1cde309 100644 --- a/matrix_sdk_crypto/src/file_encryption/key_export.rs +++ b/matrix_sdk_crypto/src/file_encryption/key_export.rs @@ -122,6 +122,11 @@ pub fn decrypt_key_export( /// attacks. Should be at least `10000`, while values in the `100000` ranges /// should be preferred. /// +/// # Panics +/// +/// This method will panic if it can't get enough randomness from the OS to +/// encrypt the exported keys securely. +/// /// # Examples /// ```no_run /// # use matrix_sdk_crypto::{OlmMachine, encrypt_key_export}; diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 0a2fc577..69c00dc8 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -172,7 +172,7 @@ impl OlmMachine { let store = Store::new(store); let verification_machine = VerificationMachine::new(account.clone(), store.clone()); let user_id = Arc::new(user_id.clone()); - let device_id: Arc = Arc::new(device_id.into()); + let device_id: Arc = Arc::new(device_id); let key_request_machine = KeyRequestMachine::new(user_id.clone(), device_id.clone(), store.clone()); @@ -1612,6 +1612,17 @@ impl OlmMachine { /// Export the keys that match the given predicate. /// + /// # Arguments + /// + /// * `predicate` - A closure that will be called for every known + /// `InboundGroupSession`, which represents a room key. If the closure + /// returns `true` the `InboundGroupSessoin` will be included in the export, + /// if the closure returns `false` it will not be included. + /// + /// # Panics + /// + /// This method will panic if it can't get enough randomness from the OS to + /// encrypt the exported keys securely. /// /// # Examples ///