Merge pull request #698 from matrix-org/poljar/rename-encrypt-method

refactor(crypto): Make it clear that the encrypt method is for room events
This commit is contained in:
Benjamin Kampmann
2022-05-20 10:35:03 +02:00
committed by GitHub
4 changed files with 10 additions and 12 deletions
+1 -1
View File
@@ -1071,7 +1071,7 @@ impl BaseClient {
content: impl MessageLikeEventContent,
) -> Result<RoomEncryptedEventContent> {
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"),
}
}
+1 -1
View File
@@ -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)?)
+7 -9
View File
@@ -651,21 +651,21 @@ 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<RoomEncryptedEventContent> {
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.
///
/// 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
///
@@ -680,9 +680,7 @@ impl OlmMachine {
/// # Panics
///
/// 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 +1955,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();
+1 -1
View File
@@ -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();