Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added shared_history flag to room key events #1669

Merged
merged 9 commits into from
Oct 6, 2023
1 change: 1 addition & 0 deletions crates/ruma-events/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ unstable-exhaustive-types = []
unstable-msc1767 = []
unstable-msc2448 = []
unstable-msc2747 = []
unstable-msc3061 = []
unstable-msc3245 = ["unstable-msc3246"]
# Support the m.room.message fallback fields from the first version of MSC3245,
# implemented in Element Web and documented at
Expand Down
15 changes: 15 additions & 0 deletions crates/ruma-events/src/forwarded_room_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ pub struct ToDeviceForwardedRoomKeyEventContent {
/// key is forwarded from A to B to C, this field is empty between A and B, and contains
/// A's Curve25519 key between B and C.
pub forwarding_curve25519_key_chain: Vec<String>,

/// Used to mark key if allowed for shared history
Michael-Hollister marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(feature = "unstable-msc3061")]
#[serde(
default,
rename = "org.matrix.msc3061.shared_history",
skip_serializing_if = "ruma_common::serde::is_default"
)]
pub shared_history: bool,
}

/// Initial set of fields of `ToDeviceForwardedRoomKeyEventContent`.
Expand Down Expand Up @@ -81,6 +90,10 @@ pub struct ToDeviceForwardedRoomKeyEventContentInit {
/// key is forwarded from A to B to C, this field is empty between A and B, and contains
/// A's Curve25519 key between B and C.
pub forwarding_curve25519_key_chain: Vec<String>,

/// Used to mark key if allowed for shared history
#[cfg(feature = "unstable-msc3061")]
pub shared_history: bool,
Michael-Hollister marked this conversation as resolved.
Show resolved Hide resolved
}

impl From<ToDeviceForwardedRoomKeyEventContentInit> for ToDeviceForwardedRoomKeyEventContent {
Expand All @@ -93,6 +106,8 @@ impl From<ToDeviceForwardedRoomKeyEventContentInit> for ToDeviceForwardedRoomKey
session_key: init.session_key,
sender_claimed_ed25519_key: init.sender_claimed_ed25519_key,
forwarding_curve25519_key_chain: init.forwarding_curve25519_key_chain,
#[cfg(feature = "unstable-msc3061")]
shared_history: init.shared_history,
Michael-Hollister marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
34 changes: 33 additions & 1 deletion crates/ruma-events/src/room_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ pub struct ToDeviceRoomKeyEventContent {

/// The key to be exchanged.
pub session_key: String,

/// Used to mark key if allowed for shared history
Michael-Hollister marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(feature = "unstable-msc3061")]
#[serde(
default,
rename = "org.matrix.msc3061.shared_history",
skip_serializing_if = "ruma_common::serde::is_default"
)]
pub shared_history: bool,
}

impl ToDeviceRoomKeyEventContent {
Expand All @@ -36,8 +45,16 @@ impl ToDeviceRoomKeyEventContent {
room_id: OwnedRoomId,
session_id: String,
session_key: String,
#[cfg(feature = "unstable-msc3061")] shared_history: bool,
Michael-Hollister marked this conversation as resolved.
Show resolved Hide resolved
) -> Self {
Self { algorithm, room_id, session_id, session_key }
Self {
algorithm,
room_id,
session_id,
session_key,
#[cfg(feature = "unstable-msc3061")]
shared_history,
Michael-Hollister marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

Expand All @@ -56,15 +73,30 @@ mod tests {
room_id: owned_room_id!("!testroomid:example.org"),
session_id: "SessId".into(),
session_key: "SessKey".into(),
#[cfg(feature = "unstable-msc3061")]
shared_history: true,
};

#[cfg(not(feature = "unstable-msc3061"))]
assert_eq!(
to_json_value(content).unwrap(),
json!({
"algorithm": "m.megolm.v1.aes-sha2",
"room_id": "!testroomid:example.org",
"session_id": "SessId",
"session_key": "SessKey",
})
);

#[cfg(feature = "unstable-msc3061")]
assert_eq!(
to_json_value(content).unwrap(),
json!({
"algorithm": "m.megolm.v1.aes-sha2",
"room_id": "!testroomid:example.org",
"session_id": "SessId",
"session_key": "SessKey",
"org.matrix.msc3061.shared_history": true,
})
);
}
Expand Down
15 changes: 15 additions & 0 deletions crates/ruma-events/tests/it/to_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ fn serialization() {
owned_room_id!("!testroomid:example.org"),
"SessId".into(),
"SessKey".into(),
#[cfg(feature = "unstable-msc3061")]
true,
);

#[cfg(not(feature = "unstable-msc3061"))]
assert_eq!(
to_json_value(&content).unwrap(),
json!({
Expand All @@ -20,4 +23,16 @@ fn serialization() {
"session_key": "SessKey",
})
);

#[cfg(feature = "unstable-msc3061")]
assert_eq!(
to_json_value(&content).unwrap(),
json!({
"algorithm": "m.megolm.v1.aes-sha2",
"room_id": "!testroomid:example.org",
"session_id": "SessId",
"session_key": "SessKey",
"org.matrix.msc3061.shared_history": true,
})
);
}
2 changes: 2 additions & 0 deletions crates/ruma/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ unstable-msc2747 = ["ruma-events?/unstable-msc2747"]
unstable-msc2870 = ["ruma-common/unstable-msc2870"]
unstable-msc2965 = ["ruma-client-api?/unstable-msc2965"]
unstable-msc2967 = ["ruma-client-api?/unstable-msc2967"]
unstable-msc3061 = ["ruma-events?/unstable-msc3061"]
unstable-msc3202 = ["ruma-appservice-api?/unstable-msc3202"]
unstable-msc3245 = ["ruma-events?/unstable-msc3245"]
# Support the m.room.message fallback fields from the first version of MSC3245,
Expand Down Expand Up @@ -232,6 +233,7 @@ __ci = [
"unstable-msc2870",
"unstable-msc2965",
"unstable-msc2967",
"unstable-msc3061",
"unstable-msc3202",
"unstable-msc3245",
"unstable-msc3245-v1-compat",
Expand Down
Loading