Skip to content

Commit

Permalink
crypto: Pass room id and session id to `room_keys_withheld_received_s…
Browse files Browse the repository at this point in the history
…tream`
  • Loading branch information
richvdh committed Jul 9, 2024
1 parent 2d3e2da commit e7f0a2b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
3 changes: 2 additions & 1 deletion crates/matrix-sdk-crypto/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ Additions:
- Expose new method `OlmMachine::room_keys_withheld_received_stream`, to allow
applications to receive notifications about received `m.room_key.withheld`
events.
([#3660](https://github.com/matrix-org/matrix-rust-sdk/pull/3660))
([#3660](https://github.com/matrix-org/matrix-rust-sdk/pull/3660)),
([#3673](https://github.com/matrix-org/matrix-rust-sdk/pull/3673))

- Expose new method `OlmMachine::clear_crypto_cache()`, with FFI bindings
([#3462](https://github.com/matrix-org/matrix-rust-sdk/pull/3462))
Expand Down
4 changes: 3 additions & 1 deletion crates/matrix-sdk-crypto/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3292,8 +3292,10 @@ pub(crate) mod tests {
.flatten()
.expect("We should have received a notification of room key being withheld");
assert_eq!(withheld_received.len(), 1);

assert_eq!(&withheld_received[0].room_id, room_id);
assert_matches!(
&withheld_received[0].content,
&withheld_received[0].withheld_event.content,
RoomKeyWithheldContent::MegolmV1AesSha2(MegolmV1AesSha2WithheldContent::Unverified(
unverified_withheld_content
))
Expand Down
17 changes: 11 additions & 6 deletions crates/matrix-sdk-crypto/src/store/crypto_store_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use super::{DeviceChanges, IdentityChanges, LockableCryptoStore};
use crate::{
olm::InboundGroupSession,
store,
store::{Changes, DynCryptoStore, IntoCryptoStore, RoomKeyInfo},
types::events::room_key_withheld::RoomKeyWithheldEvent,
store::{Changes, DynCryptoStore, IntoCryptoStore, RoomKeyInfo, RoomKeyWithheldInfo},
GossippedSecret, ReadOnlyOwnUserIdentity,
};

Expand All @@ -32,7 +31,7 @@ pub(crate) struct CryptoStoreWrapper {

/// The sender side of a broadcast stream that is notified whenever we
/// receive an `m.room_key.withheld` message.
room_keys_withheld_received_sender: broadcast::Sender<Vec<RoomKeyWithheldEvent>>,
room_keys_withheld_received_sender: broadcast::Sender<Vec<RoomKeyWithheldInfo>>,

/// The sender side of a broadcast channel which sends out secrets we
/// received as a `m.secret.send` event.
Expand Down Expand Up @@ -77,8 +76,14 @@ impl CryptoStoreWrapper {

let withheld_session_updates: Vec<_> = changes
.withheld_session_info
.values()
.flat_map(|session_map| session_map.values().cloned())
.iter()
.flat_map(|(room_id, session_map)| {
session_map.iter().map(|(session_id, withheld_event)| RoomKeyWithheldInfo {
room_id: room_id.to_owned(),
session_id: session_id.to_owned(),
withheld_event: withheld_event.clone(),
})
})
.collect();

let secrets = changes.secrets.to_owned();
Expand Down Expand Up @@ -161,7 +166,7 @@ impl CryptoStoreWrapper {
/// logged and items will be dropped.
pub fn room_keys_withheld_received_stream(
&self,
) -> impl Stream<Item = Vec<RoomKeyWithheldEvent>> {
) -> impl Stream<Item = Vec<RoomKeyWithheldInfo>> {
let stream = BroadcastStream::new(self.room_keys_withheld_received_sender.subscribe());
Self::filter_errors_out_of_stream(stream, "room_keys_withheld_received_stream")
}
Expand Down
16 changes: 15 additions & 1 deletion crates/matrix-sdk-crypto/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,20 @@ impl From<&InboundGroupSession> for RoomKeyInfo {
}
}

/// Information on a room key that has been withheld
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct RoomKeyWithheldInfo {
/// The room where the key is used.
pub room_id: OwnedRoomId,

/// The ID of the session that the key is for.
pub session_id: String,

/// The `m.room_key.withheld` event that notified us that the key is being
/// withheld.
pub withheld_event: RoomKeyWithheldEvent,
}

impl Store {
/// Create a new Store.
pub(crate) fn new(
Expand Down Expand Up @@ -1473,7 +1487,7 @@ impl Store {
/// logged and items will be dropped.
pub fn room_keys_withheld_received_stream(
&self,
) -> impl Stream<Item = Vec<RoomKeyWithheldEvent>> {
) -> impl Stream<Item = Vec<RoomKeyWithheldInfo>> {
self.inner.store.room_keys_withheld_received_stream()
}

Expand Down

0 comments on commit e7f0a2b

Please sign in to comment.