state-res: Depend on ruma-* subcrates instead of ruma

This commit is contained in:
Jonas Platte 2021-05-08 00:52:50 +02:00
parent ee39f7c28c
commit f58462a002
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
11 changed files with 80 additions and 79 deletions

View File

@ -12,11 +12,15 @@ version = "0.1.0"
edition = "2018" edition = "2018"
[features] [features]
unstable-pre-spec = ["ruma/unstable-pre-spec"] unstable-pre-spec = ["ruma-events/unstable-pre-spec"]
[dependencies] [dependencies]
itertools = "0.10.0" itertools = "0.10.0"
ruma = { version = "0.0.3", path = "../ruma", features = ["events", "signatures"] } js_int = "0.2.0"
ruma-identifiers = { version = "0.19.0", path = "../ruma-identifiers" }
ruma-events = { version = "=0.22.0-alpha.3", path = "../ruma-events" }
ruma-serde = { version = "0.3.1", path = "../ruma-serde" }
ruma-signatures = { version = "0.7.0", path = "../ruma-signatures" }
serde = { version = "1.0.118", features = ["derive"] } serde = { version = "1.0.118", features = ["derive"] }
serde_json = "1.0.60" serde_json = "1.0.60"
maplit = "1.0.2" maplit = "1.0.2"

View File

