Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/matrix-sdk-base/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ All notable changes to this project will be documented in this file.
## [Unreleased] - ReleaseDate

### Features

- Add `EncryptionState::StateEncrypted` to represent rooms supporting encrypted
state events. Feature-gated behind `experimental-encrypted-state-events`.
([#5523](https://github.com/matrix-org/matrix-rust-sdk/pull/5523))
- [**breaking**] The `state` field of `JoinedRoomUpdate` and `LeftRoomUpdate`
now uses the `State` enum, depending on whether the state changes were
received in the `state` field or the `state_after` field.
Expand Down
31 changes: 31 additions & 0 deletions crates/matrix-sdk-base/src/room/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ pub enum EncryptionState {
/// The room is encrypted.
Encrypted,

/// The room is encrypted, additionally requiring state events to be
/// encrypted.
#[cfg(feature = "experimental-encrypted-state-events")]
StateEncrypted,

/// The room is not encrypted.
NotEncrypted,

Expand All @@ -46,10 +51,25 @@ pub enum EncryptionState {

impl EncryptionState {
/// Check whether `EncryptionState` is [`Encrypted`][Self::Encrypted].
#[cfg(not(feature = "experimental-encrypted-state-events"))]
pub fn is_encrypted(&self) -> bool {
matches!(self, Self::Encrypted)
}

/// Check whether `EncryptionState` is [`Encrypted`][Self::Encrypted] or
/// [`StateEncrypted`][Self::StateEncrypted].
#[cfg(feature = "experimental-encrypted-state-events")]
pub fn is_encrypted(&self) -> bool {
matches!(self, Self::Encrypted | Self::StateEncrypted)
}

/// Check whether `EncryptionState` is
/// [`StateEncrypted`][Self::StateEncrypted].
#[cfg(feature = "experimental-encrypted-state-events")]
pub fn is_state_encrypted(&self) -> bool {
matches!(self, Self::StateEncrypted)
}

/// Check whether `EncryptionState` is [`Unknown`][Self::Unknown].
pub fn is_unknown(&self) -> bool {
matches!(self, Self::Unknown)
Expand Down Expand Up @@ -155,5 +175,16 @@ mod tests {
assert!(EncryptionState::Unknown.is_encrypted().not());
assert!(EncryptionState::Encrypted.is_encrypted());
assert!(EncryptionState::NotEncrypted.is_encrypted().not());

#[cfg(feature = "experimental-encrypted-state-events")]
{
assert!(EncryptionState::StateEncrypted.is_unknown().not());
assert!(EncryptionState::StateEncrypted.is_encrypted());

assert!(EncryptionState::Unknown.is_state_encrypted().not());
assert!(EncryptionState::Encrypted.is_state_encrypted().not());
assert!(EncryptionState::StateEncrypted.is_state_encrypted());
assert!(EncryptionState::NotEncrypted.is_state_encrypted().not());
}
}
}
21 changes: 21 additions & 0 deletions crates/matrix-sdk-base/src/room/room_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ impl RoomInfo {
}

/// Returns the encryption state of this room.
#[cfg(not(feature = "experimental-encrypted-state-events"))]
pub fn encryption_state(&self) -> EncryptionState {
if !self.encryption_state_synced {
EncryptionState::Unknown
Expand All @@ -626,6 +627,26 @@ impl RoomInfo {
}
}

/// Returns the encryption state of this room.
#[cfg(feature = "experimental-encrypted-state-events")]
pub fn encryption_state(&self) -> EncryptionState {
if !self.encryption_state_synced {
EncryptionState::Unknown
} else {
self.base_info
.encryption
.as_ref()
.map(|state| {
if state.encrypt_state_events {
EncryptionState::StateEncrypted
} else {
EncryptionState::Encrypted
}
})
.unwrap_or(EncryptionState::NotEncrypted)
}
}

/// Set the encryption event content in this room.
pub fn set_encryption_event(&mut self, event: Option<RoomEncryptionEventContent>) {
self.base_info.encryption = event;
Expand Down
Loading