identifiers: Shorten RoomVersionId variant names
This commit is contained in:
parent
f03065793b
commit
6b76d7813e
@ -142,11 +142,11 @@ impl RoomVersionsCapability {
|
|||||||
|
|
||||||
/// Returns whether all fields have their default value.
|
/// Returns whether all fields have their default value.
|
||||||
pub fn is_default(&self) -> bool {
|
pub fn is_default(&self) -> bool {
|
||||||
self.default == RoomVersionId::Version1
|
self.default == RoomVersionId::V1
|
||||||
&& self.available.len() == 1
|
&& self.available.len() == 1
|
||||||
&& self
|
&& self
|
||||||
.available
|
.available
|
||||||
.get(&RoomVersionId::Version1)
|
.get(&RoomVersionId::V1)
|
||||||
.map(|stability| *stability == RoomVersionStability::Stable)
|
.map(|stability| *stability == RoomVersionStability::Stable)
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
@ -155,8 +155,8 @@ impl RoomVersionsCapability {
|
|||||||
impl Default for RoomVersionsCapability {
|
impl Default for RoomVersionsCapability {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
default: RoomVersionId::Version1,
|
default: RoomVersionId::V1,
|
||||||
available: btreemap! { RoomVersionId::Version1 => RoomVersionStability::Stable },
|
available: btreemap! { RoomVersionId::V1 => RoomVersionStability::Stable },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,11 +35,11 @@ impl RedactContent for RoomAliasesEventContent {
|
|||||||
// We compare the long way to avoid pre version 6 behavior if/when
|
// We compare the long way to avoid pre version 6 behavior if/when
|
||||||
// a new room version is introduced.
|
// a new room version is introduced.
|
||||||
let aliases = match version {
|
let aliases = match version {
|
||||||
RoomVersionId::Version1
|
RoomVersionId::V1
|
||||||
| RoomVersionId::Version2
|
| RoomVersionId::V2
|
||||||
| RoomVersionId::Version3
|
| RoomVersionId::V3
|
||||||
| RoomVersionId::Version4
|
| RoomVersionId::V4
|
||||||
| RoomVersionId::Version5 => Some(self.aliases),
|
| RoomVersionId::V5 => Some(self.aliases),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ pub struct RoomCreateEventContent {
|
|||||||
|
|
||||||
/// The version of the room.
|
/// The version of the room.
|
||||||
///
|
///
|
||||||
/// Defaults to `RoomVersionId::Version1`.
|
/// Defaults to `RoomVersionId::V1`.
|
||||||
#[serde(default = "default_room_version_id")]
|
#[serde(default = "default_room_version_id")]
|
||||||
pub room_version: RoomVersionId,
|
pub room_version: RoomVersionId,
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ impl PreviousRoom {
|
|||||||
|
|
||||||
/// Used to default the `room_version` field to room version 1.
|
/// Used to default the `room_version` field to room version 1.
|
||||||
fn default_room_version_id() -> RoomVersionId {
|
fn default_room_version_id() -> RoomVersionId {
|
||||||
RoomVersionId::Version1
|
RoomVersionId::V1
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -121,7 +121,7 @@ mod tests {
|
|||||||
let content = RoomCreateEventContent {
|
let content = RoomCreateEventContent {
|
||||||
creator: user_id!("@carl:example.com").to_owned(),
|
creator: user_id!("@carl:example.com").to_owned(),
|
||||||
federate: false,
|
federate: false,
|
||||||
room_version: RoomVersionId::Version4,
|
room_version: RoomVersionId::V4,
|
||||||
predecessor: None,
|
predecessor: None,
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
room_type: None,
|
room_type: None,
|
||||||
@ -142,7 +142,7 @@ mod tests {
|
|||||||
let content = RoomCreateEventContent {
|
let content = RoomCreateEventContent {
|
||||||
creator: user_id!("@carl:example.com").to_owned(),
|
creator: user_id!("@carl:example.com").to_owned(),
|
||||||
federate: false,
|
federate: false,
|
||||||
room_version: RoomVersionId::Version4,
|
room_version: RoomVersionId::V4,
|
||||||
predecessor: None,
|
predecessor: None,
|
||||||
room_type: Some(RoomType::Space),
|
room_type: Some(RoomType::Space),
|
||||||
};
|
};
|
||||||
@ -170,7 +170,7 @@ mod tests {
|
|||||||
RoomCreateEventContent {
|
RoomCreateEventContent {
|
||||||
creator,
|
creator,
|
||||||
federate: true,
|
federate: true,
|
||||||
room_version: RoomVersionId::Version4,
|
room_version: RoomVersionId::V4,
|
||||||
predecessor: None,
|
predecessor: None,
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
room_type: None,
|
room_type: None,
|
||||||
@ -193,7 +193,7 @@ mod tests {
|
|||||||
RoomCreateEventContent {
|
RoomCreateEventContent {
|
||||||
creator,
|
creator,
|
||||||
federate: true,
|
federate: true,
|
||||||
room_version: RoomVersionId::Version4,
|
room_version: RoomVersionId::V4,
|
||||||
predecessor: None,
|
predecessor: None,
|
||||||
room_type
|
room_type
|
||||||
} if creator == "@carl:example.com" && room_type == Some(RoomType::Space)
|
} if creator == "@carl:example.com" && room_type == Some(RoomType::Space)
|
||||||
|
@ -296,7 +296,7 @@ fn redact_method_properly_redacts() {
|
|||||||
let event: AnyMessageEvent = from_json_value(ev).unwrap();
|
let event: AnyMessageEvent = from_json_value(ev).unwrap();
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
event.redact(redaction, &RoomVersionId::Version6),
|
event.redact(redaction, &RoomVersionId::V6),
|
||||||
AnyRedactedMessageEvent::RoomMessage(RedactedMessageEvent {
|
AnyRedactedMessageEvent::RoomMessage(RedactedMessageEvent {
|
||||||
content: RedactedRoomMessageEventContent { .. },
|
content: RedactedRoomMessageEventContent { .. },
|
||||||
event_id,
|
event_id,
|
||||||
@ -323,10 +323,7 @@ fn redact_message_content() {
|
|||||||
let raw_json = to_raw_value(&json).unwrap();
|
let raw_json = to_raw_value(&json).unwrap();
|
||||||
let content = RoomMessageEventContent::from_parts("m.room.message", &raw_json).unwrap();
|
let content = RoomMessageEventContent::from_parts("m.room.message", &raw_json).unwrap();
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(content.redact(&RoomVersionId::V6), RedactedRoomMessageEventContent { .. });
|
||||||
content.redact(&RoomVersionId::Version6),
|
|
||||||
RedactedRoomMessageEventContent { .. }
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -341,7 +338,7 @@ fn redact_state_content() {
|
|||||||
let content = RoomCreateEventContent::from_parts("m.room.create", &raw_json).unwrap();
|
let content = RoomCreateEventContent::from_parts("m.room.create", &raw_json).unwrap();
|
||||||
|
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
content.redact(&RoomVersionId::Version6),
|
content.redact(&RoomVersionId::V6),
|
||||||
RedactedRoomCreateEventContent {
|
RedactedRoomCreateEventContent {
|
||||||
creator,
|
creator,
|
||||||
..
|
..
|
||||||
|
@ -25,7 +25,7 @@ ruma_api! {
|
|||||||
|
|
||||||
/// The room versions the sending has support for.
|
/// The room versions the sending has support for.
|
||||||
///
|
///
|
||||||
/// Defaults to `&[RoomVersionId::Version1]`.
|
/// Defaults to `&[RoomVersionId::V1]`.
|
||||||
#[ruma_api(query)]
|
#[ruma_api(query)]
|
||||||
pub ver: &'a [RoomVersionId],
|
pub ver: &'a [RoomVersionId],
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ ruma_api! {
|
|||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a `Request` with the given room ID and user ID.
|
/// Creates a `Request` with the given room ID and user ID.
|
||||||
pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self {
|
pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self {
|
||||||
Self { room_id, user_id, ver: &[RoomVersionId::Version1] }
|
Self { room_id, user_id, ver: &[RoomVersionId::V1] }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ ruma_api! {
|
|||||||
|
|
||||||
/// The room versions the sending server has support for.
|
/// The room versions the sending server has support for.
|
||||||
///
|
///
|
||||||
/// Defaults to `&[RoomVersionId::Version1]`.
|
/// Defaults to `&[RoomVersionId::V1]`.
|
||||||
#[ruma_api(query)]
|
#[ruma_api(query)]
|
||||||
#[serde(default = "default_ver", skip_serializing_if = "is_default_ver")]
|
#[serde(default = "default_ver", skip_serializing_if = "is_default_ver")]
|
||||||
pub ver: &'a [RoomVersionId],
|
pub ver: &'a [RoomVersionId],
|
||||||
@ -43,17 +43,17 @@ ruma_api! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn default_ver() -> Vec<RoomVersionId> {
|
fn default_ver() -> Vec<RoomVersionId> {
|
||||||
vec![RoomVersionId::Version1]
|
vec![RoomVersionId::V1]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_default_ver(ver: &&[RoomVersionId]) -> bool {
|
fn is_default_ver(ver: &&[RoomVersionId]) -> bool {
|
||||||
**ver == [RoomVersionId::Version1]
|
**ver == [RoomVersionId::V1]
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the given room id and user id.
|
/// Creates a new `Request` with the given room id and user id.
|
||||||
pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self {
|
pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self {
|
||||||
Self { room_id, user_id, ver: &[RoomVersionId::Version1] }
|
Self { room_id, user_id, ver: &[RoomVersionId::V1] }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ Breaking changes:
|
|||||||
(these *might* be converted into the same kind of type at some point in the future)
|
(these *might* be converted into the same kind of type at some point in the future)
|
||||||
* The corresponding macros (and also `server_name!`) now return `'static` references instead of
|
* The corresponding macros (and also `server_name!`) now return `'static` references instead of
|
||||||
owned values now – use `.to_owned()` to get an owned copy
|
owned values now – use `.to_owned()` to get an owned copy
|
||||||
|
* Rename `RoomVersionId::Version{X}` variants to `RoomVersionId::V{X}`
|
||||||
|
|
||||||
# 0.20.0
|
# 0.20.0
|
||||||
|
|
||||||
|
@ -25,34 +25,34 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
|||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
pub enum RoomVersionId {
|
pub enum RoomVersionId {
|
||||||
/// A version 1 room.
|
/// A version 1 room.
|
||||||
Version1,
|
V1,
|
||||||
|
|
||||||
/// A version 2 room.
|
/// A version 2 room.
|
||||||
Version2,
|
V2,
|
||||||
|
|
||||||
/// A version 3 room.
|
/// A version 3 room.
|
||||||
Version3,
|
V3,
|
||||||
|
|
||||||
/// A version 4 room.
|
/// A version 4 room.
|
||||||
Version4,
|
V4,
|
||||||
|
|
||||||
/// A version 5 room.
|
/// A version 5 room.
|
||||||
Version5,
|
V5,
|
||||||
|
|
||||||
/// A version 6 room.
|
/// A version 6 room.
|
||||||
Version6,
|
V6,
|
||||||
|
|
||||||
/// A version 7 room.
|
/// A version 7 room.
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
Version7,
|
V7,
|
||||||
|
|
||||||
/// A version 8 room.
|
/// A version 8 room.
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
Version8,
|
V8,
|
||||||
|
|
||||||
/// A version 9 room.
|
/// A version 9 room.
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
Version9,
|
V9,
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
_Custom(CustomRoomVersion),
|
_Custom(CustomRoomVersion),
|
||||||
@ -64,18 +64,18 @@ impl RoomVersionId {
|
|||||||
// FIXME: Add support for non-`str`-deref'ing types for fallback to AsRefStr derive and
|
// FIXME: Add support for non-`str`-deref'ing types for fallback to AsRefStr derive and
|
||||||
// implement this function in terms of `AsRef<str>`
|
// implement this function in terms of `AsRef<str>`
|
||||||
match &self {
|
match &self {
|
||||||
Self::Version1 => "1",
|
Self::V1 => "1",
|
||||||
Self::Version2 => "2",
|
Self::V2 => "2",
|
||||||
Self::Version3 => "3",
|
Self::V3 => "3",
|
||||||
Self::Version4 => "4",
|
Self::V4 => "4",
|
||||||
Self::Version5 => "5",
|
Self::V5 => "5",
|
||||||
Self::Version6 => "6",
|
Self::V6 => "6",
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
Self::Version7 => "7",
|
Self::V7 => "7",
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
Self::Version8 => "8",
|
Self::V8 => "8",
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
Self::Version9 => "9",
|
Self::V9 => "9",
|
||||||
Self::_Custom(version) => version.as_str(),
|
Self::_Custom(version) => version.as_str(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,18 +89,18 @@ impl RoomVersionId {
|
|||||||
impl From<RoomVersionId> for String {
|
impl From<RoomVersionId> for String {
|
||||||
fn from(id: RoomVersionId) -> Self {
|
fn from(id: RoomVersionId) -> Self {
|
||||||
match id {
|
match id {
|
||||||
RoomVersionId::Version1 => "1".to_owned(),
|
RoomVersionId::V1 => "1".to_owned(),
|
||||||
RoomVersionId::Version2 => "2".to_owned(),
|
RoomVersionId::V2 => "2".to_owned(),
|
||||||
RoomVersionId::Version3 => "3".to_owned(),
|
RoomVersionId::V3 => "3".to_owned(),
|
||||||
RoomVersionId::Version4 => "4".to_owned(),
|
RoomVersionId::V4 => "4".to_owned(),
|
||||||
RoomVersionId::Version5 => "5".to_owned(),
|
RoomVersionId::V5 => "5".to_owned(),
|
||||||
RoomVersionId::Version6 => "6".to_owned(),
|
RoomVersionId::V6 => "6".to_owned(),
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
RoomVersionId::Version7 => "7".to_owned(),
|
RoomVersionId::V7 => "7".to_owned(),
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
RoomVersionId::Version8 => "8".to_owned(),
|
RoomVersionId::V8 => "8".to_owned(),
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
RoomVersionId::Version9 => "9".to_owned(),
|
RoomVersionId::V9 => "9".to_owned(),
|
||||||
RoomVersionId::_Custom(version) => version.into(),
|
RoomVersionId::_Custom(version) => version.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,18 +160,18 @@ where
|
|||||||
S: AsRef<str> + Into<Box<str>>,
|
S: AsRef<str> + Into<Box<str>>,
|
||||||
{
|
{
|
||||||
let version = match room_version_id.as_ref() {
|
let version = match room_version_id.as_ref() {
|
||||||
"1" => RoomVersionId::Version1,
|
"1" => RoomVersionId::V1,
|
||||||
"2" => RoomVersionId::Version2,
|
"2" => RoomVersionId::V2,
|
||||||
"3" => RoomVersionId::Version3,
|
"3" => RoomVersionId::V3,
|
||||||
"4" => RoomVersionId::Version4,
|
"4" => RoomVersionId::V4,
|
||||||
"5" => RoomVersionId::Version5,
|
"5" => RoomVersionId::V5,
|
||||||
"6" => RoomVersionId::Version6,
|
"6" => RoomVersionId::V6,
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
"7" => RoomVersionId::Version7,
|
"7" => RoomVersionId::V7,
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
"8" => RoomVersionId::Version8,
|
"8" => RoomVersionId::V8,
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
"9" => RoomVersionId::Version9,
|
"9" => RoomVersionId::V9,
|
||||||
custom => {
|
custom => {
|
||||||
ruma_identifiers_validation::room_version_id::validate(custom)?;
|
ruma_identifiers_validation::room_version_id::validate(custom)?;
|
||||||
RoomVersionId::_Custom(CustomRoomVersion(room_version_id.into()))
|
RoomVersionId::_Custom(CustomRoomVersion(room_version_id.into()))
|
||||||
@ -349,7 +349,7 @@ mod tests {
|
|||||||
let deserialized = serde_json::from_str::<RoomVersionId>(r#""1""#)
|
let deserialized = serde_json::from_str::<RoomVersionId>(r#""1""#)
|
||||||
.expect("Failed to convert RoomVersionId to JSON.");
|
.expect("Failed to convert RoomVersionId to JSON.");
|
||||||
|
|
||||||
assert_eq!(deserialized, RoomVersionId::Version1);
|
assert_eq!(deserialized, RoomVersionId::V1);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
deserialized,
|
deserialized,
|
||||||
|
@ -58,11 +58,11 @@ fn allowed_content_keys_for(event_type: &str, version: &RoomVersionId) -> &'stat
|
|||||||
"users_default",
|
"users_default",
|
||||||
],
|
],
|
||||||
"m.room.aliases" => match version {
|
"m.room.aliases" => match version {
|
||||||
RoomVersionId::Version1
|
RoomVersionId::V1
|
||||||
| RoomVersionId::Version2
|
| RoomVersionId::V2
|
||||||
| RoomVersionId::Version3
|
| RoomVersionId::V3
|
||||||
| RoomVersionId::Version4
|
| RoomVersionId::V4
|
||||||
| RoomVersionId::Version5 => &["aliases"],
|
| RoomVersionId::V5 => &["aliases"],
|
||||||
// All other room versions, including custom ones, are treated by version 6 rules.
|
// All other room versions, including custom ones, are treated by version 6 rules.
|
||||||
// TODO: Should we return an error for unknown versions instead?
|
// TODO: Should we return an error for unknown versions instead?
|
||||||
_ => &[],
|
_ => &[],
|
||||||
@ -387,9 +387,7 @@ pub fn reference_hash(
|
|||||||
Ok(encode_config(
|
Ok(encode_config(
|
||||||
&hash,
|
&hash,
|
||||||
match version {
|
match version {
|
||||||
RoomVersionId::Version1 | RoomVersionId::Version2 | RoomVersionId::Version3 => {
|
RoomVersionId::V1 | RoomVersionId::V2 | RoomVersionId::V3 => STANDARD_NO_PAD,
|
||||||
STANDARD_NO_PAD
|
|
||||||
}
|
|
||||||
// Room versions higher than version 3 are url safe base64 encoded
|
// Room versions higher than version 3 are url safe base64 encoded
|
||||||
_ => URL_SAFE_NO_PAD,
|
_ => URL_SAFE_NO_PAD,
|
||||||
},
|
},
|
||||||
@ -458,7 +456,7 @@ pub fn reference_hash(
|
|||||||
/// ).unwrap();
|
/// ).unwrap();
|
||||||
///
|
///
|
||||||
/// // Hash and sign the JSON with the key pair.
|
/// // Hash and sign the JSON with the key pair.
|
||||||
/// assert!(hash_and_sign_event("domain", &key_pair, &mut object, &RoomVersionId::Version1).is_ok());
|
/// assert!(hash_and_sign_event("domain", &key_pair, &mut object, &RoomVersionId::V1).is_ok());
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// This will modify the JSON from the structure shown to a structure like this:
|
/// This will modify the JSON from the structure shown to a structure like this:
|
||||||
@ -583,7 +581,7 @@ where
|
|||||||
/// public_key_map.insert("domain".into(), public_key_set);
|
/// public_key_map.insert("domain".into(), public_key_set);
|
||||||
///
|
///
|
||||||
/// // Verify at least one signature for each entity in `public_key_map`.
|
/// // Verify at least one signature for each entity in `public_key_map`.
|
||||||
/// let verification_result = verify_event(&public_key_map, &object, &RoomVersionId::Version6);
|
/// let verification_result = verify_event(&public_key_map, &object, &RoomVersionId::V6);
|
||||||
/// assert!(verification_result.is_ok());
|
/// assert!(verification_result.is_ok());
|
||||||
/// assert!(matches!(verification_result.unwrap(), Verified::All));
|
/// assert!(matches!(verification_result.unwrap(), Verified::All));
|
||||||
/// ```
|
/// ```
|
||||||
@ -790,7 +788,7 @@ fn servers_to_check_signatures(
|
|||||||
}
|
}
|
||||||
|
|
||||||
match version {
|
match version {
|
||||||
RoomVersionId::Version1 | RoomVersionId::Version2 => match object.get("event_id") {
|
RoomVersionId::V1 | RoomVersionId::V2 => match object.get("event_id") {
|
||||||
Some(CanonicalJsonValue::String(raw_event_id)) => {
|
Some(CanonicalJsonValue::String(raw_event_id)) => {
|
||||||
let event_id: Box<EventId> =
|
let event_id: Box<EventId> =
|
||||||
raw_event_id.parse().map_err(|e| Error::from(ParseError::EventId(e)))?;
|
raw_event_id.parse().map_err(|e| Error::from(ParseError::EventId(e)))?;
|
||||||
@ -933,8 +931,7 @@ mod tests {
|
|||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
let public_key_map = BTreeMap::new();
|
let public_key_map = BTreeMap::new();
|
||||||
let verification_result =
|
let verification_result = verify_event(&public_key_map, &signed_event, &RoomVersionId::V6);
|
||||||
verify_event(&public_key_map, &signed_event, &RoomVersionId::Version6);
|
|
||||||
|
|
||||||
assert!(verification_result.is_ok());
|
assert!(verification_result.is_ok());
|
||||||
let verification = verification_result.unwrap();
|
let verification = verification_result.unwrap();
|
||||||
@ -987,8 +984,7 @@ mod tests {
|
|||||||
add_key_to_map(&mut public_key_map, "domain-sender", &key_pair_sender);
|
add_key_to_map(&mut public_key_map, "domain-sender", &key_pair_sender);
|
||||||
add_key_to_map(&mut public_key_map, "domain-event", &key_pair_event);
|
add_key_to_map(&mut public_key_map, "domain-event", &key_pair_event);
|
||||||
|
|
||||||
let verification_result =
|
let verification_result = verify_event(&public_key_map, &signed_event, &RoomVersionId::V1);
|
||||||
verify_event(&public_key_map, &signed_event, &RoomVersionId::Version1);
|
|
||||||
|
|
||||||
assert!(verification_result.is_ok());
|
assert!(verification_result.is_ok());
|
||||||
let verification = verification_result.unwrap();
|
let verification = verification_result.unwrap();
|
||||||
@ -1023,8 +1019,7 @@ mod tests {
|
|||||||
|
|
||||||
// Verify with an empty public key map should fail due to missing public keys
|
// Verify with an empty public key map should fail due to missing public keys
|
||||||
let public_key_map = BTreeMap::new();
|
let public_key_map = BTreeMap::new();
|
||||||
let verification_result =
|
let verification_result = verify_event(&public_key_map, &signed_event, &RoomVersionId::V6);
|
||||||
verify_event(&public_key_map, &signed_event, &RoomVersionId::Version6);
|
|
||||||
|
|
||||||
assert!(verification_result.is_err());
|
assert!(verification_result.is_err());
|
||||||
let error_msg = verification_result.err().unwrap();
|
let error_msg = verification_result.err().unwrap();
|
||||||
@ -1073,8 +1068,7 @@ mod tests {
|
|||||||
sender_key_map.insert(version.to_string(), encoded_public_key);
|
sender_key_map.insert(version.to_string(), encoded_public_key);
|
||||||
public_key_map.insert("domain-sender".to_owned(), sender_key_map);
|
public_key_map.insert("domain-sender".to_owned(), sender_key_map);
|
||||||
|
|
||||||
let verification_result =
|
let verification_result = verify_event(&public_key_map, &signed_event, &RoomVersionId::V6);
|
||||||
verify_event(&public_key_map, &signed_event, &RoomVersionId::Version6);
|
|
||||||
|
|
||||||
assert!(verification_result.is_err());
|
assert!(verification_result.is_err());
|
||||||
let error_msg = verification_result.err().unwrap();
|
let error_msg = verification_result.err().unwrap();
|
||||||
|
@ -341,7 +341,7 @@ mod tests {
|
|||||||
}"#;
|
}"#;
|
||||||
|
|
||||||
let mut object = from_json_str(json).unwrap();
|
let mut object = from_json_str(json).unwrap();
|
||||||
hash_and_sign_event("domain", &key_pair, &mut object, &RoomVersionId::Version5).unwrap();
|
hash_and_sign_event("domain", &key_pair, &mut object, &RoomVersionId::V5).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
to_json_string(&object).unwrap(),
|
to_json_string(&object).unwrap(),
|
||||||
@ -374,7 +374,7 @@ mod tests {
|
|||||||
}"#;
|
}"#;
|
||||||
|
|
||||||
let mut object = from_json_str(json).unwrap();
|
let mut object = from_json_str(json).unwrap();
|
||||||
hash_and_sign_event("domain", &key_pair, &mut object, &RoomVersionId::Version5).unwrap();
|
hash_and_sign_event("domain", &key_pair, &mut object, &RoomVersionId::V5).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
to_json_string(&object).unwrap(),
|
to_json_string(&object).unwrap(),
|
||||||
@ -415,6 +415,6 @@ mod tests {
|
|||||||
}"#
|
}"#
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
assert!(verify_event(&public_key_map, &value, &RoomVersionId::Version5).is_ok());
|
assert!(verify_event(&public_key_map, &value, &RoomVersionId::V5).is_ok());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ fn resolution_shallow_auth_chain(c: &mut Criterion) {
|
|||||||
let ev_map = store.0.clone();
|
let ev_map = store.0.clone();
|
||||||
let state_sets = [&state_at_bob, &state_at_charlie];
|
let state_sets = [&state_at_bob, &state_at_charlie];
|
||||||
let _ = match state_res::resolve(
|
let _ = match state_res::resolve(
|
||||||
&RoomVersionId::Version6,
|
&RoomVersionId::V6,
|
||||||
state_sets,
|
state_sets,
|
||||||
state_sets
|
state_sets
|
||||||
.iter()
|
.iter()
|
||||||
@ -130,7 +130,7 @@ fn resolve_deeper_event_set(c: &mut Criterion) {
|
|||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
let state_sets = [&state_set_a, &state_set_b];
|
let state_sets = [&state_set_a, &state_set_b];
|
||||||
let _ = match state_res::resolve(
|
let _ = match state_res::resolve(
|
||||||
&RoomVersionId::Version6,
|
&RoomVersionId::V6,
|
||||||
state_sets,
|
state_sets,
|
||||||
state_sets
|
state_sets
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -1039,7 +1039,7 @@ mod tests {
|
|||||||
let ev_map: EventMap<Arc<StateEvent>> = store.0.clone();
|
let ev_map: EventMap<Arc<StateEvent>> = store.0.clone();
|
||||||
let state_sets = [state_at_bob, state_at_charlie];
|
let state_sets = [state_at_bob, state_at_charlie];
|
||||||
let resolved = match crate::resolve(
|
let resolved = match crate::resolve(
|
||||||
&RoomVersionId::Version2,
|
&RoomVersionId::V2,
|
||||||
&state_sets,
|
&state_sets,
|
||||||
state_sets
|
state_sets
|
||||||
.iter()
|
.iter()
|
||||||
@ -1143,7 +1143,7 @@ mod tests {
|
|||||||
let ev_map: EventMap<Arc<StateEvent>> = store.0.clone();
|
let ev_map: EventMap<Arc<StateEvent>> = store.0.clone();
|
||||||
let state_sets = [state_set_a, state_set_b];
|
let state_sets = [state_set_a, state_set_b];
|
||||||
let resolved = match crate::resolve(
|
let resolved = match crate::resolve(
|
||||||
&RoomVersionId::Version6,
|
&RoomVersionId::V6,
|
||||||
&state_sets,
|
&state_sets,
|
||||||
state_sets
|
state_sets
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -72,7 +72,7 @@ pub struct RoomVersion {
|
|||||||
|
|
||||||
impl RoomVersion {
|
impl RoomVersion {
|
||||||
pub const VERSION1: Self = Self {
|
pub const VERSION1: Self = Self {
|
||||||
version: RoomVersionId::Version1,
|
version: RoomVersionId::V1,
|
||||||
disposition: RoomDisposition::Stable,
|
disposition: RoomDisposition::Stable,
|
||||||
event_format: EventFormatVersion::V1,
|
event_format: EventFormatVersion::V1,
|
||||||
state_res: StateResolutionVersion::V1,
|
state_res: StateResolutionVersion::V1,
|
||||||
@ -86,29 +86,26 @@ impl RoomVersion {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub const VERSION2: Self = Self {
|
pub const VERSION2: Self = Self {
|
||||||
version: RoomVersionId::Version2,
|
version: RoomVersionId::V2,
|
||||||
state_res: StateResolutionVersion::V2,
|
state_res: StateResolutionVersion::V2,
|
||||||
..Self::VERSION1
|
..Self::VERSION1
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const VERSION3: Self = Self {
|
pub const VERSION3: Self = Self {
|
||||||
version: RoomVersionId::Version3,
|
version: RoomVersionId::V3,
|
||||||
event_format: EventFormatVersion::V2,
|
event_format: EventFormatVersion::V2,
|
||||||
extra_redaction_checks: true,
|
extra_redaction_checks: true,
|
||||||
..Self::VERSION2
|
..Self::VERSION2
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const VERSION4: Self = Self {
|
pub const VERSION4: Self =
|
||||||
version: RoomVersionId::Version4,
|
Self { version: RoomVersionId::V4, event_format: EventFormatVersion::V3, ..Self::VERSION3 };
|
||||||
event_format: EventFormatVersion::V3,
|
|
||||||
..Self::VERSION3
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const VERSION5: Self =
|
pub const VERSION5: Self =
|
||||||
Self { version: RoomVersionId::Version5, enforce_key_validity: true, ..Self::VERSION4 };
|
Self { version: RoomVersionId::V5, enforce_key_validity: true, ..Self::VERSION4 };
|
||||||
|
|
||||||
pub const VERSION6: Self = Self {
|
pub const VERSION6: Self = Self {
|
||||||
version: RoomVersionId::Version5,
|
version: RoomVersionId::V5,
|
||||||
special_case_aliases_auth: false,
|
special_case_aliases_auth: false,
|
||||||
strict_canonicaljson: true,
|
strict_canonicaljson: true,
|
||||||
limit_notifications_power_levels: true,
|
limit_notifications_power_levels: true,
|
||||||
@ -117,7 +114,7 @@ impl RoomVersion {
|
|||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
pub const VERSION7: Self = Self {
|
pub const VERSION7: Self = Self {
|
||||||
version: RoomVersionId::Version7,
|
version: RoomVersionId::V7,
|
||||||
// FIXME: once room version 7 is stabilized move this to version 8
|
// FIXME: once room version 7 is stabilized move this to version 8
|
||||||
disposition: RoomDisposition::Unstable,
|
disposition: RoomDisposition::Unstable,
|
||||||
allow_knocking: true,
|
allow_knocking: true,
|
||||||
@ -126,25 +123,25 @@ impl RoomVersion {
|
|||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
pub const VERSION8: Self =
|
pub const VERSION8: Self =
|
||||||
Self { version: RoomVersionId::Version8, restricted_join_rules: true, ..Self::VERSION7 };
|
Self { version: RoomVersionId::V8, restricted_join_rules: true, ..Self::VERSION7 };
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
pub const VERSION9: Self = Self { version: RoomVersionId::Version9, ..Self::VERSION8 };
|
pub const VERSION9: Self = Self { version: RoomVersionId::V9, ..Self::VERSION8 };
|
||||||
|
|
||||||
pub fn new(version: &RoomVersionId) -> Result<Self> {
|
pub fn new(version: &RoomVersionId) -> Result<Self> {
|
||||||
Ok(match version {
|
Ok(match version {
|
||||||
RoomVersionId::Version1 => Self::VERSION1,
|
RoomVersionId::V1 => Self::VERSION1,
|
||||||
RoomVersionId::Version2 => Self::VERSION2,
|
RoomVersionId::V2 => Self::VERSION2,
|
||||||
RoomVersionId::Version3 => Self::VERSION3,
|
RoomVersionId::V3 => Self::VERSION3,
|
||||||
RoomVersionId::Version4 => Self::VERSION4,
|
RoomVersionId::V4 => Self::VERSION4,
|
||||||
RoomVersionId::Version5 => Self::VERSION5,
|
RoomVersionId::V5 => Self::VERSION5,
|
||||||
RoomVersionId::Version6 => Self::VERSION6,
|
RoomVersionId::V6 => Self::VERSION6,
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
RoomVersionId::Version7 => Self::VERSION7,
|
RoomVersionId::V7 => Self::VERSION7,
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
RoomVersionId::Version8 => Self::VERSION8,
|
RoomVersionId::V8 => Self::VERSION8,
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
RoomVersionId::Version9 => Self::VERSION9,
|
RoomVersionId::V9 => Self::VERSION9,
|
||||||
ver => return Err(Error::Unsupported(format!("found version `{}`", ver.as_str()))),
|
ver => return Err(Error::Unsupported(format!("found version `{}`", ver.as_str()))),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -116,8 +116,7 @@ pub fn do_check(
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let resolved =
|
let resolved = crate::resolve(&RoomVersionId::V6, state_sets, auth_chain_sets, |id| {
|
||||||
crate::resolve(&RoomVersionId::Version6, state_sets, auth_chain_sets, |id| {
|
|
||||||
event_map.get(id).map(Arc::clone)
|
event_map.get(id).map(Arc::clone)
|
||||||
});
|
});
|
||||||
match resolved {
|
match resolved {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user