From b44224794633ae6d40ec343a05dfecde9d30ef2b Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 21 Sep 2022 13:03:42 +0200 Subject: [PATCH] feat(sdk): Rename `OlmMachine.export_keys` to `.export_room_keys`. Because that's what it does :-). --- bindings/matrix-sdk-crypto-ffi/src/lib.rs | 2 +- bindings/matrix-sdk-crypto-ffi/src/machine.rs | 8 ++++++-- bindings/matrix-sdk-crypto-ffi/src/olm.udl | 2 +- .../matrix-sdk-crypto/src/file_encryption/key_export.rs | 6 +++--- crates/matrix-sdk-crypto/src/machine.rs | 4 ++-- crates/matrix-sdk/src/docs/encryption.md | 4 ++-- crates/matrix-sdk/src/encryption/mod.rs | 8 ++++---- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/bindings/matrix-sdk-crypto-ffi/src/lib.rs b/bindings/matrix-sdk-crypto-ffi/src/lib.rs index 229af1a3f..e79e3e313 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/lib.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/lib.rs @@ -583,7 +583,7 @@ mod test { "JGgPQRuYj3ScMdPS+A0P+k/1qS9Hr3qeKXLscI+hS78" ); - let room_keys = machine.runtime.block_on(machine.inner.export_keys(|_| true))?; + let room_keys = machine.runtime.block_on(machine.inner.export_room_keys(|_| true))?; assert_eq!(room_keys.len(), 2); let cross_signing_status = machine.cross_signing_status(); diff --git a/bindings/matrix-sdk-crypto-ffi/src/machine.rs b/bindings/matrix-sdk-crypto-ffi/src/machine.rs index 73722c37b..9999f2fb0 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/machine.rs +++ b/bindings/matrix-sdk-crypto-ffi/src/machine.rs @@ -658,8 +658,12 @@ impl OlmMachine { /// /// * `rounds` - The number of rounds that should be used when expanding the /// passphrase into an key. - pub fn export_keys(&self, passphrase: &str, rounds: i32) -> Result { - let keys = self.runtime.block_on(self.inner.export_keys(|_| true))?; + pub fn export_room_keys( + &self, + passphrase: &str, + rounds: i32, + ) -> Result { + let keys = self.runtime.block_on(self.inner.export_room_keys(|_| true))?; let encrypted = encrypt_key_export(&keys, passphrase, rounds as u32) .map_err(CryptoStoreError::Serialization)?; diff --git a/bindings/matrix-sdk-crypto-ffi/src/olm.udl b/bindings/matrix-sdk-crypto-ffi/src/olm.udl index e9499b417..3e8667534 100644 --- a/bindings/matrix-sdk-crypto-ffi/src/olm.udl +++ b/bindings/matrix-sdk-crypto-ffi/src/olm.udl @@ -358,7 +358,7 @@ interface OlmMachine { KeyRequestPair request_room_key([ByRef] string event, [ByRef] string room_id); [Throws=CryptoStoreError] - string export_keys([ByRef] string passphrase, i32 rounds); + string export_room_keys([ByRef] string passphrase, i32 rounds); [Throws=KeyImportError] KeysImportResult import_keys( [ByRef] string keys, diff --git a/crates/matrix-sdk-crypto/src/file_encryption/key_export.rs b/crates/matrix-sdk-crypto/src/file_encryption/key_export.rs index d86b088f6..0a0fe73df 100644 --- a/crates/matrix-sdk-crypto/src/file_encryption/key_export.rs +++ b/crates/matrix-sdk-crypto/src/file_encryption/key_export.rs @@ -125,7 +125,7 @@ pub fn decrypt_key_export( /// * `rounds` - The number of rounds that should be used for the key /// derivation when the passphrase gets turned into an AES key. More rounds are /// increasingly computationally intensive and as such help against brute-force -/// attacks. Should be at least `10000`, while values in the `100000` ranges +/// attacks. Should be at least `10_000`, while values in the `100_000` ranges /// should be preferred. /// /// # Panics @@ -142,7 +142,7 @@ pub fn decrypt_key_export( /// # block_on(async { /// # let machine = OlmMachine::new(&alice, device_id!("DEVICEID")).await; /// let room_id = room_id!("!test:localhost"); -/// let exported_keys = machine.export_keys(|s| s.room_id() == room_id).await.unwrap(); +/// let exported_keys = machine.export_room_keys(|s| s.room_id() == room_id).await.unwrap(); /// let encrypted_export = encrypt_key_export(&exported_keys, "1234", 1); /// # }); /// ``` @@ -332,7 +332,7 @@ mod tests { let room_id = room_id!("!test:localhost"); machine.create_outbound_group_session_with_defaults(room_id).await.unwrap(); - let export = machine.export_keys(|s| s.room_id() == room_id).await.unwrap(); + let export = machine.export_room_keys(|s| s.room_id() == room_id).await.unwrap(); assert!(!export.is_empty()); diff --git a/crates/matrix-sdk-crypto/src/machine.rs b/crates/matrix-sdk-crypto/src/machine.rs index 4b2a05fd3..6656732d1 100644 --- a/crates/matrix-sdk-crypto/src/machine.rs +++ b/crates/matrix-sdk-crypto/src/machine.rs @@ -1441,11 +1441,11 @@ impl OlmMachine { /// # block_on(async { /// # let machine = OlmMachine::new(&alice, device_id!("DEVICEID")).await; /// let room_id = room_id!("!test:localhost"); - /// let exported_keys = machine.export_keys(|s| s.room_id() == room_id).await.unwrap(); + /// let exported_keys = machine.export_room_keys(|s| s.room_id() == room_id).await.unwrap(); /// let encrypted_export = encrypt_key_export(&exported_keys, "1234", 1); /// # }); /// ``` - pub async fn export_keys( + pub async fn export_room_keys( &self, mut predicate: impl FnMut(&InboundGroupSession) -> bool, ) -> StoreResult> { diff --git a/crates/matrix-sdk/src/docs/encryption.md b/crates/matrix-sdk/src/docs/encryption.md index 90c78eb5d..09ebb93b0 100644 --- a/crates/matrix-sdk/src/docs/encryption.md +++ b/crates/matrix-sdk/src/docs/encryption.md @@ -84,10 +84,10 @@ comes first. Since room keys get relatively often rotated, each room key will need to be stored, otherwise we won't be able to decrypt historical messages. The SDK -stores all room keys locally in a encrypted manner. +stores all room keys locally in an encrypted manner. Besides storing them as part of the SDK store, users can export room keys -using the [`Encryption::export_keys`] method. +using the [`Encryption::export_room_keys`] method. # Verification diff --git a/crates/matrix-sdk/src/encryption/mod.rs b/crates/matrix-sdk/src/encryption/mod.rs index 080e6fc4b..4b08cce76 100644 --- a/crates/matrix-sdk/src/encryption/mod.rs +++ b/crates/matrix-sdk/src/encryption/mod.rs @@ -716,7 +716,7 @@ impl Encryption { /// // Export all room keys. /// client /// .encryption() - /// .export_keys(path, "secret-passphrase", |_| true) + /// .export_room_keys(path, "secret-passphrase", |_| true) /// .await?; /// /// // Export only the room keys for a certain room. @@ -725,12 +725,12 @@ impl Encryption { /// /// client /// .encryption() - /// .export_keys(path, "secret-passphrase", |s| s.room_id() == room_id) + /// .export_room_keys(path, "secret-passphrase", |s| s.room_id() == room_id) /// .await?; /// # anyhow::Ok(()) }); /// ``` #[cfg(not(target_arch = "wasm32"))] - pub async fn export_keys( + pub async fn export_room_keys( &self, path: PathBuf, passphrase: &str, @@ -738,7 +738,7 @@ impl Encryption { ) -> Result<()> { let olm = self.client.olm_machine().ok_or(Error::AuthenticationRequired)?; - let keys = olm.export_keys(predicate).await?; + let keys = olm.export_room_keys(predicate).await?; let passphrase = zeroize::Zeroizing::new(passphrase.to_owned()); let encrypt = move || -> Result<()> {