From 813f38881233944ad6a314d3a558636603d238cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Fri, 20 May 2022 07:47:47 +0200 Subject: [PATCH 1/2] refactor(crypto): Make it clear that the encrypt method is for room events --- crates/matrix-sdk-base/src/client.rs | 2 +- crates/matrix-sdk-crypto-ffi/src/machine.rs | 2 +- crates/matrix-sdk-crypto/src/machine.rs | 9 ++++----- crates/matrix-sdk/src/room/joined.rs | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/matrix-sdk-base/src/client.rs b/crates/matrix-sdk-base/src/client.rs index ff086f96c..df920c5a0 100644 --- a/crates/matrix-sdk-base/src/client.rs +++ b/crates/matrix-sdk-base/src/client.rs @@ -1071,7 +1071,7 @@ impl BaseClient { content: impl MessageLikeEventContent, ) -> Result { match self.olm_machine().await { - Some(o) => Ok(o.encrypt(room_id, content).await?), + Some(o) => Ok(o.encrypt_room_event(room_id, content).await?), None => panic!("Olm machine wasn't started"), } } diff --git a/crates/matrix-sdk-crypto-ffi/src/machine.rs b/crates/matrix-sdk-crypto-ffi/src/machine.rs index b895bb9c6..fbd01ee4f 100644 --- a/crates/matrix-sdk-crypto-ffi/src/machine.rs +++ b/crates/matrix-sdk-crypto-ffi/src/machine.rs @@ -523,7 +523,7 @@ impl OlmMachine { let content = AnyMessageLikeEventContent::from_parts(event_type, &content)?; let encrypted_content = self .runtime - .block_on(self.inner.encrypt(&room_id, content)) + .block_on(self.inner.encrypt_room_event(&room_id, content)) .expect("Encrypting an event produced an error"); Ok(serde_json::to_string(&encrypted_content)?) diff --git a/crates/matrix-sdk-crypto/src/machine.rs b/crates/matrix-sdk-crypto/src/machine.rs index 1d79ef5a7..7ce3e1eb6 100644 --- a/crates/matrix-sdk-crypto/src/machine.rs +++ b/crates/matrix-sdk-crypto/src/machine.rs @@ -651,15 +651,14 @@ impl OlmMachine { /// Panics if a group session for the given room wasn't shared beforehand. /// /// [`share_group_session`]: Self::share_group_session - pub async fn encrypt( + pub async fn encrypt_room_event( &self, room_id: &RoomId, content: impl MessageLikeEventContent, ) -> MegolmResult { let event_type = content.event_type().to_string(); let content = serde_json::to_value(&content)?; - - self.group_session_manager.encrypt(room_id, content, &event_type).await + self.encrypt_room_event_raw(room_id, content, &event_type).await } /// Encrypt a json [`Value`] content for the given room. @@ -682,7 +681,7 @@ impl OlmMachine { /// Panics if a group session for the given room wasn't shared beforehand. /// /// [`encrypt()`]: #method.encrypt - pub async fn encrypt_raw( + pub async fn encrypt_room_event_raw( &self, room_id: &RoomId, content: Value, @@ -1957,7 +1956,7 @@ pub(crate) mod tests { let content = RoomMessageEventContent::text_plain(plaintext); let encrypted_content = alice - .encrypt(room_id, AnyMessageLikeEventContent::RoomMessage(content.clone())) + .encrypt_room_event(room_id, AnyMessageLikeEventContent::RoomMessage(content.clone())) .await .unwrap(); diff --git a/crates/matrix-sdk/src/room/joined.rs b/crates/matrix-sdk/src/room/joined.rs index c7bcb9007..ef773eb91 100644 --- a/crates/matrix-sdk/src/room/joined.rs +++ b/crates/matrix-sdk/src/room/joined.rs @@ -575,7 +575,7 @@ impl Joined { let olm = self.client.olm_machine().await.expect("Olm machine wasn't started"); let encrypted_content = - olm.encrypt_raw(self.inner.room_id(), content, event_type).await?; + olm.encrypt_room_event_raw(self.inner.room_id(), content, event_type).await?; let raw_content = Raw::new(&encrypted_content) .expect("Failed to serialize encrypted event") .cast(); From f3045dbf995f309b44fffa3bb67af30804e7ccab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Fri, 20 May 2022 08:32:50 +0200 Subject: [PATCH 2/2] fixup! refactor(crypto): Make it clear that the encrypt method is for room events --- crates/matrix-sdk-crypto/src/machine.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/matrix-sdk-crypto/src/machine.rs b/crates/matrix-sdk-crypto/src/machine.rs index 7ce3e1eb6..ee2880d03 100644 --- a/crates/matrix-sdk-crypto/src/machine.rs +++ b/crates/matrix-sdk-crypto/src/machine.rs @@ -663,8 +663,9 @@ impl OlmMachine { /// Encrypt a json [`Value`] content for the given room. /// - /// This method is equivalent to the [`encrypt()`] method but operates on an - /// arbitrary JSON value instead of strongly-typed event content struct. + /// This method is equivalent to the [`OlmMachine::encrypt_room_event()`] + /// method but operates on an arbitrary JSON value instead of strongly-typed + /// event content struct. /// /// # Arguments /// @@ -679,8 +680,6 @@ impl OlmMachine { /// # Panics /// /// Panics if a group session for the given room wasn't shared beforehand. - /// - /// [`encrypt()`]: #method.encrypt pub async fn encrypt_room_event_raw( &self, room_id: &RoomId,