@ -13,18 +13,17 @@ use std::{
use criterion::{criterion_group, criterion_main, Criterion}; use criterion::{criterion_group, criterion_main, Criterion};
use event::StateEvent; use event::StateEvent;
use js_int::uint;
use maplit::btreemap; use maplit::btreemap;
use ruma::{ use ruma_events::{
events::{
pdu::{EventHash, Pdu, RoomV3Pdu}, pdu::{EventHash, Pdu, RoomV3Pdu},
room::{ room::{
join_rules::JoinRule, join_rules::JoinRule,
member::{MemberEventContent, MembershipState}, member::{MemberEventContent, MembershipState},
}, },
EventType, EventType,
},
EventId, RoomId, RoomVersionId, UserId,
}; };
use ruma_identifiers::{EventId, RoomId, RoomVersionId, UserId};
use ruma_state_res::{Error, Event, EventMap, Result, StateMap, StateResolution}; use ruma_state_res::{Error, Event, EventMap, Result, StateMap, StateResolution};
use serde_json::{json, Value as JsonValue}; use serde_json::{json, Value as JsonValue};
@ -387,7 +386,7 @@ where
origin: "foo".into(), origin: "foo".into(),
auth_events, auth_events,
prev_events, prev_events,
depth: ruma::uint!(0), depth: uint!(0),
hashes: EventHash { sha256: "".into() }, hashes: EventHash { sha256: "".into() },
signatures: btreemap! {}, signatures: btreemap! {},
}), }),
@ -525,14 +524,16 @@ fn BAN_STATE_SET() -> BTreeMap<EventId, Arc<StateEvent>> {
pub mod event { pub mod event {
use std::{collections::BTreeMap, time::SystemTime}; use std::{collections::BTreeMap, time::SystemTime};
use ruma::{ use js_int::UInt;
events::{ use ruma_events::{
pdu::{EventHash, Pdu}, pdu::{EventHash, Pdu},
room::member::MembershipState, room::member::MembershipState,
EventType, EventType,
},
EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UInt, UserId,
}; };
use ruma_identifiers::{
EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UserId,
};
use ruma_serde::CanonicalJsonObject;
use ruma_state_res::Event; use ruma_state_res::Event;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
@ -612,7 +613,7 @@ pub mod event {
pub fn from_id_canon_obj( pub fn from_id_canon_obj(
id: EventId, id: EventId,
json: ruma::serde::CanonicalJsonObject, json: CanonicalJsonObject,
) -> Result<Self, serde_json::Error> { ) -> Result<Self, serde_json::Error> {
Ok(Self { Ok(Self {
event_id: id, event_id: id,

View File

@ -1,19 +1,19 @@
use std::{convert::TryFrom, sync::Arc}; use std::{convert::TryFrom, sync::Arc};
use js_int::int;
use log::warn; use log::warn;
use maplit::btreeset; use maplit::btreeset;
use ruma::{ use ruma_events::{
events::{
room::{ room::{
create::CreateEventContent, create::CreateEventContent,
join_rules::{JoinRule, JoinRulesEventContent}, join_rules::{JoinRule, JoinRulesEventContent},
member::{MembershipState, ThirdPartyInvite}, member::{MembershipState, ThirdPartyInvite},
power_levels::PowerLevelsEventContent, power_levels::PowerLevelsEventContent,
third_party_invite::ThirdPartyInviteEventContent,
}, },
EventType, EventType,
},
RoomVersionId, UserId,
}; };
use ruma_identifiers::{RoomVersionId, UserId};
use crate::{room_version::RoomVersion, Error, Event, Result, StateMap}; use crate::{room_version::RoomVersion, Error, Event, Result, StateMap};
@ -799,7 +799,7 @@ pub fn can_send_invite<E: Event>(event: &Arc<E>, auth_events: &StateMap<Arc<E>>)
let invite_level = auth_events let invite_level = auth_events
.get(&key) .get(&key)
.map_or_else( .map_or_else(
|| Ok::<_, Error>(ruma::int!(50)), || Ok::<_, Error>(int!(50)),
|power_levels| { |power_levels| {
serde_json::from_value::<PowerLevelsEventContent>(power_levels.content()) serde_json::from_value::<PowerLevelsEventContent>(power_levels.content())
.map(|pl| pl.invite) .map(|pl| pl.invite)
@ -837,9 +837,8 @@ pub fn verify_third_party_invite<E: Event>(
// If any signature in signed matches any public key in the m.room.third_party_invite event, // If any signature in signed matches any public key in the m.room.third_party_invite event,
// allow // allow
if let Ok(tpid_ev) = serde_json::from_value::< if let Ok(tpid_ev) =
ruma::events::room::third_party_invite::ThirdPartyInviteEventContent, serde_json::from_value::<ThirdPartyInviteEventContent>(current_tpid.content())
>(current_tpid.content())
{ {
// A list of public keys in the public_keys field // A list of public keys in the public_keys field
for key in tpid_ev.public_keys.unwrap_or_default() { for key in tpid_ev.public_keys.unwrap_or_default() {

View File

@ -7,16 +7,14 @@ use std::{
use maplit::btreeset; use maplit::btreeset;
use room_version::RoomVersion; use room_version::RoomVersion;
use ruma::{ use ruma_events::{
events::{
room::{ room::{
member::{MemberEventContent, MembershipState}, member::{MemberEventContent, MembershipState},
power_levels::PowerLevelsEventContent, power_levels::PowerLevelsEventContent,
}, },
EventType, EventType,
},
EventId, RoomId, RoomVersionId,
}; };
use ruma_identifiers::{EventId, RoomId, RoomVersionId};
mod error; mod error;
pub mod event_auth; pub mod event_auth;

View File

@ -1,4 +1,4 @@
use ruma::RoomVersionId; use ruma_identifiers::RoomVersionId;
use crate::{Error, Result}; use crate::{Error, Result};

View File

@ -1,9 +1,8 @@
use std::{collections::BTreeMap, time::SystemTime}; use std::{collections::BTreeMap, time::SystemTime};
use ruma::{ use js_int::UInt;
events::{pdu::EventHash, EventType}, use ruma_events::{pdu::EventHash, EventType};
EventId, RoomId, ServerName, UInt, UserId, use ruma_identifiers::{EventId, RoomId, ServerName, ServerSigningKeyId, UserId};
};
use serde_json::value::Value as JsonValue; use serde_json::value::Value as JsonValue;
/// Abstraction of a PDU so users can have their own PDU types. /// Abstraction of a PDU so users can have their own PDU types.
@ -48,5 +47,5 @@ pub trait Event {
fn hashes(&self) -> &EventHash; fn hashes(&self) -> &EventHash;
fn signatures(&self) -> BTreeMap<Box<ServerName>, BTreeMap<ruma::ServerSigningKeyId, String>>; fn signatures(&self) -> BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, String>>;
} }

View File

@ -1,5 +1,6 @@
use std::sync::Arc; use std::sync::Arc;
use ruma_events::EventType;
use ruma_state_res::{event_auth::valid_membership_change, StateMap}; use ruma_state_res::{event_auth::valid_membership_change, StateMap};
// use ruma_state_res::event_auth:::{ // use ruma_state_res::event_auth:::{
// auth_check, auth_types_for_event, can_federate, check_power_levels, check_redaction, // auth_check, auth_types_for_event, can_federate, check_power_levels, check_redaction,
@ -22,7 +23,7 @@ fn test_ban_pass() {
let requester = to_pdu_event( let requester = to_pdu_event(
"HELLO", "HELLO",
alice(), alice(),
ruma::events::EventType::RoomMember, EventType::RoomMember,
Some(charlie().as_str()), Some(charlie().as_str()),
member_content_ban(), member_content_ban(),
&[], &[],
@ -54,7 +55,7 @@ fn test_ban_fail() {
let requester = to_pdu_event( let requester = to_pdu_event(
"HELLO", "HELLO",
charlie(), charlie(),
ruma::events::EventType::RoomMember, EventType::RoomMember,
Some(alice().as_str()), Some(alice().as_str()),
member_content_ban(), member_content_ban(),
&[], &[],

View File

@ -1,6 +1,7 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use ruma::{events::EventType, EventId}; use ruma_events::EventType;
use ruma_identifiers::EventId;
use ruma_state_res::{is_power_event, room_version::RoomVersion, StateMap, StateResolution}; use ruma_state_res::{is_power_event, room_version::RoomVersion, StateMap, StateResolution};
mod utils; mod utils;

View File

@ -2,7 +2,8 @@
use std::{collections::BTreeMap, sync::Arc}; use std::{collections::BTreeMap, sync::Arc};
use ruma::{events::EventType, EventId, RoomVersionId}; use ruma_events::EventType;
use ruma_identifiers::{EventId, RoomVersionId};
use ruma_state_res::{EventMap, StateMap, StateResolution}; use ruma_state_res::{EventMap, StateMap, StateResolution};
use serde_json::json; use serde_json::json;

View File

@ -1,10 +1,8 @@
use std::{sync::Arc, time::UNIX_EPOCH}; use std::{sync::Arc, time::UNIX_EPOCH};
use maplit::btreemap; use maplit::btreemap;
use ruma::{ use ruma_events::{room::join_rules::JoinRule, EventType};
events::{room::join_rules::JoinRule, EventType}, use ruma_identifiers::{EventId, RoomVersionId};
EventId, RoomVersionId,
};
use ruma_state_res::{EventMap, StateMap, StateResolution}; use ruma_state_res::{EventMap, StateMap, StateResolution};
use serde_json::json; use serde_json::json;
use tracing_subscriber as tracer; use tracing_subscriber as tracer;

View File

@ -7,18 +7,17 @@ use std::{
time::{Duration, UNIX_EPOCH}, time::{Duration, UNIX_EPOCH},
}; };
use js_int::uint;
use maplit::btreemap; use maplit::btreemap;
use ruma::{ use ruma_events::{
events::{
pdu::{EventHash, Pdu, RoomV3Pdu}, pdu::{EventHash, Pdu, RoomV3Pdu},
room::{ room::{
join_rules::JoinRule, join_rules::JoinRule,
member::{MemberEventContent, MembershipState}, member::{MemberEventContent, MembershipState},
}, },
EventType, EventType,
},
EventId, RoomId, RoomVersionId, UserId,
}; };
use ruma_identifiers::{EventId, RoomId, RoomVersionId, UserId};
use ruma_state_res::{auth_types_for_event, Error, Event, Result, StateMap, StateResolution}; use ruma_state_res::{auth_types_for_event, Error, Event, Result, StateMap, StateResolution};
use serde_json::{json, Value as JsonValue}; use serde_json::{json, Value as JsonValue};
use tracing_subscriber as tracer; use tracing_subscriber as tracer;
@ -350,7 +349,7 @@ pub fn to_init_pdu_event(
origin: "foo".into(), origin: "foo".into(),
auth_events: vec![], auth_events: vec![],
prev_events: vec![], prev_events: vec![],
depth: ruma::uint!(0), depth: uint!(0),
hashes: EventHash { sha256: "".into() }, hashes: EventHash { sha256: "".into() },
signatures: btreemap! {}, signatures: btreemap! {},
}), }),
@ -395,7 +394,7 @@ where
origin: "foo".into(), origin: "foo".into(),
auth_events, auth_events,
prev_events, prev_events,
depth: ruma::uint!(0), depth: uint!(0),
hashes: EventHash { sha256: "".into() }, hashes: EventHash { sha256: "".into() },
signatures: btreemap! {}, signatures: btreemap! {},
}), }),
@ -499,14 +498,16 @@ pub fn INITIAL_EDGES() -> Vec<EventId> {
pub mod event { pub mod event {
use std::{collections::BTreeMap, time::SystemTime}; use std::{collections::BTreeMap, time::SystemTime};
use ruma::{ use js_int::UInt;
events::{ use ruma_events::{
pdu::{EventHash, Pdu}, pdu::{EventHash, Pdu},
room::member::{MemberEventContent, MembershipState}, room::member::{MemberEventContent, MembershipState},
EventType, EventType,
},
EventId, RoomId, RoomVersionId, ServerName, UInt, UserId,
}; };
use ruma_identifiers::{
EventId, RoomId, RoomVersionId, ServerName, ServerSigningKeyId, UserId,
};
use ruma_serde::CanonicalJsonObject;
use ruma_state_res::Event; use ruma_state_res::Event;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
@ -552,9 +553,7 @@ pub mod event {
fn hashes(&self) -> &EventHash { fn hashes(&self) -> &EventHash {
self.hashes() self.hashes()
} }
fn signatures( fn signatures(&self) -> BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, String>> {
&self,
) -> BTreeMap<Box<ServerName>, BTreeMap<ruma::ServerSigningKeyId, String>> {
self.signatures() self.signatures()
} }
fn unsigned(&self) -> &BTreeMap<String, JsonValue> { fn unsigned(&self) -> &BTreeMap<String, JsonValue> {
@ -579,7 +578,7 @@ pub mod event {
pub fn from_id_canon_obj( pub fn from_id_canon_obj(
id: EventId, id: EventId,
json: ruma::serde::CanonicalJsonObject, json: CanonicalJsonObject,
) -> Result<Self, serde_json::Error> { ) -> Result<Self, serde_json::Error> {
Ok(Self { Ok(Self {
event_id: id, event_id: id,
@ -704,7 +703,7 @@ pub mod event {
pub fn signatures( pub fn signatures(
&self, &self,
) -> BTreeMap<Box<ServerName>, BTreeMap<ruma::ServerSigningKeyId, String>> { ) -> BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, String>> {
match &self.rest { match &self.rest {
Pdu::RoomV1Pdu(_) => maplit::btreemap! {}, Pdu::RoomV1Pdu(_) => maplit::btreemap! {},
Pdu::RoomV3Pdu(ev) => ev.signatures.clone(), Pdu::RoomV3Pdu(ev) => ev.signatures.clone(),