mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-07 23:44:53 -04:00
Upgrade Ruma
This commit is contained in:
@@ -27,5 +27,5 @@ byteorder = "1.4.3"
|
||||
image = { version = "0.23.14", optional = true }
|
||||
qrcode = { version = "0.12.0", default-features = false }
|
||||
rqrr = { version = "0.4.0", optional = true }
|
||||
ruma-identifiers = { git = "https://github.com/ruma/ruma", rev = "ac6ecc3e5" }
|
||||
ruma-identifiers = { git = "https://github.com/ruma/ruma", rev = "6c4892664" }
|
||||
thiserror = "1.0.25"
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
convert::{TryFrom, TryInto},
|
||||
io::{Cursor, Read},
|
||||
};
|
||||
|
||||
@@ -316,7 +316,7 @@ impl QrVerificationData {
|
||||
|
||||
match mode {
|
||||
VerificationData::QR_MODE => {
|
||||
let event_id = EventId::try_from(flow_id)?;
|
||||
let event_id = flow_id.try_into()?;
|
||||
Ok(VerificationData::new(event_id, first_key, second_key, shared_secret).into())
|
||||
}
|
||||
SelfVerificationData::QR_MODE => {
|
||||
@@ -375,7 +375,7 @@ impl QrVerificationData {
|
||||
/// cross signing keys.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct VerificationData {
|
||||
event_id: EventId,
|
||||
event_id: Box<EventId>,
|
||||
first_master_key: String,
|
||||
second_master_key: String,
|
||||
shared_secret: String,
|
||||
@@ -398,7 +398,7 @@ impl VerificationData {
|
||||
/// * ` shared_secret` - A random bytestring encoded as unpadded base64,
|
||||
/// needs to be at least 8 bytes long.
|
||||
pub fn new(
|
||||
event_id: EventId,
|
||||
event_id: Box<EventId>,
|
||||
first_key: String,
|
||||
second_key: String,
|
||||
shared_secret: String,
|
||||
|
||||
@@ -38,7 +38,7 @@ warp = { version = "0.3.1", optional = true, default-features = false }
|
||||
|
||||
[dependencies.ruma]
|
||||
git = "https://github.com/ruma/ruma"
|
||||
rev = "ac6ecc3e5"
|
||||
rev = "6c4892664"
|
||||
features = ["client-api-c", "appservice-api-s", "unstable-pre-spec"]
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -21,7 +21,7 @@ pub async fn handle_room_member(
|
||||
if !appservice.user_id_is_in_namespace(&event.state_key)? {
|
||||
trace!("not an appservice user: {}", event.state_key);
|
||||
} else if let MembershipState::Invite = event.content.membership {
|
||||
let user_id = UserId::try_from(event.state_key.as_str())?;
|
||||
let user_id = Box::<UserId>::try_from(event.state_key.as_str())?;
|
||||
appservice.register_virtual_user(user_id.localpart()).await?;
|
||||
|
||||
let client = appservice.virtual_user_client(user_id.localpart()).await?;
|
||||
|
||||
@@ -107,7 +107,7 @@ use ruma::{
|
||||
},
|
||||
client::r0::account::register,
|
||||
},
|
||||
assign, identifiers, DeviceId, ServerNameBox, UserId,
|
||||
assign, identifiers, DeviceId, ServerName, UserId,
|
||||
};
|
||||
use serde::de::DeserializeOwned;
|
||||
use tracing::info;
|
||||
@@ -203,7 +203,7 @@ pub type VirtualUser = ();
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AppService {
|
||||
homeserver_url: Url,
|
||||
server_name: ServerNameBox,
|
||||
server_name: Box<ServerName>,
|
||||
registration: Arc<AppServiceRegistration>,
|
||||
clients: Arc<DashMap<Localpart, Client>>,
|
||||
event_handler: event_handler::EventHandler,
|
||||
@@ -227,7 +227,7 @@ impl AppService {
|
||||
/// [AppService Registration]: https://matrix.org/docs/spec/application_service/r0.1.2#registration
|
||||
pub async fn new(
|
||||
homeserver_url: impl TryInto<Url, Error = url::ParseError>,
|
||||
server_name: impl TryInto<ServerNameBox, Error = identifiers::Error>,
|
||||
server_name: impl TryInto<Box<ServerName>, Error = identifiers::Error>,
|
||||
registration: AppServiceRegistration,
|
||||
) -> Result<Self> {
|
||||
let appservice = Self::new_with_config(
|
||||
@@ -245,7 +245,7 @@ impl AppService {
|
||||
/// [`Client`]
|
||||
pub async fn new_with_config(
|
||||
homeserver_url: impl TryInto<Url, Error = url::ParseError>,
|
||||
server_name: impl TryInto<ServerNameBox, Error = identifiers::Error>,
|
||||
server_name: impl TryInto<Box<ServerName>, Error = identifiers::Error>,
|
||||
registration: AppServiceRegistration,
|
||||
client_config: ClientConfig,
|
||||
) -> Result<Self> {
|
||||
|
||||
@@ -35,7 +35,7 @@ matrix-sdk-common = { version = "0.4.0", path = "../matrix-sdk-common" }
|
||||
matrix-sdk-crypto = { version = "0.4.0", path = "../matrix-sdk-crypto", optional = true }
|
||||
pbkdf2 = { version = "0.9.0", default-features = false, optional = true }
|
||||
rand = { version = "0.8.4", optional = true }
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "ac6ecc3e5", features = ["client-api-c", "unstable-pre-spec"] }
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "6c4892664", features = ["client-api-c", "unstable-pre-spec"] }
|
||||
serde = { version = "1.0.126", features = ["rc"] }
|
||||
serde_json = "1.0.64"
|
||||
sha2 = { version = "0.9.5", optional = true }
|
||||
|
||||
@@ -223,27 +223,27 @@ impl Inspector {
|
||||
match matches.subcommand() {
|
||||
("get-profiles", args) => {
|
||||
let args = args.expect("No args provided for get-state");
|
||||
let room_id = RoomId::try_from(args.value_of("room-id").unwrap()).unwrap();
|
||||
let room_id = Box::<RoomId>::try_from(args.value_of("room-id").unwrap()).unwrap();
|
||||
|
||||
self.get_profiles(room_id).await;
|
||||
}
|
||||
|
||||
("get-members", args) => {
|
||||
let args = args.expect("No args provided for get-state");
|
||||
let room_id = RoomId::try_from(args.value_of("room-id").unwrap()).unwrap();
|
||||
let room_id = Box::<RoomId>::try_from(args.value_of("room-id").unwrap()).unwrap();
|
||||
|
||||
self.get_members(room_id).await;
|
||||
}
|
||||
("list-rooms", _) => self.list_rooms().await,
|
||||
("get-display-names", args) => {
|
||||
let args = args.expect("No args provided for get-state");
|
||||
let room_id = RoomId::try_from(args.value_of("room-id").unwrap()).unwrap();
|
||||
let room_id = Box::<RoomId>::try_from(args.value_of("room-id").unwrap()).unwrap();
|
||||
let display_name = args.value_of("display-name").unwrap().to_string();
|
||||
self.get_display_name_owners(room_id, display_name).await;
|
||||
}
|
||||
("get-state", args) => {
|
||||
let args = args.expect("No args provided for get-state");
|
||||
let room_id = RoomId::try_from(args.value_of("room-id").unwrap()).unwrap();
|
||||
let room_id = Box::<RoomId>::try_from(args.value_of("room-id").unwrap()).unwrap();
|
||||
let event_type = EventType::try_from(args.value_of("event-type").unwrap()).unwrap();
|
||||
self.get_state(room_id, event_type).await;
|
||||
}
|
||||
@@ -256,13 +256,13 @@ impl Inspector {
|
||||
self.printer.pretty_print_struct(&rooms);
|
||||
}
|
||||
|
||||
async fn get_display_name_owners(&self, room_id: RoomId, display_name: String) {
|
||||
async fn get_display_name_owners(&self, room_id: Box<RoomId>, display_name: String) {
|
||||
let users = self.store.get_users_with_display_name(&room_id, &display_name).await.unwrap();
|
||||
self.printer.pretty_print_struct(&users);
|
||||
}
|
||||
|
||||
async fn get_profiles(&self, room_id: RoomId) {
|
||||
let joined: Vec<UserId> = self.store.get_joined_user_ids(&room_id).await.unwrap();
|
||||
async fn get_profiles(&self, room_id: Box<RoomId>) {
|
||||
let joined: Vec<Box<UserId>> = self.store.get_joined_user_ids(&room_id).await.unwrap();
|
||||
|
||||
for member in joined {
|
||||
let event = self.store.get_profile(&room_id, &member).await.unwrap();
|
||||
@@ -270,8 +270,8 @@ impl Inspector {
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_members(&self, room_id: RoomId) {
|
||||
let joined: Vec<UserId> = self.store.get_joined_user_ids(&room_id).await.unwrap();
|
||||
async fn get_members(&self, room_id: Box<RoomId>) {
|
||||
let joined: Vec<Box<UserId>> = self.store.get_joined_user_ids(&room_id).await.unwrap();
|
||||
|
||||
for member in joined {
|
||||
let event = self.store.get_member_event(&room_id, &member).await.unwrap();
|
||||
@@ -279,7 +279,7 @@ impl Inspector {
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_state(&self, room_id: RoomId, event_type: EventType) {
|
||||
async fn get_state(&self, room_id: Box<RoomId>, event_type: EventType) {
|
||||
self.printer.pretty_print_struct(
|
||||
&self.store.get_state_event(&room_id, event_type, "").await.unwrap(),
|
||||
);
|
||||
@@ -290,22 +290,30 @@ impl Inspector {
|
||||
SubCommand::with_name("list-rooms"),
|
||||
SubCommand::with_name("get-members").arg(
|
||||
Arg::with_name("room-id").required(true).validator(|r| {
|
||||
RoomId::try_from(r).map(|_| ()).map_err(|_| "Invalid room id given".to_owned())
|
||||
Box::<RoomId>::try_from(r)
|
||||
.map(|_| ())
|
||||
.map_err(|_| "Invalid room id given".to_owned())
|
||||
}),
|
||||
),
|
||||
SubCommand::with_name("get-profiles").arg(
|
||||
Arg::with_name("room-id").required(true).validator(|r| {
|
||||
RoomId::try_from(r).map(|_| ()).map_err(|_| "Invalid room id given".to_owned())
|
||||
Box::<RoomId>::try_from(r)
|
||||
.map(|_| ())
|
||||
.map_err(|_| "Invalid room id given".to_owned())
|
||||
}),
|
||||
),
|
||||
SubCommand::with_name("get-display-names")
|
||||
.arg(Arg::with_name("room-id").required(true).validator(|r| {
|
||||
RoomId::try_from(r).map(|_| ()).map_err(|_| "Invalid room id given".to_owned())
|
||||
Box::<RoomId>::try_from(r)
|
||||
.map(|_| ())
|
||||
.map_err(|_| "Invalid room id given".to_owned())
|
||||
}))
|
||||
.arg(Arg::with_name("display-name").required(true)),
|
||||
SubCommand::with_name("get-state")
|
||||
.arg(Arg::with_name("room-id").required(true).validator(|r| {
|
||||
RoomId::try_from(r).map(|_| ()).map_err(|_| "Invalid room id given".to_owned())
|
||||
Box::<RoomId>::try_from(r)
|
||||
.map(|_| ())
|
||||
.map_err(|_| "Invalid room id given".to_owned())
|
||||
}))
|
||||
.arg(Arg::with_name("event-type").required(true).validator(|e| {
|
||||
EventType::try_from(e).map(|_| ()).map_err(|_| "Invalid event type".to_string())
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#[cfg(feature = "encryption")]
|
||||
use std::ops::Deref;
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
convert::TryFrom,
|
||||
@@ -352,7 +354,7 @@ impl BaseClient {
|
||||
room_info: &mut RoomInfo,
|
||||
changes: &mut StateChanges,
|
||||
ambiguity_cache: &mut AmbiguityCache,
|
||||
user_ids: &mut BTreeSet<UserId>,
|
||||
user_ids: &mut BTreeSet<Box<UserId>>,
|
||||
) -> Result<Timeline> {
|
||||
let room_id = room.room_id();
|
||||
let user_id = room.own_user_id();
|
||||
@@ -388,14 +390,14 @@ impl BaseClient {
|
||||
if member.state_key == member.sender {
|
||||
changes
|
||||
.profiles
|
||||
.entry(room_id.clone())
|
||||
.entry(room_id.to_owned())
|
||||
.or_insert_with(BTreeMap::new)
|
||||
.insert(member.sender.clone(), member.content.clone());
|
||||
}
|
||||
|
||||
changes
|
||||
.members
|
||||
.entry(room_id.clone())
|
||||
.entry(room_id.to_owned())
|
||||
.or_insert_with(BTreeMap::new)
|
||||
.insert(member.state_key.clone(), member);
|
||||
}
|
||||
@@ -443,7 +445,7 @@ impl BaseClient {
|
||||
actions,
|
||||
event.event.clone(),
|
||||
false,
|
||||
room_id.clone(),
|
||||
room_id.to_owned(),
|
||||
MilliSecondsSinceUnixEpoch::now(),
|
||||
),
|
||||
);
|
||||
@@ -475,7 +477,7 @@ impl BaseClient {
|
||||
events: &[Raw<AnyStrippedStateEvent>],
|
||||
room_info: &mut RoomInfo,
|
||||
) -> (
|
||||
BTreeMap<UserId, StrippedMemberEvent>,
|
||||
BTreeMap<Box<UserId>, StrippedMemberEvent>,
|
||||
BTreeMap<String, BTreeMap<String, Raw<AnyStrippedStateEvent>>>,
|
||||
) {
|
||||
events.iter().fold(
|
||||
@@ -520,7 +522,7 @@ impl BaseClient {
|
||||
ambiguity_cache: &mut AmbiguityCache,
|
||||
events: &[Raw<AnySyncStateEvent>],
|
||||
room_info: &mut RoomInfo,
|
||||
) -> StoreResult<BTreeSet<UserId>> {
|
||||
) -> StoreResult<BTreeSet<Box<UserId>>> {
|
||||
let mut members = BTreeMap::new();
|
||||
let mut state_events = BTreeMap::new();
|
||||
let mut user_ids = BTreeSet::new();
|
||||
@@ -577,9 +579,9 @@ impl BaseClient {
|
||||
}
|
||||
}
|
||||
|
||||
changes.members.insert(room_id.as_ref().clone(), members);
|
||||
changes.profiles.insert(room_id.as_ref().clone(), profiles);
|
||||
changes.state.insert(room_id.as_ref().clone(), state_events);
|
||||
changes.members.insert((&*room_id).to_owned(), members);
|
||||
changes.profiles.insert((&*room_id).to_owned(), profiles);
|
||||
changes.state.insert((&*room_id).to_owned(), state_events);
|
||||
|
||||
Ok(user_ids)
|
||||
}
|
||||
@@ -748,11 +750,12 @@ impl BaseClient {
|
||||
let joined = self.store.get_joined_user_ids(&room_id).await?;
|
||||
let invited = self.store.get_invited_user_ids(&room_id).await?;
|
||||
|
||||
let user_ids: Vec<&UserId> = joined.iter().chain(&invited).collect();
|
||||
let user_ids: Vec<&UserId> =
|
||||
joined.iter().chain(&invited).map(Deref::deref).collect();
|
||||
o.update_tracked_users(user_ids).await
|
||||
}
|
||||
|
||||
o.update_tracked_users(&user_ids).await
|
||||
o.update_tracked_users(user_ids.iter().map(|x| &**x)).await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -923,14 +926,14 @@ impl BaseClient {
|
||||
if member.state_key == member.sender {
|
||||
changes
|
||||
.profiles
|
||||
.entry(room_id.clone())
|
||||
.entry(room_id.to_owned())
|
||||
.or_insert_with(BTreeMap::new)
|
||||
.insert(member.sender.clone(), member.content.clone());
|
||||
}
|
||||
|
||||
changes
|
||||
.members
|
||||
.entry(room_id.clone())
|
||||
.entry(room_id.to_owned())
|
||||
.or_insert_with(BTreeMap::new)
|
||||
.insert(member.state_key.clone(), member.clone());
|
||||
}
|
||||
@@ -939,7 +942,7 @@ impl BaseClient {
|
||||
#[cfg(feature = "encryption")]
|
||||
if room_info.is_encrypted() {
|
||||
if let Some(o) = self.olm_machine().await {
|
||||
o.update_tracked_users(&user_ids).await
|
||||
o.update_tracked_users(user_ids.iter().map(Deref::deref)).await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1077,7 +1080,7 @@ impl BaseClient {
|
||||
let settings = settings.ok_or(MegolmError::EncryptionNotEnabled)?;
|
||||
let settings = EncryptionSettings::new(settings, history_visibility);
|
||||
|
||||
Ok(o.share_group_session(room_id, members, settings).await?)
|
||||
Ok(o.share_group_session(room_id, members.map(Deref::deref), settings).await?)
|
||||
}
|
||||
None => panic!("Olm machine wasn't started"),
|
||||
}
|
||||
@@ -1145,10 +1148,10 @@ impl BaseClient {
|
||||
/// # use matrix_sdk_base::BaseClient;
|
||||
/// # use ruma::UserId;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = UserId::try_from("@alice:example.org").unwrap();
|
||||
/// # let alice = Box::<UserId>::try_from("@alice:example.org").unwrap();
|
||||
/// # let client = BaseClient::new().unwrap();
|
||||
/// # block_on(async {
|
||||
/// let device = client.get_device(&alice, "DEVICEID".into()).await;
|
||||
/// let device = client.get_device(&alice, device_id!("DEVICEID")).await;
|
||||
///
|
||||
/// println!("{:?}", device);
|
||||
/// # });
|
||||
@@ -1201,7 +1204,7 @@ impl BaseClient {
|
||||
/// # use matrix_sdk_base::BaseClient;
|
||||
/// # use ruma::UserId;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = UserId::try_from("@alice:example.org").unwrap();
|
||||
/// # let alice = Box::<UserId>::try_from("@alice:example.org").unwrap();
|
||||
/// # let client = BaseClient::new().unwrap();
|
||||
/// # block_on(async {
|
||||
/// let devices = client.get_user_devices(&alice).await.unwrap();
|
||||
@@ -1307,7 +1310,7 @@ impl BaseClient {
|
||||
};
|
||||
|
||||
Ok(Some(PushConditionRoomCtx {
|
||||
room_id: room_id.clone(),
|
||||
room_id: room_id.to_owned(),
|
||||
member_count: UInt::new(member_count).unwrap_or(UInt::MAX),
|
||||
user_display_name,
|
||||
users_power_levels: room_power_levels.users,
|
||||
@@ -1330,7 +1333,8 @@ impl BaseClient {
|
||||
|
||||
push_rules.member_count = UInt::new(room_info.active_members_count()).unwrap_or(UInt::MAX);
|
||||
|
||||
if let Some(member) = changes.members.get(room_id).and_then(|members| members.get(user_id))
|
||||
if let Some(member) =
|
||||
changes.members.get(&**room_id).and_then(|members| members.get(user_id))
|
||||
{
|
||||
push_rules.user_display_name =
|
||||
member.content.displayname.clone().unwrap_or_else(|| user_id.localpart().to_owned())
|
||||
@@ -1338,7 +1342,7 @@ impl BaseClient {
|
||||
|
||||
if let Some(AnySyncStateEvent::RoomPowerLevels(event)) = changes
|
||||
.state
|
||||
.get(room_id)
|
||||
.get(&**room_id)
|
||||
.and_then(|types| types.get(EventType::RoomPowerLevels.as_str()))
|
||||
.and_then(|events| events.get(""))
|
||||
.and_then(|e| e.deserialize().ok())
|
||||
|
||||
@@ -68,7 +68,7 @@ impl UniqueKey for MediaThumbnailSize {
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum MediaType {
|
||||
/// A media content URI.
|
||||
Uri(MxcUri),
|
||||
Uri(Box<MxcUri>),
|
||||
|
||||
/// An encrypted media content.
|
||||
Encrypted(Box<EncryptedFile>),
|
||||
@@ -219,7 +219,7 @@ pub(crate) mod test {
|
||||
|
||||
use super::*;
|
||||
|
||||
fn encrypted_test_data() -> (MxcUri, EncryptedFile) {
|
||||
fn encrypted_test_data() -> (Box<MxcUri>, EncryptedFile) {
|
||||
let c = &mut std::io::Cursor::new("some content");
|
||||
let reader = crate::crypto::AttachmentEncryptor::new(c);
|
||||
|
||||
|
||||
@@ -67,8 +67,8 @@ impl RoomMember {
|
||||
/// Get the avatar url of the member, if there is one.
|
||||
pub fn avatar_url(&self) -> Option<&MxcUri> {
|
||||
match self.profile.as_ref() {
|
||||
Some(p) => p.avatar_url.as_ref(),
|
||||
None => self.event.content.avatar_url.as_ref(),
|
||||
Some(p) => p.avatar_url.as_deref(),
|
||||
None => self.event.content.avatar_url.as_deref(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,14 +24,14 @@ use serde::{Deserialize, Serialize};
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct BaseRoomInfo {
|
||||
/// The avatar URL of this room.
|
||||
pub avatar_url: Option<MxcUri>,
|
||||
pub avatar_url: Option<Box<MxcUri>>,
|
||||
/// The canonical alias of this room.
|
||||
pub canonical_alias: Option<RoomAliasId>,
|
||||
pub canonical_alias: Option<Box<RoomAliasId>>,
|
||||
/// The `m.room.create` event content of this room.
|
||||
pub create: Option<RoomCreateEventContent>,
|
||||
/// The user id this room is sharing the direct message with, if the room is
|
||||
/// a direct message.
|
||||
pub dm_target: Option<UserId>,
|
||||
pub dm_target: Option<Box<UserId>>,
|
||||
/// The `m.room.encryption` event content that enabled E2EE in this room.
|
||||
pub encryption: Option<RoomEncryptionEventContent>,
|
||||
/// The guest access policy of this room.
|
||||
|
||||
@@ -87,10 +87,8 @@ impl Room {
|
||||
room_id: &RoomId,
|
||||
room_type: RoomType,
|
||||
) -> Self {
|
||||
let room_id = Arc::new(room_id.clone());
|
||||
|
||||
let room_info = RoomInfo {
|
||||
room_id,
|
||||
room_id: room_id.into(),
|
||||
room_type,
|
||||
notification_counts: Default::default(),
|
||||
summary: Default::default(),
|
||||
@@ -108,7 +106,7 @@ impl Room {
|
||||
room_info: RoomInfo,
|
||||
) -> Self {
|
||||
Self {
|
||||
own_user_id: Arc::new(own_user_id.clone()),
|
||||
own_user_id: own_user_id.into(),
|
||||
room_id: room_info.room_id.clone(),
|
||||
store,
|
||||
inner: Arc::new(SyncRwLock::new(room_info)),
|
||||
@@ -160,12 +158,12 @@ impl Room {
|
||||
}
|
||||
|
||||
/// Get the avatar url of this room.
|
||||
pub fn avatar_url(&self) -> Option<MxcUri> {
|
||||
pub fn avatar_url(&self) -> Option<Box<MxcUri>> {
|
||||
self.inner.read().unwrap().base_info.avatar_url.clone()
|
||||
}
|
||||
|
||||
/// Get the canonical alias of this room.
|
||||
pub fn canonical_alias(&self) -> Option<RoomAliasId> {
|
||||
pub fn canonical_alias(&self) -> Option<Box<RoomAliasId>> {
|
||||
self.inner.read().unwrap().base_info.canonical_alias.clone()
|
||||
}
|
||||
|
||||
@@ -189,7 +187,7 @@ impl Room {
|
||||
/// *Note*: The member list might have been modified in the meantime and
|
||||
/// the target might not even be in the room anymore. This setting should
|
||||
/// only be considered as guidance.
|
||||
pub fn direct_target(&self) -> Option<UserId> {
|
||||
pub fn direct_target(&self) -> Option<Box<UserId>> {
|
||||
self.inner.read().unwrap().base_info.dm_target.clone()
|
||||
}
|
||||
|
||||
@@ -264,7 +262,7 @@ impl Room {
|
||||
|
||||
/// Get the list of users ids that are considered to be joined members of
|
||||
/// this room.
|
||||
pub async fn joined_user_ids(&self) -> StoreResult<Vec<UserId>> {
|
||||
pub async fn joined_user_ids(&self) -> StoreResult<Vec<Box<UserId>>> {
|
||||
self.store.get_joined_user_ids(self.room_id()).await
|
||||
}
|
||||
|
||||
@@ -348,7 +346,7 @@ impl Room {
|
||||
let members: Vec<_> =
|
||||
stream::iter(summary.heroes.iter().filter(|u| !is_own_user_id(u)))
|
||||
.filter_map(|u| async move {
|
||||
let user_id = UserId::try_from(u.as_str()).ok()?;
|
||||
let user_id = Box::<UserId>::try_from(u.as_str()).ok()?;
|
||||
self.get_member(&user_id).await.transpose()
|
||||
})
|
||||
.collect()
|
||||
@@ -404,7 +402,7 @@ impl Room {
|
||||
.base_info
|
||||
.create
|
||||
.as_ref()
|
||||
.map(|c| &c.creator == user_id)
|
||||
.map(|c| c.creator == user_id)
|
||||
.unwrap_or(false);
|
||||
|
||||
let power =
|
||||
@@ -460,7 +458,7 @@ impl Room {
|
||||
pub async fn user_read_receipt(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
) -> StoreResult<Option<(EventId, Receipt)>> {
|
||||
) -> StoreResult<Option<(Box<EventId>, Receipt)>> {
|
||||
self.store.get_user_room_receipt_event(self.room_id(), ReceiptType::Read, user_id).await
|
||||
}
|
||||
|
||||
@@ -469,7 +467,7 @@ impl Room {
|
||||
pub async fn event_read_receipts(
|
||||
&self,
|
||||
event_id: &EventId,
|
||||
) -> StoreResult<Vec<(UserId, Receipt)>> {
|
||||
) -> StoreResult<Vec<(Box<UserId>, Receipt)>> {
|
||||
self.store.get_event_room_receipt_events(self.room_id(), ReceiptType::Read, event_id).await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
//! User sessions.
|
||||
|
||||
use ruma::{DeviceIdBox, UserId};
|
||||
use ruma::{DeviceId, UserId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// A user session, containing an access token and information about the
|
||||
@@ -25,12 +25,12 @@ use serde::{Deserialize, Serialize};
|
||||
///
|
||||
/// ```
|
||||
/// use matrix_sdk_base::Session;
|
||||
/// use ruma::{DeviceIdBox, user_id};
|
||||
/// use ruma::{device_id, user_id};
|
||||
///
|
||||
/// let session = Session {
|
||||
/// access_token: "My-Token".to_owned(),
|
||||
/// user_id: user_id!("@example:localhost"),
|
||||
/// device_id: DeviceIdBox::from("MYDEVICEID"),
|
||||
/// user_id: user_id!("@example:localhost").to_owned(),
|
||||
/// device_id: device_id!("MYDEVICEID").to_owned(),
|
||||
/// };
|
||||
///
|
||||
/// assert_eq!(session.device_id.as_str(), "MYDEVICEID");
|
||||
@@ -40,9 +40,9 @@ pub struct Session {
|
||||
/// The access token used for this session.
|
||||
pub access_token: String,
|
||||
/// The user the access token was issued for.
|
||||
pub user_id: UserId,
|
||||
pub user_id: Box<UserId>,
|
||||
/// The ID of the client device
|
||||
pub device_id: DeviceIdBox,
|
||||
pub device_id: Box<DeviceId>,
|
||||
}
|
||||
|
||||
impl From<ruma::api::client::r0::session::login::Response> for Session {
|
||||
|
||||
@@ -24,18 +24,18 @@ use crate::Store;
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AmbiguityCache {
|
||||
pub store: Store,
|
||||
pub cache: BTreeMap<RoomId, BTreeMap<String, BTreeSet<UserId>>>,
|
||||
pub changes: BTreeMap<RoomId, BTreeMap<EventId, AmbiguityChange>>,
|
||||
pub cache: BTreeMap<Box<RoomId>, BTreeMap<String, BTreeSet<Box<UserId>>>>,
|
||||
pub changes: BTreeMap<Box<RoomId>, BTreeMap<Box<EventId>, AmbiguityChange>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct AmbiguityMap {
|
||||
display_name: String,
|
||||
users: BTreeSet<UserId>,
|
||||
users: BTreeSet<Box<UserId>>,
|
||||
}
|
||||
|
||||
impl AmbiguityMap {
|
||||
fn remove(&mut self, user_id: &UserId) -> Option<UserId> {
|
||||
fn remove(&mut self, user_id: &UserId) -> Option<Box<UserId>> {
|
||||
self.users.remove(user_id);
|
||||
|
||||
if self.user_count() == 1 {
|
||||
@@ -45,7 +45,7 @@ impl AmbiguityMap {
|
||||
}
|
||||
}
|
||||
|
||||
fn add(&mut self, user_id: UserId) -> Option<UserId> {
|
||||
fn add(&mut self, user_id: Box<UserId>) -> Option<Box<UserId>> {
|
||||
let ambiguous_user =
|
||||
if self.user_count() == 1 { self.users.iter().next().cloned() } else { None };
|
||||
|
||||
@@ -129,7 +129,7 @@ impl AmbiguityCache {
|
||||
old_map: Option<AmbiguityMap>,
|
||||
new_map: Option<AmbiguityMap>,
|
||||
) {
|
||||
let entry = self.cache.entry(room_id.clone()).or_insert_with(BTreeMap::new);
|
||||
let entry = self.cache.entry(room_id.to_owned()).or_insert_with(BTreeMap::new);
|
||||
|
||||
if let Some(old) = old_map {
|
||||
entry.insert(old.display_name, old.users);
|
||||
@@ -140,8 +140,11 @@ impl AmbiguityCache {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_change(&mut self, room_id: &RoomId, event_id: EventId, change: AmbiguityChange) {
|
||||
self.changes.entry(room_id.clone()).or_insert_with(BTreeMap::new).insert(event_id, change);
|
||||
fn add_change(&mut self, room_id: &RoomId, event_id: Box<EventId>, change: AmbiguityChange) {
|
||||
self.changes
|
||||
.entry(room_id.to_owned())
|
||||
.or_insert_with(BTreeMap::new)
|
||||
.insert(event_id, change);
|
||||
}
|
||||
|
||||
async fn get(
|
||||
@@ -190,7 +193,7 @@ impl AmbiguityCache {
|
||||
|
||||
let old_map = if let Some(old_name) = old_display_name.as_deref() {
|
||||
let old_display_name_map = if let Some(u) =
|
||||
self.cache.entry(room_id.clone()).or_insert_with(BTreeMap::new).get(old_name)
|
||||
self.cache.entry(room_id.to_owned()).or_insert_with(BTreeMap::new).get(old_name)
|
||||
{
|
||||
u.clone()
|
||||
} else {
|
||||
@@ -222,7 +225,7 @@ impl AmbiguityCache {
|
||||
|
||||
let new_display_name_map = if let Some(u) = self
|
||||
.cache
|
||||
.entry(room_id.clone())
|
||||
.entry(room_id.to_owned())
|
||||
.or_insert_with(BTreeMap::new)
|
||||
.get(new_display_name)
|
||||
{
|
||||
|
||||
@@ -40,31 +40,30 @@ use crate::{
|
||||
media::{MediaRequest, UniqueKey},
|
||||
};
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MemoryStore {
|
||||
sync_token: Arc<RwLock<Option<String>>>,
|
||||
filters: Arc<DashMap<String, String>>,
|
||||
account_data: Arc<DashMap<String, Raw<AnyGlobalAccountDataEvent>>>,
|
||||
members: Arc<DashMap<RoomId, DashMap<UserId, MemberEvent>>>,
|
||||
profiles: Arc<DashMap<RoomId, DashMap<UserId, RoomMemberEventContent>>>,
|
||||
display_names: Arc<DashMap<RoomId, DashMap<String, BTreeSet<UserId>>>>,
|
||||
joined_user_ids: Arc<DashMap<RoomId, DashSet<UserId>>>,
|
||||
invited_user_ids: Arc<DashMap<RoomId, DashSet<UserId>>>,
|
||||
room_info: Arc<DashMap<RoomId, RoomInfo>>,
|
||||
#[allow(clippy::type_complexity)]
|
||||
room_state: Arc<DashMap<RoomId, DashMap<String, DashMap<String, Raw<AnySyncStateEvent>>>>>,
|
||||
room_account_data: Arc<DashMap<RoomId, DashMap<String, Raw<AnyRoomAccountDataEvent>>>>,
|
||||
stripped_room_info: Arc<DashMap<RoomId, RoomInfo>>,
|
||||
#[allow(clippy::type_complexity)]
|
||||
members: Arc<DashMap<Box<RoomId>, DashMap<Box<UserId>, MemberEvent>>>,
|
||||
profiles: Arc<DashMap<Box<RoomId>, DashMap<Box<UserId>, RoomMemberEventContent>>>,
|
||||
display_names: Arc<DashMap<Box<RoomId>, DashMap<String, BTreeSet<Box<UserId>>>>>,
|
||||
joined_user_ids: Arc<DashMap<Box<RoomId>, DashSet<Box<UserId>>>>,
|
||||
invited_user_ids: Arc<DashMap<Box<RoomId>, DashSet<Box<UserId>>>>,
|
||||
room_info: Arc<DashMap<Box<RoomId>, RoomInfo>>,
|
||||
room_state: Arc<DashMap<Box<RoomId>, DashMap<String, DashMap<String, Raw<AnySyncStateEvent>>>>>,
|
||||
room_account_data: Arc<DashMap<Box<RoomId>, DashMap<String, Raw<AnyRoomAccountDataEvent>>>>,
|
||||
stripped_room_info: Arc<DashMap<Box<RoomId>, RoomInfo>>,
|
||||
stripped_room_state:
|
||||
Arc<DashMap<RoomId, DashMap<String, DashMap<String, Raw<AnyStrippedStateEvent>>>>>,
|
||||
stripped_members: Arc<DashMap<RoomId, DashMap<UserId, StrippedMemberEvent>>>,
|
||||
presence: Arc<DashMap<UserId, Raw<PresenceEvent>>>,
|
||||
#[allow(clippy::type_complexity)]
|
||||
room_user_receipts: Arc<DashMap<RoomId, DashMap<String, DashMap<UserId, (EventId, Receipt)>>>>,
|
||||
#[allow(clippy::type_complexity)]
|
||||
room_event_receipts:
|
||||
Arc<DashMap<RoomId, DashMap<String, DashMap<EventId, DashMap<UserId, Receipt>>>>>,
|
||||
Arc<DashMap<Box<RoomId>, DashMap<String, DashMap<String, Raw<AnyStrippedStateEvent>>>>>,
|
||||
stripped_members: Arc<DashMap<Box<RoomId>, DashMap<Box<UserId>, StrippedMemberEvent>>>,
|
||||
presence: Arc<DashMap<Box<UserId>, Raw<PresenceEvent>>>,
|
||||
room_user_receipts:
|
||||
Arc<DashMap<Box<RoomId>, DashMap<String, DashMap<Box<UserId>, (Box<EventId>, Receipt)>>>>,
|
||||
room_event_receipts: Arc<
|
||||
DashMap<Box<RoomId>, DashMap<String, DashMap<Box<EventId>, DashMap<Box<UserId>, Receipt>>>>,
|
||||
>,
|
||||
media: Arc<Mutex<LruCache<String, Vec<u8>>>>,
|
||||
custom: Arc<DashMap<Vec<u8>, Vec<u8>>>,
|
||||
}
|
||||
@@ -323,21 +322,21 @@ impl MemoryStore {
|
||||
Ok(self.members.get(room_id).and_then(|m| m.get(state_key).map(|m| m.clone())))
|
||||
}
|
||||
|
||||
fn get_user_ids(&self, room_id: &RoomId) -> Vec<UserId> {
|
||||
fn get_user_ids(&self, room_id: &RoomId) -> Vec<Box<UserId>> {
|
||||
self.members
|
||||
.get(room_id)
|
||||
.map(|u| u.iter().map(|u| u.key().clone()).collect())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn get_invited_user_ids(&self, room_id: &RoomId) -> Vec<UserId> {
|
||||
fn get_invited_user_ids(&self, room_id: &RoomId) -> Vec<Box<UserId>> {
|
||||
self.invited_user_ids
|
||||
.get(room_id)
|
||||
.map(|u| u.iter().map(|u| u.clone()).collect())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn get_joined_user_ids(&self, room_id: &RoomId) -> Vec<UserId> {
|
||||
fn get_joined_user_ids(&self, room_id: &RoomId) -> Vec<Box<UserId>> {
|
||||
self.joined_user_ids
|
||||
.get(room_id)
|
||||
.map(|u| u.iter().map(|u| u.clone()).collect())
|
||||
@@ -375,7 +374,7 @@ impl MemoryStore {
|
||||
room_id: &RoomId,
|
||||
receipt_type: ReceiptType,
|
||||
user_id: &UserId,
|
||||
) -> Result<Option<(EventId, Receipt)>> {
|
||||
) -> Result<Option<(Box<EventId>, Receipt)>> {
|
||||
Ok(self.room_user_receipts.get(room_id).and_then(|m| {
|
||||
m.get(receipt_type.as_ref()).and_then(|m| m.get(user_id).map(|r| r.clone()))
|
||||
}))
|
||||
@@ -386,7 +385,7 @@ impl MemoryStore {
|
||||
room_id: &RoomId,
|
||||
receipt_type: ReceiptType,
|
||||
event_id: &EventId,
|
||||
) -> Result<Vec<(UserId, Receipt)>> {
|
||||
) -> Result<Vec<(Box<UserId>, Receipt)>> {
|
||||
Ok(self
|
||||
.room_event_receipts
|
||||
.get(room_id)
|
||||
@@ -497,15 +496,15 @@ impl StateStore for MemoryStore {
|
||||
self.get_member_event(room_id, state_key).await
|
||||
}
|
||||
|
||||
async fn get_user_ids(&self, room_id: &RoomId) -> Result<Vec<UserId>> {
|
||||
async fn get_user_ids(&self, room_id: &RoomId) -> Result<Vec<Box<UserId>>> {
|
||||
Ok(self.get_user_ids(room_id))
|
||||
}
|
||||
|
||||
async fn get_invited_user_ids(&self, room_id: &RoomId) -> Result<Vec<UserId>> {
|
||||
async fn get_invited_user_ids(&self, room_id: &RoomId) -> Result<Vec<Box<UserId>>> {
|
||||
Ok(self.get_invited_user_ids(room_id))
|
||||
}
|
||||
|
||||
async fn get_joined_user_ids(&self, room_id: &RoomId) -> Result<Vec<UserId>> {
|
||||
async fn get_joined_user_ids(&self, room_id: &RoomId) -> Result<Vec<Box<UserId>>> {
|
||||
Ok(self.get_joined_user_ids(room_id))
|
||||
}
|
||||
|
||||
@@ -521,7 +520,7 @@ impl StateStore for MemoryStore {
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
display_name: &str,
|
||||
) -> Result<BTreeSet<UserId>> {
|
||||
) -> Result<BTreeSet<Box<UserId>>> {
|
||||
Ok(self
|
||||
.display_names
|
||||
.get(room_id)
|
||||
@@ -549,7 +548,7 @@ impl StateStore for MemoryStore {
|
||||
room_id: &RoomId,
|
||||
receipt_type: ReceiptType,
|
||||
user_id: &UserId,
|
||||
) -> Result<Option<(EventId, Receipt)>> {
|
||||
) -> Result<Option<(Box<EventId>, Receipt)>> {
|
||||
self.get_user_room_receipt_event(room_id, receipt_type, user_id).await
|
||||
}
|
||||
|
||||
@@ -558,7 +557,7 @@ impl StateStore for MemoryStore {
|
||||
room_id: &RoomId,
|
||||
receipt_type: ReceiptType,
|
||||
event_id: &EventId,
|
||||
) -> Result<Vec<(UserId, Receipt)>> {
|
||||
) -> Result<Vec<(Box<UserId>, Receipt)>> {
|
||||
self.get_event_room_receipt_events(room_id, receipt_type, event_id).await
|
||||
}
|
||||
|
||||
@@ -599,7 +598,7 @@ mod test {
|
||||
use super::{MemoryStore, StateChanges};
|
||||
use crate::media::{MediaFormat, MediaRequest, MediaThumbnailSize, MediaType};
|
||||
|
||||
fn user_id() -> UserId {
|
||||
fn user_id() -> &'static UserId {
|
||||
user_id!("@example:localhost")
|
||||
}
|
||||
|
||||
@@ -609,13 +608,13 @@ mod test {
|
||||
|
||||
let room_id = room_id!("!test:localhost");
|
||||
|
||||
let first_event_id = event_id!("$1435641916114394fHBLK:matrix.org");
|
||||
let second_event_id = event_id!("$fHBLK1435641916114394:matrix.org");
|
||||
let first_event_id = event_id!("$1435641916114394fHBLK:matrix.org").to_owned();
|
||||
let second_event_id = event_id!("$fHBLK1435641916114394:matrix.org").to_owned();
|
||||
|
||||
let first_receipt_event = serde_json::from_value(json!({
|
||||
first_event_id.clone(): {
|
||||
"m.read": {
|
||||
user_id(): {
|
||||
user_id().to_owned(): {
|
||||
"ts": 1436451550453u64
|
||||
}
|
||||
}
|
||||
@@ -626,7 +625,7 @@ mod test {
|
||||
let second_receipt_event = serde_json::from_value(json!({
|
||||
second_event_id.clone(): {
|
||||
"m.read": {
|
||||
user_id(): {
|
||||
user_id().to_owned(): {
|
||||
"ts": 1436451551453u64
|
||||
}
|
||||
}
|
||||
@@ -635,61 +634,61 @@ mod test {
|
||||
.unwrap();
|
||||
|
||||
assert!(store
|
||||
.get_user_room_receipt_event(&room_id, ReceiptType::Read, &user_id())
|
||||
.get_user_room_receipt_event(room_id, ReceiptType::Read, user_id())
|
||||
.await
|
||||
.unwrap()
|
||||
.is_none());
|
||||
assert!(store
|
||||
.get_event_room_receipt_events(&room_id, ReceiptType::Read, &first_event_id)
|
||||
.get_event_room_receipt_events(room_id, ReceiptType::Read, &first_event_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.is_empty());
|
||||
assert!(store
|
||||
.get_event_room_receipt_events(&room_id, ReceiptType::Read, &second_event_id)
|
||||
.get_event_room_receipt_events(room_id, ReceiptType::Read, &second_event_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.is_empty());
|
||||
|
||||
let mut changes = StateChanges::default();
|
||||
changes.add_receipts(&room_id, first_receipt_event);
|
||||
changes.add_receipts(room_id, first_receipt_event);
|
||||
|
||||
store.save_changes(&changes).await.unwrap();
|
||||
assert!(store
|
||||
.get_user_room_receipt_event(&room_id, ReceiptType::Read, &user_id())
|
||||
.get_user_room_receipt_event(room_id, ReceiptType::Read, user_id())
|
||||
.await
|
||||
.unwrap()
|
||||
.is_some(),);
|
||||
assert_eq!(
|
||||
store
|
||||
.get_event_room_receipt_events(&room_id, ReceiptType::Read, &first_event_id)
|
||||
.get_event_room_receipt_events(room_id, ReceiptType::Read, &first_event_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.len(),
|
||||
1
|
||||
);
|
||||
assert!(store
|
||||
.get_event_room_receipt_events(&room_id, ReceiptType::Read, &second_event_id)
|
||||
.get_event_room_receipt_events(room_id, ReceiptType::Read, &second_event_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.is_empty());
|
||||
|
||||
let mut changes = StateChanges::default();
|
||||
changes.add_receipts(&room_id, second_receipt_event);
|
||||
changes.add_receipts(room_id, second_receipt_event);
|
||||
|
||||
store.save_changes(&changes).await.unwrap();
|
||||
assert!(store
|
||||
.get_user_room_receipt_event(&room_id, ReceiptType::Read, &user_id())
|
||||
.get_user_room_receipt_event(room_id, ReceiptType::Read, user_id())
|
||||
.await
|
||||
.unwrap()
|
||||
.is_some());
|
||||
assert!(store
|
||||
.get_event_room_receipt_events(&room_id, ReceiptType::Read, &first_event_id)
|
||||
.get_event_room_receipt_events(room_id, ReceiptType::Read, &first_event_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.is_empty());
|
||||
assert_eq!(
|
||||
store
|
||||
.get_event_room_receipt_events(&room_id, ReceiptType::Read, &second_event_id)
|
||||
.get_event_room_receipt_events(room_id, ReceiptType::Read, &second_event_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.len(),
|
||||
@@ -705,10 +704,10 @@ mod test {
|
||||
let content: Vec<u8> = "somebinarydata".into();
|
||||
|
||||
let request_file =
|
||||
MediaRequest { media_type: MediaType::Uri(uri.clone()), format: MediaFormat::File };
|
||||
MediaRequest { media_type: MediaType::Uri(uri.to_owned()), format: MediaFormat::File };
|
||||
|
||||
let request_thumbnail = MediaRequest {
|
||||
media_type: MediaType::Uri(uri.clone()),
|
||||
media_type: MediaType::Uri(uri.to_owned()),
|
||||
format: MediaFormat::Thumbnail(MediaThumbnailSize {
|
||||
method: Method::Crop,
|
||||
width: uint!(100),
|
||||
@@ -731,7 +730,7 @@ mod test {
|
||||
store.add_media_content(&request_thumbnail, content.clone()).await.unwrap();
|
||||
assert!(store.get_media_content(&request_thumbnail).await.unwrap().is_some());
|
||||
|
||||
store.remove_media_content_for_uri(&uri).await.unwrap();
|
||||
store.remove_media_content_for_uri(uri).await.unwrap();
|
||||
assert!(store.get_media_content(&request_file).await.unwrap().is_none());
|
||||
assert!(store.get_media_content(&request_thumbnail).await.unwrap().is_none());
|
||||
}
|
||||
|
||||
@@ -177,15 +177,15 @@ pub trait StateStore: AsyncTraitDeps {
|
||||
) -> Result<Option<MemberEvent>>;
|
||||
|
||||
/// Get all the user ids of members for a given room.
|
||||
async fn get_user_ids(&self, room_id: &RoomId) -> Result<Vec<UserId>>;
|
||||
async fn get_user_ids(&self, room_id: &RoomId) -> Result<Vec<Box<UserId>>>;
|
||||
|
||||
/// Get all the user ids of members that are in the invited state for a
|
||||
/// given room.
|
||||
async fn get_invited_user_ids(&self, room_id: &RoomId) -> Result<Vec<UserId>>;
|
||||
async fn get_invited_user_ids(&self, room_id: &RoomId) -> Result<Vec<Box<UserId>>>;
|
||||
|
||||
/// Get all the user ids of members that are in the joined state for a
|
||||
/// given room.
|
||||
async fn get_joined_user_ids(&self, room_id: &RoomId) -> Result<Vec<UserId>>;
|
||||
async fn get_joined_user_ids(&self, room_id: &RoomId) -> Result<Vec<Box<UserId>>>;
|
||||
|
||||
/// Get all the pure `RoomInfo`s the store knows about.
|
||||
async fn get_room_infos(&self) -> Result<Vec<RoomInfo>>;
|
||||
@@ -205,7 +205,7 @@ pub trait StateStore: AsyncTraitDeps {
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
display_name: &str,
|
||||
) -> Result<BTreeSet<UserId>>;
|
||||
) -> Result<BTreeSet<Box<UserId>>>;
|
||||
|
||||
/// Get an event out of the account data store.
|
||||
///
|
||||
@@ -247,7 +247,7 @@ pub trait StateStore: AsyncTraitDeps {
|
||||
room_id: &RoomId,
|
||||
receipt_type: ReceiptType,
|
||||
user_id: &UserId,
|
||||
) -> Result<Option<(EventId, Receipt)>>;
|
||||
) -> Result<Option<(Box<EventId>, Receipt)>>;
|
||||
|
||||
/// Get events out of the event room receipt store.
|
||||
///
|
||||
@@ -265,7 +265,7 @@ pub trait StateStore: AsyncTraitDeps {
|
||||
room_id: &RoomId,
|
||||
receipt_type: ReceiptType,
|
||||
event_id: &EventId,
|
||||
) -> Result<Vec<(UserId, Receipt)>>;
|
||||
) -> Result<Vec<(Box<UserId>, Receipt)>>;
|
||||
|
||||
/// Get arbitrary data from the custom store
|
||||
///
|
||||
@@ -324,8 +324,8 @@ pub struct Store {
|
||||
inner: Arc<dyn StateStore>,
|
||||
pub(crate) session: Arc<RwLock<Option<Session>>>,
|
||||
pub(crate) sync_token: Arc<RwLock<Option<String>>>,
|
||||
rooms: Arc<DashMap<RoomId, Room>>,
|
||||
stripped_rooms: Arc<DashMap<RoomId, Room>>,
|
||||
rooms: Arc<DashMap<Box<RoomId>, Room>>,
|
||||
stripped_rooms: Arc<DashMap<Box<RoomId>, Room>>,
|
||||
}
|
||||
|
||||
impl Store {
|
||||
@@ -417,7 +417,7 @@ impl Store {
|
||||
let user_id = &session.as_ref().expect("Creating room while not being logged in").user_id;
|
||||
|
||||
self.stripped_rooms
|
||||
.entry(room_id.clone())
|
||||
.entry(room_id.to_owned())
|
||||
.or_insert_with(|| Room::new(user_id, self.inner.clone(), room_id, RoomType::Invited))
|
||||
.clone()
|
||||
}
|
||||
@@ -427,7 +427,7 @@ impl Store {
|
||||
let user_id = &session.as_ref().expect("Creating room while not being logged in").user_id;
|
||||
|
||||
self.rooms
|
||||
.entry(room_id.clone())
|
||||
.entry(room_id.to_owned())
|
||||
.or_insert_with(|| Room::new(user_id, self.inner.clone(), room_id, room_type))
|
||||
.clone()
|
||||
}
|
||||
@@ -452,38 +452,40 @@ pub struct StateChanges {
|
||||
/// A mapping of event type string to `AnyBasicEvent`.
|
||||
pub account_data: BTreeMap<String, Raw<AnyGlobalAccountDataEvent>>,
|
||||
/// A mapping of `UserId` to `PresenceEvent`.
|
||||
pub presence: BTreeMap<UserId, Raw<PresenceEvent>>,
|
||||
pub presence: BTreeMap<Box<UserId>, Raw<PresenceEvent>>,
|
||||
|
||||
/// A mapping of `RoomId` to a map of users and their `MemberEvent`.
|
||||
pub members: BTreeMap<RoomId, BTreeMap<UserId, MemberEvent>>,
|
||||
pub members: BTreeMap<Box<RoomId>, BTreeMap<Box<UserId>, MemberEvent>>,
|
||||
/// A mapping of `RoomId` to a map of users and their
|
||||
/// `RoomMemberEventContent`.
|
||||
pub profiles: BTreeMap<RoomId, BTreeMap<UserId, RoomMemberEventContent>>,
|
||||
pub profiles: BTreeMap<Box<RoomId>, BTreeMap<Box<UserId>, RoomMemberEventContent>>,
|
||||
|
||||
/// A mapping of `RoomId` to a map of event type string to a state key and
|
||||
/// `AnySyncStateEvent`.
|
||||
pub state: BTreeMap<RoomId, BTreeMap<String, BTreeMap<String, Raw<AnySyncStateEvent>>>>,
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub state: BTreeMap<Box<RoomId>, BTreeMap<String, BTreeMap<String, Raw<AnySyncStateEvent>>>>,
|
||||
/// A mapping of `RoomId` to a map of event type string to `AnyBasicEvent`.
|
||||
pub room_account_data: BTreeMap<RoomId, BTreeMap<String, Raw<AnyRoomAccountDataEvent>>>,
|
||||
pub room_account_data: BTreeMap<Box<RoomId>, BTreeMap<String, Raw<AnyRoomAccountDataEvent>>>,
|
||||
/// A map of `RoomId` to `RoomInfo`.
|
||||
pub room_infos: BTreeMap<RoomId, RoomInfo>,
|
||||
pub room_infos: BTreeMap<Box<RoomId>, RoomInfo>,
|
||||
/// A map of `RoomId` to `ReceiptEventContent`.
|
||||
pub receipts: BTreeMap<RoomId, ReceiptEventContent>,
|
||||
pub receipts: BTreeMap<Box<RoomId>, ReceiptEventContent>,
|
||||
|
||||
/// A mapping of `RoomId` to a map of event type to a map of state key to
|
||||
/// `AnyStrippedStateEvent`.
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub stripped_state:
|
||||
BTreeMap<RoomId, BTreeMap<String, BTreeMap<String, Raw<AnyStrippedStateEvent>>>>,
|
||||
BTreeMap<Box<RoomId>, BTreeMap<String, BTreeMap<String, Raw<AnyStrippedStateEvent>>>>,
|
||||
/// A mapping of `RoomId` to a map of users and their `StrippedMemberEvent`.
|
||||
pub stripped_members: BTreeMap<RoomId, BTreeMap<UserId, StrippedMemberEvent>>,
|
||||
pub stripped_members: BTreeMap<Box<RoomId>, BTreeMap<Box<UserId>, StrippedMemberEvent>>,
|
||||
/// A map of `RoomId` to `RoomInfo`.
|
||||
pub invited_room_info: BTreeMap<RoomId, RoomInfo>,
|
||||
pub invited_room_info: BTreeMap<Box<RoomId>, RoomInfo>,
|
||||
|
||||
/// A map from room id to a map of a display name and a set of user ids that
|
||||
/// share that display name in the given room.
|
||||
pub ambiguity_maps: BTreeMap<RoomId, BTreeMap<String, BTreeSet<UserId>>>,
|
||||
pub ambiguity_maps: BTreeMap<Box<RoomId>, BTreeMap<String, BTreeSet<Box<UserId>>>>,
|
||||
/// A map of `RoomId` to a vector of `Notification`s
|
||||
pub notifications: BTreeMap<RoomId, Vec<Notification>>,
|
||||
pub notifications: BTreeMap<Box<RoomId>, Vec<Notification>>,
|
||||
}
|
||||
|
||||
impl StateChanges {
|
||||
|
||||
@@ -456,7 +456,7 @@ impl SledStore {
|
||||
|
||||
for (room_id, room_info) in &changes.room_infos {
|
||||
rooms.insert(
|
||||
room_id.encode(),
|
||||
(&**room_id).encode(),
|
||||
self.serialize_event(room_info)
|
||||
.map_err(ConflictableTransactionError::Abort)?,
|
||||
)?;
|
||||
@@ -464,7 +464,7 @@ impl SledStore {
|
||||
|
||||
for (sender, event) in &changes.presence {
|
||||
presence.insert(
|
||||
sender.encode(),
|
||||
(&**sender).encode(),
|
||||
self.serialize_event(&event)
|
||||
.map_err(ConflictableTransactionError::Abort)?,
|
||||
)?;
|
||||
@@ -472,7 +472,7 @@ impl SledStore {
|
||||
|
||||
for (room_id, info) in &changes.invited_room_info {
|
||||
striped_rooms.insert(
|
||||
room_id.encode(),
|
||||
(&**room_id).encode(),
|
||||
self.serialize_event(&info)
|
||||
.map_err(ConflictableTransactionError::Abort)?,
|
||||
)?;
|
||||
@@ -522,7 +522,7 @@ impl SledStore {
|
||||
.map_err(ConflictableTransactionError::Abort)?,
|
||||
)? {
|
||||
// Remove the old receipt from the room event receipts
|
||||
let (old_event, _): (EventId, Receipt) = self
|
||||
let (old_event, _): (Box<EventId>, Receipt) = self
|
||||
.deserialize_event(&old)
|
||||
.map_err(ConflictableTransactionError::Abort)?;
|
||||
room_event_receipts.remove(
|
||||
@@ -635,8 +635,8 @@ impl SledStore {
|
||||
pub async fn get_user_ids_stream(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> Result<impl Stream<Item = Result<UserId>>> {
|
||||
let decode = |key: &[u8]| -> Result<UserId> {
|
||||
) -> Result<impl Stream<Item = Result<Box<UserId>>>> {
|
||||
let decode = |key: &[u8]| -> Result<Box<UserId>> {
|
||||
let mut iter = key.split(|c| c == &ENCODE_SEPARATOR);
|
||||
// Our key is a the room id separated from the user id by a null
|
||||
// byte, discard the first value of the split.
|
||||
@@ -644,7 +644,7 @@ impl SledStore {
|
||||
|
||||
let user_id = iter.next().expect("User ids weren't properly encoded");
|
||||
|
||||
Ok(UserId::try_from(String::from_utf8_lossy(user_id).to_string())?)
|
||||
Ok(Box::<UserId>::try_from(String::from_utf8_lossy(user_id).to_string())?)
|
||||
};
|
||||
|
||||
let members = self.members.clone();
|
||||
@@ -658,12 +658,12 @@ impl SledStore {
|
||||
pub async fn get_invited_user_ids(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> Result<impl Stream<Item = Result<UserId>>> {
|
||||
) -> Result<impl Stream<Item = Result<Box<UserId>>>> {
|
||||
let db = self.clone();
|
||||
let key = room_id.encode();
|
||||
spawn_blocking(move || {
|
||||
stream::iter(db.invited_user_ids.scan_prefix(key).map(|u| {
|
||||
UserId::try_from(String::from_utf8_lossy(&u?.1).to_string())
|
||||
Box::<UserId>::try_from(String::from_utf8_lossy(&u?.1).to_string())
|
||||
.map_err(StoreError::Identifier)
|
||||
}))
|
||||
})
|
||||
@@ -674,12 +674,12 @@ impl SledStore {
|
||||
pub async fn get_joined_user_ids(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> Result<impl Stream<Item = Result<UserId>>> {
|
||||
) -> Result<impl Stream<Item = Result<Box<UserId>>>> {
|
||||
let db = self.clone();
|
||||
let key = room_id.encode();
|
||||
spawn_blocking(move || {
|
||||
stream::iter(db.joined_user_ids.scan_prefix(key).map(|u| {
|
||||
UserId::try_from(String::from_utf8_lossy(&u?.1).to_string())
|
||||
Box::<UserId>::try_from(String::from_utf8_lossy(&u?.1).to_string())
|
||||
.map_err(StoreError::Identifier)
|
||||
}))
|
||||
})
|
||||
@@ -715,7 +715,7 @@ impl SledStore {
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
display_name: &str,
|
||||
) -> Result<BTreeSet<UserId>> {
|
||||
) -> Result<BTreeSet<Box<UserId>>> {
|
||||
let db = self.clone();
|
||||
let key = (room_id.as_str(), display_name).encode();
|
||||
spawn_blocking(move || {
|
||||
@@ -759,7 +759,7 @@ impl SledStore {
|
||||
room_id: &RoomId,
|
||||
receipt_type: ReceiptType,
|
||||
user_id: &UserId,
|
||||
) -> Result<Option<(EventId, Receipt)>> {
|
||||
) -> Result<Option<(Box<EventId>, Receipt)>> {
|
||||
let db = self.clone();
|
||||
let key = (room_id.as_str(), receipt_type.as_ref(), user_id.as_str()).encode();
|
||||
spawn_blocking(move || {
|
||||
@@ -773,7 +773,7 @@ impl SledStore {
|
||||
room_id: &RoomId,
|
||||
receipt_type: ReceiptType,
|
||||
event_id: &EventId,
|
||||
) -> Result<Vec<(UserId, Receipt)>> {
|
||||
) -> Result<Vec<(Box<UserId>, Receipt)>> {
|
||||
let db = self.clone();
|
||||
let key = (room_id.as_str(), receipt_type.as_ref(), event_id.as_str()).encode();
|
||||
spawn_blocking(move || {
|
||||
@@ -903,15 +903,15 @@ impl StateStore for SledStore {
|
||||
self.get_member_event(room_id, state_key).await
|
||||
}
|
||||
|
||||
async fn get_user_ids(&self, room_id: &RoomId) -> Result<Vec<UserId>> {
|
||||
async fn get_user_ids(&self, room_id: &RoomId) -> Result<Vec<Box<UserId>>> {
|
||||
self.get_user_ids_stream(room_id).await?.try_collect().await
|
||||
}
|
||||
|
||||
async fn get_invited_user_ids(&self, room_id: &RoomId) -> Result<Vec<UserId>> {
|
||||
async fn get_invited_user_ids(&self, room_id: &RoomId) -> Result<Vec<Box<UserId>>> {
|
||||
self.get_invited_user_ids(room_id).await?.try_collect().await
|
||||
}
|
||||
|
||||
async fn get_joined_user_ids(&self, room_id: &RoomId) -> Result<Vec<UserId>> {
|
||||
async fn get_joined_user_ids(&self, room_id: &RoomId) -> Result<Vec<Box<UserId>>> {
|
||||
self.get_joined_user_ids(room_id).await?.try_collect().await
|
||||
}
|
||||
|
||||
@@ -927,7 +927,7 @@ impl StateStore for SledStore {
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
display_name: &str,
|
||||
) -> Result<BTreeSet<UserId>> {
|
||||
) -> Result<BTreeSet<Box<UserId>>> {
|
||||
self.get_users_with_display_name(room_id, display_name).await
|
||||
}
|
||||
|
||||
@@ -951,7 +951,7 @@ impl StateStore for SledStore {
|
||||
room_id: &RoomId,
|
||||
receipt_type: ReceiptType,
|
||||
user_id: &UserId,
|
||||
) -> Result<Option<(EventId, Receipt)>> {
|
||||
) -> Result<Option<(Box<EventId>, Receipt)>> {
|
||||
self.get_user_room_receipt_event(room_id, receipt_type, user_id).await
|
||||
}
|
||||
|
||||
@@ -960,7 +960,7 @@ impl StateStore for SledStore {
|
||||
room_id: &RoomId,
|
||||
receipt_type: ReceiptType,
|
||||
event_id: &EventId,
|
||||
) -> Result<Vec<(UserId, Receipt)>> {
|
||||
) -> Result<Vec<(Box<UserId>, Receipt)>> {
|
||||
self.get_event_room_receipt_events(room_id, receipt_type, event_id).await
|
||||
}
|
||||
|
||||
@@ -991,8 +991,6 @@ impl StateStore for SledStore {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::{
|
||||
api::client::r0::media::get_content_thumbnail::Method,
|
||||
@@ -1008,7 +1006,7 @@ mod test {
|
||||
receipt::ReceiptType,
|
||||
room_id,
|
||||
serde::Raw,
|
||||
uint, user_id, EventId, MilliSecondsSinceUnixEpoch, UserId,
|
||||
uint, user_id, MilliSecondsSinceUnixEpoch, UserId,
|
||||
};
|
||||
use serde_json::json;
|
||||
|
||||
@@ -1019,7 +1017,7 @@ mod test {
|
||||
StateStore,
|
||||
};
|
||||
|
||||
fn user_id() -> UserId {
|
||||
fn user_id() -> &'static UserId {
|
||||
user_id!("@example:localhost")
|
||||
}
|
||||
|
||||
@@ -1027,7 +1025,7 @@ mod test {
|
||||
let content = RoomPowerLevelsEventContent::default();
|
||||
|
||||
let event = json!({
|
||||
"event_id": EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||
"event_id": "$h29iv0s8:example.com",
|
||||
"content": content,
|
||||
"sender": user_id(),
|
||||
"type": "m.room.power_levels",
|
||||
@@ -1041,11 +1039,11 @@ mod test {
|
||||
|
||||
fn membership_event() -> MemberEvent {
|
||||
MemberEvent {
|
||||
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||
event_id: event_id!("$h29iv0s8:example.com").to_owned(),
|
||||
content: RoomMemberEventContent::new(MembershipState::Join),
|
||||
sender: user_id(),
|
||||
sender: user_id().to_owned(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
|
||||
state_key: user_id(),
|
||||
state_key: user_id().to_owned(),
|
||||
prev_content: None,
|
||||
unsigned: Unsigned::default(),
|
||||
}
|
||||
@@ -1057,18 +1055,18 @@ mod test {
|
||||
let room_id = room_id!("!test:localhost");
|
||||
let user_id = user_id();
|
||||
|
||||
assert!(store.get_member_event(&room_id, &user_id).await.unwrap().is_none());
|
||||
assert!(store.get_member_event(room_id, user_id).await.unwrap().is_none());
|
||||
let mut changes = StateChanges::default();
|
||||
changes
|
||||
.members
|
||||
.entry(room_id.clone())
|
||||
.entry(room_id.to_owned())
|
||||
.or_default()
|
||||
.insert(user_id.clone(), membership_event());
|
||||
.insert(user_id.to_owned(), membership_event());
|
||||
|
||||
store.save_changes(&changes).await.unwrap();
|
||||
assert!(store.get_member_event(&room_id, &user_id).await.unwrap().is_some());
|
||||
assert!(store.get_member_event(room_id, user_id).await.unwrap().is_some());
|
||||
|
||||
let members = store.get_user_ids(&room_id).await.unwrap();
|
||||
let members = store.get_user_ids(room_id).await.unwrap();
|
||||
assert!(!members.is_empty())
|
||||
}
|
||||
|
||||
@@ -1081,16 +1079,16 @@ mod test {
|
||||
let event = raw_event.deserialize().unwrap();
|
||||
|
||||
assert!(store
|
||||
.get_state_event(&room_id, EventType::RoomPowerLevels, "")
|
||||
.get_state_event(room_id, EventType::RoomPowerLevels, "")
|
||||
.await
|
||||
.unwrap()
|
||||
.is_none());
|
||||
let mut changes = StateChanges::default();
|
||||
changes.add_state_event(&room_id, event, raw_event);
|
||||
changes.add_state_event(room_id, event, raw_event);
|
||||
|
||||
store.save_changes(&changes).await.unwrap();
|
||||
assert!(store
|
||||
.get_state_event(&room_id, EventType::RoomPowerLevels, "")
|
||||
.get_state_event(room_id, EventType::RoomPowerLevels, "")
|
||||
.await
|
||||
.unwrap()
|
||||
.is_some());
|
||||
@@ -1102,13 +1100,13 @@ mod test {
|
||||
|
||||
let room_id = room_id!("!test:localhost");
|
||||
|
||||
let first_event_id = event_id!("$1435641916114394fHBLK:matrix.org");
|
||||
let second_event_id = event_id!("$fHBLK1435641916114394:matrix.org");
|
||||
let first_event_id = event_id!("$1435641916114394fHBLK:matrix.org").to_owned();
|
||||
let second_event_id = event_id!("$fHBLK1435641916114394:matrix.org").to_owned();
|
||||
|
||||
let first_receipt_event = serde_json::from_value(json!({
|
||||
first_event_id.clone(): {
|
||||
"m.read": {
|
||||
user_id(): {
|
||||
user_id().to_owned(): {
|
||||
"ts": 1436451550453u64
|
||||
}
|
||||
}
|
||||
@@ -1119,7 +1117,7 @@ mod test {
|
||||
let second_receipt_event = serde_json::from_value(json!({
|
||||
second_event_id.clone(): {
|
||||
"m.read": {
|
||||
user_id(): {
|
||||
user_id().to_owned(): {
|
||||
"ts": 1436451551453u64
|
||||
}
|
||||
}
|
||||
@@ -1128,61 +1126,61 @@ mod test {
|
||||
.unwrap();
|
||||
|
||||
assert!(store
|
||||
.get_user_room_receipt_event(&room_id, ReceiptType::Read, &user_id())
|
||||
.get_user_room_receipt_event(room_id, ReceiptType::Read, user_id())
|
||||
.await
|
||||
.unwrap()
|
||||
.is_none());
|
||||
assert!(store
|
||||
.get_event_room_receipt_events(&room_id, ReceiptType::Read, &first_event_id)
|
||||
.get_event_room_receipt_events(room_id, ReceiptType::Read, &first_event_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.is_empty());
|
||||
assert!(store
|
||||
.get_event_room_receipt_events(&room_id, ReceiptType::Read, &second_event_id)
|
||||
.get_event_room_receipt_events(room_id, ReceiptType::Read, &second_event_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.is_empty());
|
||||
|
||||
let mut changes = StateChanges::default();
|
||||
changes.add_receipts(&room_id, first_receipt_event);
|
||||
changes.add_receipts(room_id, first_receipt_event);
|
||||
|
||||
store.save_changes(&changes).await.unwrap();
|
||||
assert!(store
|
||||
.get_user_room_receipt_event(&room_id, ReceiptType::Read, &user_id())
|
||||
.get_user_room_receipt_event(room_id, ReceiptType::Read, user_id())
|
||||
.await
|
||||
.unwrap()
|
||||
.is_some(),);
|
||||
assert_eq!(
|
||||
store
|
||||
.get_event_room_receipt_events(&room_id, ReceiptType::Read, &first_event_id)
|
||||
.get_event_room_receipt_events(room_id, ReceiptType::Read, &first_event_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.len(),
|
||||
1
|
||||
);
|
||||
assert!(store
|
||||
.get_event_room_receipt_events(&room_id, ReceiptType::Read, &second_event_id)
|
||||
.get_event_room_receipt_events(room_id, ReceiptType::Read, &second_event_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.is_empty());
|
||||
|
||||
let mut changes = StateChanges::default();
|
||||
changes.add_receipts(&room_id, second_receipt_event);
|
||||
changes.add_receipts(room_id, second_receipt_event);
|
||||
|
||||
store.save_changes(&changes).await.unwrap();
|
||||
assert!(store
|
||||
.get_user_room_receipt_event(&room_id, ReceiptType::Read, &user_id())
|
||||
.get_user_room_receipt_event(room_id, ReceiptType::Read, user_id())
|
||||
.await
|
||||
.unwrap()
|
||||
.is_some());
|
||||
assert!(store
|
||||
.get_event_room_receipt_events(&room_id, ReceiptType::Read, &first_event_id)
|
||||
.get_event_room_receipt_events(room_id, ReceiptType::Read, &first_event_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.is_empty());
|
||||
assert_eq!(
|
||||
store
|
||||
.get_event_room_receipt_events(&room_id, ReceiptType::Read, &second_event_id)
|
||||
.get_event_room_receipt_events(room_id, ReceiptType::Read, &second_event_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.len(),
|
||||
@@ -1198,10 +1196,10 @@ mod test {
|
||||
let content: Vec<u8> = "somebinarydata".into();
|
||||
|
||||
let request_file =
|
||||
MediaRequest { media_type: MediaType::Uri(uri.clone()), format: MediaFormat::File };
|
||||
MediaRequest { media_type: MediaType::Uri(uri.to_owned()), format: MediaFormat::File };
|
||||
|
||||
let request_thumbnail = MediaRequest {
|
||||
media_type: MediaType::Uri(uri.clone()),
|
||||
media_type: MediaType::Uri(uri.to_owned()),
|
||||
format: MediaFormat::Thumbnail(MediaThumbnailSize {
|
||||
method: Method::Crop,
|
||||
width: uint!(100),
|
||||
@@ -1224,7 +1222,7 @@ mod test {
|
||||
store.add_media_content(&request_thumbnail, content.clone()).await.unwrap();
|
||||
assert!(store.get_media_content(&request_thumbnail).await.unwrap().is_some());
|
||||
|
||||
store.remove_media_content_for_uri(&uri).await.unwrap();
|
||||
store.remove_media_content_for_uri(uri).await.unwrap();
|
||||
assert!(store.get_media_content(&request_file).await.unwrap().is_none());
|
||||
assert!(store.get_media_content(&request_thumbnail).await.unwrap().is_none());
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ version = "0.4.1"
|
||||
|
||||
[dependencies]
|
||||
async-trait = "0.1.50"
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "ac6ecc3e5", features = ["client-api-c"] }
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "6c4892664", features = ["client-api-c"] }
|
||||
serde = "1.0.126"
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
|
||||
@@ -15,7 +15,7 @@ use ruma::{
|
||||
AnyRoomEvent, AnySyncRoomEvent, Unsigned,
|
||||
},
|
||||
serde::Raw,
|
||||
DeviceIdBox, DeviceKeyAlgorithm, EventId, MilliSecondsSinceUnixEpoch, RoomId, UserId,
|
||||
DeviceId, DeviceKeyAlgorithm, EventId, MilliSecondsSinceUnixEpoch, RoomId, UserId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -27,9 +27,9 @@ pub struct AmbiguityChange {
|
||||
/// event itself ambiguous because of the event.
|
||||
pub member_ambiguous: bool,
|
||||
/// Has another user been disambiguated because of this event.
|
||||
pub disambiguated_member: Option<UserId>,
|
||||
pub disambiguated_member: Option<Box<UserId>>,
|
||||
/// Has another user become ambiguous because of this event.
|
||||
pub ambiguated_member: Option<UserId>,
|
||||
pub ambiguated_member: Option<Box<UserId>>,
|
||||
}
|
||||
|
||||
/// Collection of ambiguioty changes that room member events trigger.
|
||||
@@ -37,7 +37,7 @@ pub struct AmbiguityChange {
|
||||
pub struct AmbiguityChanges {
|
||||
/// A map from room id to a map of an event id to the `AmbiguityChange` that
|
||||
/// the event with the given id caused.
|
||||
pub changes: BTreeMap<RoomId, BTreeMap<EventId, AmbiguityChange>>,
|
||||
pub changes: BTreeMap<Box<RoomId>, BTreeMap<Box<EventId>, AmbiguityChange>>,
|
||||
}
|
||||
|
||||
/// The verification state of the device that sent an event to us.
|
||||
@@ -74,10 +74,10 @@ pub enum AlgorithmInfo {
|
||||
pub struct EncryptionInfo {
|
||||
/// The user ID of the event sender, note this is untrusted data unless the
|
||||
/// `verification_state` is as well trusted.
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
/// The device ID of the device that sent us the event, note this is
|
||||
/// untrusted data unless `verification_state` is as well trusted.
|
||||
pub sender_device: DeviceIdBox,
|
||||
pub sender_device: Box<DeviceId>,
|
||||
/// Information about the algorithm that was used to encrypt the event.
|
||||
pub algorithm_info: AlgorithmInfo,
|
||||
/// The verification state of the device that sent us the event, note this
|
||||
@@ -126,7 +126,7 @@ pub struct SyncResponse {
|
||||
/// Collection of ambiguity changes that room member events trigger.
|
||||
pub ambiguity_changes: AmbiguityChanges,
|
||||
/// New notifications per room.
|
||||
pub notifications: BTreeMap<RoomId, Vec<Notification>>,
|
||||
pub notifications: BTreeMap<Box<RoomId>, Vec<Notification>>,
|
||||
}
|
||||
|
||||
impl SyncResponse {
|
||||
@@ -147,11 +147,11 @@ pub struct RoomEvent {
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
pub struct Rooms {
|
||||
/// The rooms that the user has left or been banned from.
|
||||
pub leave: BTreeMap<RoomId, LeftRoom>,
|
||||
pub leave: BTreeMap<Box<RoomId>, LeftRoom>,
|
||||
/// The rooms that the user has joined.
|
||||
pub join: BTreeMap<RoomId, JoinedRoom>,
|
||||
pub join: BTreeMap<Box<RoomId>, JoinedRoom>,
|
||||
/// The rooms that the user has been invited to.
|
||||
pub invite: BTreeMap<RoomId, InvitedRoom>,
|
||||
pub invite: BTreeMap<Box<RoomId>, InvitedRoom>,
|
||||
}
|
||||
|
||||
/// Updates to joined rooms.
|
||||
@@ -249,11 +249,11 @@ impl Timeline {
|
||||
#[serde(try_from = "SyncRoomMemberEvent", into = "SyncRoomMemberEvent")]
|
||||
pub struct MemberEvent {
|
||||
pub content: RoomMemberEventContent,
|
||||
pub event_id: EventId,
|
||||
pub event_id: Box<EventId>,
|
||||
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||
pub prev_content: Option<RoomMemberEventContent>,
|
||||
pub sender: UserId,
|
||||
pub state_key: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
pub state_key: Box<UserId>,
|
||||
pub unsigned: Unsigned,
|
||||
}
|
||||
|
||||
@@ -267,7 +267,7 @@ impl TryFrom<SyncRoomMemberEvent> for MemberEvent {
|
||||
origin_server_ts: event.origin_server_ts,
|
||||
prev_content: event.prev_content,
|
||||
sender: event.sender,
|
||||
state_key: UserId::try_from(event.state_key)?,
|
||||
state_key: event.state_key.try_into()?,
|
||||
unsigned: event.unsigned,
|
||||
})
|
||||
}
|
||||
@@ -283,7 +283,7 @@ impl TryFrom<RoomMemberEvent> for MemberEvent {
|
||||
origin_server_ts: event.origin_server_ts,
|
||||
prev_content: event.prev_content,
|
||||
sender: event.sender,
|
||||
state_key: UserId::try_from(event.state_key)?,
|
||||
state_key: event.state_key.try_into()?,
|
||||
unsigned: event.unsigned,
|
||||
})
|
||||
}
|
||||
@@ -307,8 +307,8 @@ impl From<MemberEvent> for SyncRoomMemberEvent {
|
||||
#[serde(try_from = "StrippedRoomMemberEvent", into = "StrippedRoomMemberEvent")]
|
||||
pub struct StrippedMemberEvent {
|
||||
pub content: RoomMemberEventContent,
|
||||
pub sender: UserId,
|
||||
pub state_key: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
pub state_key: Box<UserId>,
|
||||
}
|
||||
|
||||
impl TryFrom<StrippedRoomMemberEvent> for StrippedMemberEvent {
|
||||
@@ -318,7 +318,7 @@ impl TryFrom<StrippedRoomMemberEvent> for StrippedMemberEvent {
|
||||
Ok(StrippedMemberEvent {
|
||||
content: event.content,
|
||||
sender: event.sender,
|
||||
state_key: UserId::try_from(event.state_key)?,
|
||||
state_key: event.state_key.try_into()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ matrix-sdk-common = { version = "0.4.0", path = "../matrix-sdk-common" }
|
||||
olm-rs = { version = "2.1", features = ["serde"] }
|
||||
pbkdf2 = { version = "0.9.0", default-features = false }
|
||||
rand = "0.8.4"
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "ac6ecc3e5", features = [
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "6c4892664", features = [
|
||||
"client-api-c",
|
||||
"unstable-pre-spec",
|
||||
] }
|
||||
|
||||
@@ -24,8 +24,8 @@ use ruma::{UserId, api::client::r0::sync::sync_events::{ToDevice, DeviceLists}};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), OlmError> {
|
||||
let alice = UserId::try_from("@alice:example.org").unwrap();
|
||||
let machine = OlmMachine::new(&alice, "DEVICEID".into());
|
||||
let alice = Box::<UserId>::try_from("@alice:example.org").unwrap();
|
||||
let machine = OlmMachine::new(&alice, device_id!("DEVICEID"));
|
||||
|
||||
let to_device_events = ToDevice::default();
|
||||
let changed_devices = DeviceLists::default();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::sync::Arc;
|
||||
use std::{ops::Deref, sync::Arc};
|
||||
|
||||
use criterion::*;
|
||||
use matrix_sdk_common::uuid::Uuid;
|
||||
@@ -12,17 +12,17 @@ use ruma::{
|
||||
},
|
||||
IncomingResponse,
|
||||
},
|
||||
room_id, user_id, DeviceIdBox, UserId,
|
||||
device_id, room_id, user_id, DeviceId, UserId,
|
||||
};
|
||||
use serde_json::Value;
|
||||
use tokio::runtime::Builder;
|
||||
|
||||
fn alice_id() -> UserId {
|
||||
fn alice_id() -> &'static UserId {
|
||||
user_id!("@alice:example.org")
|
||||
}
|
||||
|
||||
fn alice_device_id() -> DeviceIdBox {
|
||||
"JLAFKJWSCS".into()
|
||||
fn alice_device_id() -> &'static DeviceId {
|
||||
device_id!("JLAFKJWSCS")
|
||||
}
|
||||
|
||||
fn keys_query_response() -> get_keys::Response {
|
||||
@@ -49,7 +49,7 @@ fn huge_keys_query_response() -> get_keys::Response {
|
||||
|
||||
pub fn keys_query(c: &mut Criterion) {
|
||||
let runtime = Builder::new_multi_thread().build().expect("Can't create runtime");
|
||||
let machine = OlmMachine::new(&alice_id(), &alice_device_id());
|
||||
let machine = OlmMachine::new(alice_id(), alice_device_id());
|
||||
let response = keys_query_response();
|
||||
let uuid = Uuid::new_v4();
|
||||
|
||||
@@ -71,8 +71,8 @@ pub fn keys_query(c: &mut Criterion) {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let machine = runtime
|
||||
.block_on(OlmMachine::new_with_default_store(
|
||||
&alice_id(),
|
||||
&alice_device_id(),
|
||||
alice_id(),
|
||||
alice_device_id(),
|
||||
dir.path(),
|
||||
None,
|
||||
))
|
||||
@@ -104,7 +104,7 @@ pub fn keys_claiming(c: &mut Criterion) {
|
||||
group.bench_with_input(BenchmarkId::new("memory store", &name), &response, |b, response| {
|
||||
b.iter_batched(
|
||||
|| {
|
||||
let machine = OlmMachine::new(&alice_id(), &alice_device_id());
|
||||
let machine = OlmMachine::new(alice_id(), alice_device_id());
|
||||
runtime
|
||||
.block_on(machine.mark_request_as_sent(&uuid, &keys_query_response))
|
||||
.unwrap();
|
||||
@@ -123,8 +123,8 @@ pub fn keys_claiming(c: &mut Criterion) {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let machine = runtime
|
||||
.block_on(OlmMachine::new_with_default_store(
|
||||
&alice_id(),
|
||||
&alice_device_id(),
|
||||
alice_id(),
|
||||
alice_device_id(),
|
||||
dir.path(),
|
||||
None,
|
||||
))
|
||||
@@ -153,11 +153,11 @@ pub fn room_key_sharing(c: &mut Criterion) {
|
||||
let room_id = room_id!("!test:localhost");
|
||||
|
||||
let to_device_response = ToDeviceResponse::new();
|
||||
let users: Vec<UserId> = keys_query_response.device_keys.keys().cloned().collect();
|
||||
let users: Vec<Box<UserId>> = keys_query_response.device_keys.keys().cloned().collect();
|
||||
|
||||
let count = response.one_time_keys.values().fold(0, |acc, d| acc + d.len());
|
||||
|
||||
let machine = OlmMachine::new(&alice_id(), &alice_device_id());
|
||||
let machine = OlmMachine::new(alice_id(), alice_device_id());
|
||||
runtime.block_on(machine.mark_request_as_sent(&uuid, &keys_query_response)).unwrap();
|
||||
runtime.block_on(machine.mark_request_as_sent(&uuid, &response)).unwrap();
|
||||
|
||||
@@ -168,7 +168,11 @@ pub fn room_key_sharing(c: &mut Criterion) {
|
||||
group.bench_function(BenchmarkId::new("memory store", &name), |b| {
|
||||
b.to_async(&runtime).iter(|| async {
|
||||
let requests = machine
|
||||
.share_group_session(&room_id, users.iter(), EncryptionSettings::default())
|
||||
.share_group_session(
|
||||
room_id,
|
||||
users.iter().map(Deref::deref),
|
||||
EncryptionSettings::default(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -178,15 +182,15 @@ pub fn room_key_sharing(c: &mut Criterion) {
|
||||
machine.mark_request_as_sent(&request.txn_id, &to_device_response).await.unwrap();
|
||||
}
|
||||
|
||||
machine.invalidate_group_session(&room_id).await.unwrap();
|
||||
machine.invalidate_group_session(room_id).await.unwrap();
|
||||
})
|
||||
});
|
||||
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let machine = runtime
|
||||
.block_on(OlmMachine::new_with_default_store(
|
||||
&alice_id(),
|
||||
&alice_device_id(),
|
||||
alice_id(),
|
||||
alice_device_id(),
|
||||
dir.path(),
|
||||
None,
|
||||
))
|
||||
@@ -197,7 +201,11 @@ pub fn room_key_sharing(c: &mut Criterion) {
|
||||
group.bench_function(BenchmarkId::new("sled store", &name), |b| {
|
||||
b.to_async(&runtime).iter(|| async {
|
||||
let requests = machine
|
||||
.share_group_session(&room_id, users.iter(), EncryptionSettings::default())
|
||||
.share_group_session(
|
||||
room_id,
|
||||
users.iter().map(Deref::deref),
|
||||
EncryptionSettings::default(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -207,7 +215,7 @@ pub fn room_key_sharing(c: &mut Criterion) {
|
||||
machine.mark_request_as_sent(&request.txn_id, &to_device_response).await.unwrap();
|
||||
}
|
||||
|
||||
machine.invalidate_group_session(&room_id).await.unwrap();
|
||||
machine.invalidate_group_session(room_id).await.unwrap();
|
||||
})
|
||||
});
|
||||
|
||||
@@ -217,10 +225,10 @@ pub fn room_key_sharing(c: &mut Criterion) {
|
||||
pub fn devices_missing_sessions_collecting(c: &mut Criterion) {
|
||||
let runtime = Builder::new_multi_thread().build().expect("Can't create runtime");
|
||||
|
||||
let machine = OlmMachine::new(&alice_id(), &alice_device_id());
|
||||
let machine = OlmMachine::new(alice_id(), alice_device_id());
|
||||
let response = huge_keys_query_response();
|
||||
let uuid = Uuid::new_v4();
|
||||
let users: Vec<UserId> = response.device_keys.keys().cloned().collect();
|
||||
let users: Vec<Box<UserId>> = response.device_keys.keys().cloned().collect();
|
||||
|
||||
let count = response.device_keys.values().fold(0, |acc, d| acc + d.len());
|
||||
|
||||
@@ -233,15 +241,15 @@ pub fn devices_missing_sessions_collecting(c: &mut Criterion) {
|
||||
|
||||
group.bench_function(BenchmarkId::new("memory store", &name), |b| {
|
||||
b.to_async(&runtime).iter_with_large_drop(|| async {
|
||||
machine.get_missing_sessions(users.iter()).await.unwrap()
|
||||
machine.get_missing_sessions(users.iter().map(Deref::deref)).await.unwrap()
|
||||
})
|
||||
});
|
||||
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let machine = runtime
|
||||
.block_on(OlmMachine::new_with_default_store(
|
||||
&alice_id(),
|
||||
&alice_device_id(),
|
||||
alice_id(),
|
||||
alice_device_id(),
|
||||
dir.path(),
|
||||
None,
|
||||
))
|
||||
@@ -250,8 +258,9 @@ pub fn devices_missing_sessions_collecting(c: &mut Criterion) {
|
||||
runtime.block_on(machine.mark_request_as_sent(&uuid, &response)).unwrap();
|
||||
|
||||
group.bench_function(BenchmarkId::new("sled store", &name), |b| {
|
||||
b.to_async(&runtime)
|
||||
.iter(|| async { machine.get_missing_sessions(users.iter()).await.unwrap() })
|
||||
b.to_async(&runtime).iter(|| async {
|
||||
machine.get_missing_sessions(users.iter().map(Deref::deref)).await.unwrap()
|
||||
})
|
||||
});
|
||||
|
||||
group.finish()
|
||||
|
||||
@@ -30,7 +30,7 @@ use crate::olm::InboundGroupSession;
|
||||
#[derive(Debug)]
|
||||
struct InnerBackupKey {
|
||||
key: [u8; MegolmV1BackupKey::KEY_SIZE],
|
||||
signatures: BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>,
|
||||
signatures: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>,
|
||||
version: Mutex<Option<String>>,
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ impl MegolmV1BackupKey {
|
||||
}
|
||||
|
||||
/// Get all the signatures of this `MegolmV1BackupKey`.
|
||||
pub fn signatures(&self) -> BTreeMap<UserId, BTreeMap<DeviceKeyId, String>> {
|
||||
pub fn signatures(&self) -> BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>> {
|
||||
self.inner.signatures.to_owned()
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ pub struct BackupMachine {
|
||||
struct PendingBackup {
|
||||
request_id: Uuid,
|
||||
request: KeysBackupRequest,
|
||||
sessions: BTreeMap<RoomId, BTreeMap<String, BTreeSet<String>>>,
|
||||
sessions: BTreeMap<Box<RoomId>, BTreeMap<String, BTreeSet<String>>>,
|
||||
}
|
||||
|
||||
impl PendingBackup {
|
||||
@@ -124,7 +124,7 @@ impl BackupMachine {
|
||||
struct AuthData {
|
||||
public_key: String,
|
||||
#[serde(default)]
|
||||
signatures: BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>,
|
||||
signatures: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>,
|
||||
#[serde(flatten)]
|
||||
extra: BTreeMap<String, Value>,
|
||||
}
|
||||
@@ -348,10 +348,12 @@ impl BackupMachine {
|
||||
async fn backup_keys(
|
||||
sessions: Vec<InboundGroupSession>,
|
||||
backup_key: &MegolmV1BackupKey,
|
||||
) -> (BTreeMap<RoomId, RoomKeyBackup>, BTreeMap<RoomId, BTreeMap<String, BTreeSet<String>>>)
|
||||
{
|
||||
let mut backup: BTreeMap<RoomId, RoomKeyBackup> = BTreeMap::new();
|
||||
let mut session_record: BTreeMap<RoomId, BTreeMap<String, BTreeSet<String>>> =
|
||||
) -> (
|
||||
BTreeMap<Box<RoomId>, RoomKeyBackup>,
|
||||
BTreeMap<Box<RoomId>, BTreeMap<String, BTreeSet<String>>>,
|
||||
) {
|
||||
let mut backup: BTreeMap<Box<RoomId>, RoomKeyBackup> = BTreeMap::new();
|
||||
let mut session_record: BTreeMap<Box<RoomId>, BTreeMap<String, BTreeSet<String>>> =
|
||||
BTreeMap::new();
|
||||
|
||||
for session in sessions.into_iter() {
|
||||
@@ -361,7 +363,7 @@ impl BackupMachine {
|
||||
let session = backup_key.encrypt(session).await;
|
||||
|
||||
session_record
|
||||
.entry(room_id.clone())
|
||||
.entry(room_id.to_owned())
|
||||
.or_default()
|
||||
.entry(sender_key)
|
||||
.or_default()
|
||||
@@ -381,24 +383,24 @@ impl BackupMachine {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::{room_id, user_id, DeviceIdBox, RoomId, UserId};
|
||||
use ruma::{device_id, room_id, user_id, DeviceId, RoomId, UserId};
|
||||
|
||||
use super::RecoveryKey;
|
||||
use crate::{OlmError, OlmMachine};
|
||||
|
||||
fn alice_id() -> UserId {
|
||||
fn alice_id() -> &'static UserId {
|
||||
user_id!("@alice:example.org")
|
||||
}
|
||||
|
||||
fn alice_device_id() -> DeviceIdBox {
|
||||
"JLAFKJWSCS".into()
|
||||
fn alice_device_id() -> &'static DeviceId {
|
||||
device_id!("JLAFKJWSCS")
|
||||
}
|
||||
|
||||
fn room_id() -> RoomId {
|
||||
fn room_id() -> &'static RoomId {
|
||||
room_id!("!test:localhost")
|
||||
}
|
||||
|
||||
fn room_id2() -> RoomId {
|
||||
fn room_id2() -> &'static RoomId {
|
||||
room_id!("!test2:localhost")
|
||||
}
|
||||
|
||||
@@ -409,8 +411,8 @@ mod test {
|
||||
assert_eq!(counts.total, 0, "Initially no keys exist");
|
||||
assert_eq!(counts.backed_up, 0, "Initially no backed up keys exist");
|
||||
|
||||
machine.create_outbound_group_session_with_defaults(&room_id()).await?;
|
||||
machine.create_outbound_group_session_with_defaults(&room_id2()).await?;
|
||||
machine.create_outbound_group_session_with_defaults(room_id()).await?;
|
||||
machine.create_outbound_group_session_with_defaults(room_id2()).await?;
|
||||
|
||||
let counts = backup_machine.store.inbound_group_session_counts().await?;
|
||||
assert_eq!(counts.total, 2, "Two room keys need to exist in the store");
|
||||
@@ -455,7 +457,7 @@ mod test {
|
||||
|
||||
#[async_test]
|
||||
async fn memory_store_backups() -> Result<(), OlmError> {
|
||||
let machine = OlmMachine::new(&alice_id(), &alice_device_id());
|
||||
let machine = OlmMachine::new(alice_id(), alice_device_id());
|
||||
|
||||
backup_flow(machine).await
|
||||
}
|
||||
@@ -467,8 +469,8 @@ mod test {
|
||||
|
||||
let tmpdir = tempdir().expect("Can't create a temporary dir");
|
||||
let machine = OlmMachine::new_with_default_store(
|
||||
&alice_id(),
|
||||
&alice_device_id(),
|
||||
alice_id(),
|
||||
alice_device_id(),
|
||||
tmpdir.as_ref(),
|
||||
None,
|
||||
)
|
||||
@@ -484,8 +486,8 @@ mod test {
|
||||
|
||||
let tmpdir = tempdir().expect("Can't create a temporary dir");
|
||||
let machine = OlmMachine::new_with_default_store(
|
||||
&alice_id(),
|
||||
&alice_device_id(),
|
||||
alice_id(),
|
||||
alice_device_id(),
|
||||
tmpdir.as_ref(),
|
||||
Some("test"),
|
||||
)
|
||||
|
||||
@@ -50,12 +50,12 @@ pub enum OlmError {
|
||||
#[error(
|
||||
"decryption failed likely because an Olm session from {0} with sender key {1} was wedged"
|
||||
)]
|
||||
SessionWedged(UserId, String),
|
||||
SessionWedged(Box<UserId>, String),
|
||||
|
||||
/// An Olm message got replayed while the Olm ratchet has already moved
|
||||
/// forward.
|
||||
#[error("decryption failed because an Olm message from {0} with sender key {1} was replayed")]
|
||||
ReplayedMessage(UserId, String),
|
||||
ReplayedMessage(Box<UserId>, String),
|
||||
|
||||
/// Encryption failed because the device does not have a valid Olm session
|
||||
/// with us.
|
||||
@@ -122,7 +122,7 @@ pub enum EventError {
|
||||
"the sender of the plaintext doesn't match the sender of the encrypted \
|
||||
message, got {0}, expected {0}"
|
||||
)]
|
||||
MismatchedSender(UserId, UserId),
|
||||
MismatchedSender(Box<UserId>, Box<UserId>),
|
||||
|
||||
#[error(
|
||||
"the public that was part of the message doesn't match to the key we \
|
||||
@@ -134,7 +134,7 @@ pub enum EventError {
|
||||
"the room id of the room key doesn't match the room id of the \
|
||||
decrypted event: expected {0}, got {:1}"
|
||||
)]
|
||||
MismatchedRoom(RoomId, Option<RoomId>),
|
||||
MismatchedRoom(Box<RoomId>, Option<Box<RoomId>>),
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
@@ -193,24 +193,24 @@ pub(crate) enum SessionCreationError {
|
||||
"Failed to create a new Olm session for {0} {1}, the requested \
|
||||
one-time key isn't a signed curve key"
|
||||
)]
|
||||
OneTimeKeyNotSigned(UserId, Box<DeviceId>),
|
||||
OneTimeKeyNotSigned(Box<UserId>, Box<DeviceId>),
|
||||
#[error(
|
||||
"Tried to create a new Olm session for {0} {1}, but the signed \
|
||||
one-time key is missing"
|
||||
)]
|
||||
OneTimeKeyMissing(UserId, Box<DeviceId>),
|
||||
OneTimeKeyMissing(Box<UserId>, Box<DeviceId>),
|
||||
#[error(
|
||||
"Tried to create a new Olm session for {0} {1}, but the one-time \
|
||||
key algorithm is unsupported"
|
||||
)]
|
||||
OneTimeKeyUnknown(UserId, Box<DeviceId>),
|
||||
OneTimeKeyUnknown(Box<UserId>, Box<DeviceId>),
|
||||
#[error("Failed to verify the one-time key signatures for {0} {1}: {2:?}")]
|
||||
InvalidSignature(UserId, Box<DeviceId>, SignatureError),
|
||||
InvalidSignature(Box<UserId>, Box<DeviceId>, SignatureError),
|
||||
#[error(
|
||||
"Tried to create an Olm session for {0} {1}, but the device is missing \
|
||||
a curve25519 key"
|
||||
)]
|
||||
DeviceMissingCurveKey(UserId, Box<DeviceId>),
|
||||
DeviceMissingCurveKey(Box<UserId>, Box<DeviceId>),
|
||||
#[error("Error creating new Olm session for {0} {1}: {2:?}")]
|
||||
OlmError(UserId, Box<DeviceId>, OlmSessionError),
|
||||
OlmError(Box<UserId>, Box<DeviceId>, OlmSessionError),
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ pub enum KeyExportError {
|
||||
/// # use ruma::user_id;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # let machine = OlmMachine::new(&alice, "DEVICEID".into());
|
||||
/// # let machine = OlmMachine::new(&alice, device_id!("DEVICEID"));
|
||||
/// # block_on(async {
|
||||
/// # let export = Cursor::new("".to_owned());
|
||||
/// let exported_keys = decrypt_key_export(export, "1234").unwrap();
|
||||
@@ -130,7 +130,7 @@ pub fn decrypt_key_export(
|
||||
/// # use ruma::{user_id, room_id};
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # let machine = OlmMachine::new(&alice, "DEVICEID".into());
|
||||
/// # let machine = OlmMachine::new(&alice, device_id!("DEVICEID"));
|
||||
/// # block_on(async {
|
||||
/// let room_id = room_id!("!test:localhost");
|
||||
/// let exported_keys = machine.export_keys(|s| s.room_id() == &room_id).await.unwrap();
|
||||
@@ -305,8 +305,8 @@ mod test {
|
||||
let (machine, _) = get_prepared_machine().await;
|
||||
let room_id = room_id!("!test:localhost");
|
||||
|
||||
machine.create_outbound_group_session_with_defaults(&room_id).await.unwrap();
|
||||
let export = machine.export_keys(|s| s.room_id() == &room_id).await.unwrap();
|
||||
machine.create_outbound_group_session_with_defaults(room_id).await.unwrap();
|
||||
let export = machine.export_keys(|s| s.room_id() == room_id).await.unwrap();
|
||||
|
||||
assert!(!export.is_empty());
|
||||
|
||||
@@ -324,7 +324,7 @@ mod test {
|
||||
async fn test_importing_better_session() -> OlmResult<()> {
|
||||
let (machine, _) = get_prepared_machine().await;
|
||||
let room_id = room_id!("!test:localhost");
|
||||
let session = machine.create_inbound_session(&room_id).await?;
|
||||
let session = machine.create_inbound_session(room_id).await?;
|
||||
|
||||
let export = vec![session.export_at_index(10).await];
|
||||
|
||||
@@ -350,7 +350,7 @@ mod test {
|
||||
|
||||
assert_eq!(machine.import_keys(better_export, false, |_, _| {}).await?, keys,);
|
||||
|
||||
let another_session = machine.create_inbound_session(&room_id).await?;
|
||||
let another_session = machine.create_inbound_session(room_id).await?;
|
||||
let export = vec![another_session.export_at_index(10).await];
|
||||
|
||||
let keys = RoomKeyImportResult::new(
|
||||
|
||||
@@ -40,7 +40,7 @@ use ruma::{
|
||||
},
|
||||
AnyToDeviceEvent, AnyToDeviceEventContent,
|
||||
},
|
||||
DeviceId, DeviceIdBox, DeviceKeyAlgorithm, EventEncryptionAlgorithm, RoomId, UserId,
|
||||
DeviceId, DeviceKeyAlgorithm, EventEncryptionAlgorithm, RoomId, UserId,
|
||||
};
|
||||
use tracing::{debug, info, trace, warn};
|
||||
|
||||
@@ -63,7 +63,7 @@ pub(crate) struct GossipMachine {
|
||||
outgoing_requests: Arc<DashMap<Uuid, OutgoingRequest>>,
|
||||
incoming_key_requests: Arc<DashMap<RequestInfo, RequestEvent>>,
|
||||
wait_queue: WaitQueue,
|
||||
users_for_key_claim: Arc<DashMap<UserId, DashSet<DeviceIdBox>>>,
|
||||
users_for_key_claim: Arc<DashMap<Box<UserId>, DashSet<Box<DeviceId>>>>,
|
||||
}
|
||||
|
||||
impl GossipMachine {
|
||||
@@ -72,7 +72,7 @@ impl GossipMachine {
|
||||
device_id: Arc<DeviceId>,
|
||||
store: Store,
|
||||
outbound_group_sessions: GroupSessionCache,
|
||||
users_for_key_claim: Arc<DashMap<UserId, DashSet<DeviceIdBox>>>,
|
||||
users_for_key_claim: Arc<DashMap<Box<UserId>, DashSet<Box<DeviceId>>>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
user_id,
|
||||
@@ -940,6 +940,7 @@ mod test {
|
||||
use matrix_sdk_common::locks::Mutex;
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::{
|
||||
device_id,
|
||||
events::{
|
||||
forwarded_room_key::ToDeviceForwardedRoomKeyEventContent,
|
||||
room::encrypted::ToDeviceRoomEncryptedEventContent,
|
||||
@@ -949,7 +950,7 @@ mod test {
|
||||
},
|
||||
room_id,
|
||||
to_device::DeviceIdOrAllDevices,
|
||||
user_id, DeviceIdBox, DeviceKeyAlgorithm, RoomId, UserId,
|
||||
user_id, DeviceId, DeviceKeyAlgorithm, RoomId, UserId,
|
||||
};
|
||||
|
||||
use super::{GossipMachine, KeyForwardDecision};
|
||||
@@ -962,49 +963,50 @@ mod test {
|
||||
OutgoingRequests,
|
||||
};
|
||||
|
||||
fn alice_id() -> UserId {
|
||||
fn alice_id() -> &'static UserId {
|
||||
user_id!("@alice:example.org")
|
||||
}
|
||||
|
||||
fn alice_device_id() -> DeviceIdBox {
|
||||
"JLAFKJWSCS".into()
|
||||
fn alice_device_id() -> &'static DeviceId {
|
||||
device_id!("JLAFKJWSCS")
|
||||
}
|
||||
|
||||
fn bob_id() -> UserId {
|
||||
fn bob_id() -> &'static UserId {
|
||||
user_id!("@bob:example.org")
|
||||
}
|
||||
|
||||
fn bob_device_id() -> DeviceIdBox {
|
||||
"ILMLKASTES".into()
|
||||
fn bob_device_id() -> &'static DeviceId {
|
||||
device_id!("ILMLKASTES")
|
||||
}
|
||||
|
||||
fn alice2_device_id() -> DeviceIdBox {
|
||||
"ILMLKASTES".into()
|
||||
fn alice2_device_id() -> &'static DeviceId {
|
||||
device_id!("ILMLKASTES")
|
||||
}
|
||||
|
||||
fn room_id() -> RoomId {
|
||||
fn room_id() -> &'static RoomId {
|
||||
room_id!("!test:example.org")
|
||||
}
|
||||
|
||||
fn account() -> ReadOnlyAccount {
|
||||
ReadOnlyAccount::new(&alice_id(), &alice_device_id())
|
||||
ReadOnlyAccount::new(alice_id(), alice_device_id())
|
||||
}
|
||||
|
||||
fn bob_account() -> ReadOnlyAccount {
|
||||
ReadOnlyAccount::new(&bob_id(), &bob_device_id())
|
||||
ReadOnlyAccount::new(bob_id(), bob_device_id())
|
||||
}
|
||||
|
||||
fn alice_2_account() -> ReadOnlyAccount {
|
||||
ReadOnlyAccount::new(&alice_id(), &alice2_device_id())
|
||||
ReadOnlyAccount::new(alice_id(), alice2_device_id())
|
||||
}
|
||||
|
||||
fn bob_machine() -> GossipMachine {
|
||||
let user_id = Arc::new(bob_id());
|
||||
let account = ReadOnlyAccount::new(&user_id, &alice_device_id());
|
||||
let user_id = Arc::from(bob_id());
|
||||
let account = ReadOnlyAccount::new(&user_id, alice_device_id());
|
||||
let store: Arc<dyn CryptoStore> = Arc::new(MemoryStore::new());
|
||||
let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(bob_id())));
|
||||
let identity =
|
||||
Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(bob_id().to_owned())));
|
||||
let verification = VerificationMachine::new(account, identity.clone(), store.clone());
|
||||
let store = Store::new(user_id.clone(), identity, store, verification);
|
||||
let store = Store::new(user_id.to_owned(), identity, store, verification);
|
||||
let session_cache = GroupSessionCache::new(store.clone());
|
||||
|
||||
GossipMachine::new(
|
||||
@@ -1018,14 +1020,14 @@ mod test {
|
||||
|
||||
async fn get_machine() -> GossipMachine {
|
||||
let user_id: Arc<UserId> = alice_id().into();
|
||||
let account = ReadOnlyAccount::new(&user_id, &alice_device_id());
|
||||
let account = ReadOnlyAccount::new(&user_id, alice_device_id());
|
||||
let device = ReadOnlyDevice::from_account(&account).await;
|
||||
let another_device =
|
||||
ReadOnlyDevice::from_account(&ReadOnlyAccount::new(&user_id, &alice2_device_id()))
|
||||
.await;
|
||||
ReadOnlyDevice::from_account(&ReadOnlyAccount::new(&user_id, alice2_device_id())).await;
|
||||
|
||||
let store: Arc<dyn CryptoStore> = Arc::new(MemoryStore::new());
|
||||
let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(alice_id())));
|
||||
let identity =
|
||||
Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(alice_id().to_owned())));
|
||||
let verification = VerificationMachine::new(account, identity.clone(), store.clone());
|
||||
|
||||
let store = Store::new(user_id.clone(), identity, store, verification);
|
||||
@@ -1054,7 +1056,7 @@ mod test {
|
||||
let account = account();
|
||||
|
||||
let (_, session) =
|
||||
account.create_group_session_pair_with_defaults(&room_id()).await.unwrap();
|
||||
account.create_group_session_pair_with_defaults(room_id()).await.unwrap();
|
||||
|
||||
assert!(machine.outgoing_to_device_requests().await.unwrap().is_empty());
|
||||
let (cancel, request) = machine
|
||||
@@ -1086,7 +1088,7 @@ mod test {
|
||||
machine.store.save_devices(&[alice_device]).await.unwrap();
|
||||
|
||||
let (_, session) =
|
||||
account.create_group_session_pair_with_defaults(&room_id()).await.unwrap();
|
||||
account.create_group_session_pair_with_defaults(room_id()).await.unwrap();
|
||||
|
||||
assert!(machine.outgoing_to_device_requests().await.unwrap().is_empty());
|
||||
machine
|
||||
@@ -1131,7 +1133,7 @@ mod test {
|
||||
machine.store.save_devices(&[alice_device]).await.unwrap();
|
||||
|
||||
let (_, session) =
|
||||
account.create_group_session_pair_with_defaults(&room_id()).await.unwrap();
|
||||
account.create_group_session_pair_with_defaults(room_id()).await.unwrap();
|
||||
machine
|
||||
.create_outgoing_key_request(
|
||||
session.room_id(),
|
||||
@@ -1151,7 +1153,7 @@ mod test {
|
||||
|
||||
let content: ToDeviceForwardedRoomKeyEventContent = export.try_into().unwrap();
|
||||
|
||||
let mut event = ToDeviceEvent { sender: alice_id(), content };
|
||||
let mut event = ToDeviceEvent { sender: alice_id().to_owned(), content };
|
||||
|
||||
assert!(
|
||||
machine
|
||||
@@ -1198,7 +1200,7 @@ mod test {
|
||||
|
||||
let content: ToDeviceForwardedRoomKeyEventContent = export.try_into().unwrap();
|
||||
|
||||
let mut event = ToDeviceEvent { sender: alice_id(), content };
|
||||
let mut event = ToDeviceEvent { sender: alice_id().to_owned(), content };
|
||||
|
||||
let (_, second_session) =
|
||||
machine.receive_forwarded_room_key(&session.sender_key, &mut event).await.unwrap();
|
||||
@@ -1209,7 +1211,7 @@ mod test {
|
||||
|
||||
let content: ToDeviceForwardedRoomKeyEventContent = export.try_into().unwrap();
|
||||
|
||||
let mut event = ToDeviceEvent { sender: alice_id(), content };
|
||||
let mut event = ToDeviceEvent { sender: alice_id().to_owned(), content };
|
||||
|
||||
let (_, second_session) =
|
||||
machine.receive_forwarded_room_key(&session.sender_key, &mut event).await.unwrap();
|
||||
@@ -1223,10 +1225,10 @@ mod test {
|
||||
let account = account();
|
||||
|
||||
let own_device =
|
||||
machine.store.get_device(&alice_id(), &alice2_device_id()).await.unwrap().unwrap();
|
||||
machine.store.get_device(alice_id(), alice2_device_id()).await.unwrap().unwrap();
|
||||
|
||||
let (outbound, inbound) =
|
||||
account.create_group_session_pair_with_defaults(&room_id()).await.unwrap();
|
||||
account.create_group_session_pair_with_defaults(room_id()).await.unwrap();
|
||||
|
||||
// We don't share keys with untrusted devices.
|
||||
assert_matches!(
|
||||
@@ -1241,7 +1243,7 @@ mod test {
|
||||
machine.store.save_devices(&[bob_device]).await.unwrap();
|
||||
|
||||
let bob_device =
|
||||
machine.store.get_device(&bob_id(), &bob_device_id()).await.unwrap().unwrap();
|
||||
machine.store.get_device(bob_id(), bob_device_id()).await.unwrap().unwrap();
|
||||
|
||||
// We don't share sessions with other user's devices if no outbound
|
||||
// session was provided.
|
||||
@@ -1284,7 +1286,7 @@ mod test {
|
||||
assert!(machine.should_share_key(&bob_device, &inbound).await.is_ok());
|
||||
|
||||
let (other_outbound, other_inbound) =
|
||||
account.create_group_session_pair_with_defaults(&room_id()).await.unwrap();
|
||||
account.create_group_session_pair_with_defaults(room_id()).await.unwrap();
|
||||
|
||||
// But we don't share some other session that doesn't match our outbound
|
||||
// session.
|
||||
@@ -1299,7 +1301,7 @@ mod test {
|
||||
machine.store.save_devices(&[bob_device]).await.unwrap();
|
||||
|
||||
let bob_device =
|
||||
machine.store.get_device(&bob_id(), &bob_device_id()).await.unwrap().unwrap();
|
||||
machine.store.get_device(bob_id(), bob_device_id()).await.unwrap().unwrap();
|
||||
assert_matches!(
|
||||
machine.should_share_key(&bob_device, &inbound).await,
|
||||
Err(KeyForwardDecision::ChangedSenderKey)
|
||||
@@ -1362,14 +1364,14 @@ mod test {
|
||||
bob_machine.store.save_devices(&[alice_device.clone()]).await.unwrap();
|
||||
|
||||
let (group_session, inbound_group_session) =
|
||||
bob_account.create_group_session_pair_with_defaults(&room_id()).await.unwrap();
|
||||
bob_account.create_group_session_pair_with_defaults(room_id()).await.unwrap();
|
||||
|
||||
bob_machine.store.save_inbound_group_sessions(&[inbound_group_session]).await.unwrap();
|
||||
|
||||
// Alice wants to request the outbound group session from bob.
|
||||
alice_machine
|
||||
.create_outgoing_key_request(
|
||||
&room_id(),
|
||||
room_id(),
|
||||
bob_account.identity_keys.curve25519(),
|
||||
group_session.session_id(),
|
||||
)
|
||||
@@ -1395,7 +1397,7 @@ mod test {
|
||||
.to_device()
|
||||
.unwrap()
|
||||
.messages
|
||||
.get(&alice_id())
|
||||
.get(alice_id())
|
||||
.unwrap()
|
||||
.get(&DeviceIdOrAllDevices::AllDevices)
|
||||
.unwrap();
|
||||
@@ -1403,7 +1405,7 @@ mod test {
|
||||
|
||||
alice_machine.mark_outgoing_request_as_sent(id).await.unwrap();
|
||||
|
||||
let event = ToDeviceEvent { sender: alice_id(), content };
|
||||
let event = ToDeviceEvent { sender: alice_id().to_owned(), content };
|
||||
|
||||
// Bob doesn't have any outgoing requests.
|
||||
assert!(bob_machine.outgoing_requests.is_empty());
|
||||
@@ -1424,21 +1426,21 @@ mod test {
|
||||
.to_device()
|
||||
.unwrap()
|
||||
.messages
|
||||
.get(&alice_id())
|
||||
.get(alice_id())
|
||||
.unwrap()
|
||||
.get(&DeviceIdOrAllDevices::DeviceId(alice_device_id()))
|
||||
.get(&DeviceIdOrAllDevices::DeviceId(alice_device_id().to_owned()))
|
||||
.unwrap();
|
||||
let content: ToDeviceRoomEncryptedEventContent = content.deserialize_as().unwrap();
|
||||
|
||||
bob_machine.mark_outgoing_request_as_sent(id).await.unwrap();
|
||||
|
||||
let event = ToDeviceEvent { sender: bob_id(), content };
|
||||
let event = ToDeviceEvent { sender: bob_id().to_owned(), content };
|
||||
|
||||
// Check that alice doesn't have the session.
|
||||
assert!(alice_machine
|
||||
.store
|
||||
.get_inbound_group_session(
|
||||
&room_id(),
|
||||
room_id(),
|
||||
bob_account.identity_keys().curve25519(),
|
||||
group_session.session_id()
|
||||
)
|
||||
@@ -1461,11 +1463,7 @@ mod test {
|
||||
// Check that alice now does have the session.
|
||||
let session = alice_machine
|
||||
.store
|
||||
.get_inbound_group_session(
|
||||
&room_id(),
|
||||
&decrypted.sender_key,
|
||||
group_session.session_id(),
|
||||
)
|
||||
.get_inbound_group_session(room_id(), &decrypted.sender_key, group_session.session_id())
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
@@ -1521,7 +1519,7 @@ mod test {
|
||||
assert!(alice_machine.outgoing_requests.is_empty());
|
||||
|
||||
let event = ToDeviceEvent {
|
||||
sender: alice_id(),
|
||||
sender: alice_id().to_owned(),
|
||||
content: ToDeviceSecretRequestEventContent::new(
|
||||
RequestAction::Request(SecretName::CrossSigningMasterKey),
|
||||
second_account.device_id().into(),
|
||||
@@ -1570,14 +1568,14 @@ mod test {
|
||||
bob_machine.store.save_devices(&[alice_device.clone()]).await.unwrap();
|
||||
|
||||
let (group_session, inbound_group_session) =
|
||||
bob_account.create_group_session_pair_with_defaults(&room_id()).await.unwrap();
|
||||
bob_account.create_group_session_pair_with_defaults(room_id()).await.unwrap();
|
||||
|
||||
bob_machine.store.save_inbound_group_sessions(&[inbound_group_session]).await.unwrap();
|
||||
|
||||
// Alice wants to request the outbound group session from bob.
|
||||
alice_machine
|
||||
.create_outgoing_key_request(
|
||||
&room_id(),
|
||||
room_id(),
|
||||
bob_account.identity_keys.curve25519(),
|
||||
group_session.session_id(),
|
||||
)
|
||||
@@ -1603,7 +1601,7 @@ mod test {
|
||||
.to_device()
|
||||
.unwrap()
|
||||
.messages
|
||||
.get(&alice_id())
|
||||
.get(alice_id())
|
||||
.unwrap()
|
||||
.get(&DeviceIdOrAllDevices::AllDevices)
|
||||
.unwrap();
|
||||
@@ -1611,7 +1609,7 @@ mod test {
|
||||
|
||||
alice_machine.mark_outgoing_request_as_sent(id).await.unwrap();
|
||||
|
||||
let event = ToDeviceEvent { sender: alice_id(), content };
|
||||
let event = ToDeviceEvent { sender: alice_id().to_owned(), content };
|
||||
|
||||
// Bob doesn't have any outgoing requests.
|
||||
assert!(bob_machine.outgoing_to_device_requests().await.unwrap().is_empty());
|
||||
@@ -1634,7 +1632,7 @@ mod test {
|
||||
alice_machine.store.save_sessions(&[alice_session]).await.unwrap();
|
||||
bob_machine.store.save_sessions(&[bob_session]).await.unwrap();
|
||||
|
||||
bob_machine.retry_keyshare(&alice_id(), &alice_device_id());
|
||||
bob_machine.retry_keyshare(alice_id(), alice_device_id());
|
||||
assert!(bob_machine.users_for_key_claim.is_empty());
|
||||
bob_machine.collect_incoming_key_requests().await.unwrap();
|
||||
// Bob now has an outgoing requests.
|
||||
@@ -1652,21 +1650,21 @@ mod test {
|
||||
.to_device()
|
||||
.unwrap()
|
||||
.messages
|
||||
.get(&alice_id())
|
||||
.get(alice_id())
|
||||
.unwrap()
|
||||
.get(&DeviceIdOrAllDevices::DeviceId(alice_device_id()))
|
||||
.get(&DeviceIdOrAllDevices::DeviceId(alice_device_id().to_owned()))
|
||||
.unwrap();
|
||||
let content: ToDeviceRoomEncryptedEventContent = content.deserialize_as().unwrap();
|
||||
|
||||
bob_machine.mark_outgoing_request_as_sent(id).await.unwrap();
|
||||
|
||||
let event = ToDeviceEvent { sender: bob_id(), content };
|
||||
let event = ToDeviceEvent { sender: bob_id().to_owned(), content };
|
||||
|
||||
// Check that alice doesn't have the session.
|
||||
assert!(alice_machine
|
||||
.store
|
||||
.get_inbound_group_session(
|
||||
&room_id(),
|
||||
room_id(),
|
||||
bob_account.identity_keys().curve25519(),
|
||||
group_session.session_id()
|
||||
)
|
||||
@@ -1689,11 +1687,7 @@ mod test {
|
||||
// Check that alice now does have the session.
|
||||
let session = alice_machine
|
||||
.store
|
||||
.get_inbound_group_session(
|
||||
&room_id(),
|
||||
&decrypted.sender_key,
|
||||
group_session.session_id(),
|
||||
)
|
||||
.get_inbound_group_session(room_id(), &decrypted.sender_key, group_session.session_id())
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
@@ -32,7 +32,7 @@ use ruma::{
|
||||
AnyToDeviceEventContent,
|
||||
},
|
||||
to_device::DeviceIdOrAllDevices,
|
||||
DeviceId, DeviceIdBox, UserId,
|
||||
DeviceId, UserId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
@@ -67,7 +67,7 @@ pub enum KeyForwardDecision {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct GossipRequest {
|
||||
/// The user we requested the secret from
|
||||
pub request_recipient: UserId,
|
||||
pub request_recipient: Box<UserId>,
|
||||
/// The unique id of the secret request.
|
||||
pub request_id: Uuid,
|
||||
/// The info of the requested secret.
|
||||
@@ -99,7 +99,7 @@ impl From<SecretName> for SecretInfo {
|
||||
|
||||
impl GossipRequest {
|
||||
/// Create an ougoing secret request for the given secret.
|
||||
pub(crate) fn from_secret_name(own_user_id: UserId, secret_name: SecretName) -> Self {
|
||||
pub(crate) fn from_secret_name(own_user_id: Box<UserId>, secret_name: SecretName) -> Self {
|
||||
Self {
|
||||
request_recipient: own_user_id,
|
||||
request_id: Uuid::new_v4(),
|
||||
@@ -243,13 +243,13 @@ impl RequestEvent {
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
struct RequestInfo {
|
||||
sender: UserId,
|
||||
requesting_device_id: DeviceIdBox,
|
||||
sender: Box<UserId>,
|
||||
requesting_device_id: Box<DeviceId>,
|
||||
request_id: String,
|
||||
}
|
||||
|
||||
impl RequestInfo {
|
||||
fn new(sender: UserId, requesting_device_id: DeviceIdBox, request_id: String) -> Self {
|
||||
fn new(sender: Box<UserId>, requesting_device_id: Box<DeviceId>, request_id: String) -> Self {
|
||||
Self { sender, requesting_device_id, request_id }
|
||||
}
|
||||
}
|
||||
@@ -259,7 +259,8 @@ impl RequestInfo {
|
||||
#[derive(Debug, Clone)]
|
||||
struct WaitQueue {
|
||||
requests_waiting_for_session: Arc<DashMap<RequestInfo, RequestEvent>>,
|
||||
requests_ids_waiting: Arc<DashMap<(UserId, DeviceIdBox), DashSet<String>>>,
|
||||
#[allow(clippy::type_complexity)]
|
||||
requests_ids_waiting: Arc<DashMap<(Box<UserId>, Box<DeviceId>), DashSet<String>>>,
|
||||
}
|
||||
|
||||
impl WaitQueue {
|
||||
|
||||
@@ -32,7 +32,7 @@ use ruma::{
|
||||
key::verification::VerificationMethod, room::encrypted::ToDeviceRoomEncryptedEventContent,
|
||||
AnyToDeviceEventContent,
|
||||
},
|
||||
DeviceId, DeviceIdBox, DeviceKeyAlgorithm, DeviceKeyId, EventEncryptionAlgorithm, UserId,
|
||||
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, EventEncryptionAlgorithm, UserId,
|
||||
};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use serde_json::{json, Value};
|
||||
@@ -69,7 +69,7 @@ pub struct ReadOnlyDevice {
|
||||
impl std::fmt::Debug for ReadOnlyDevice {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("ReadOnlyDevice")
|
||||
.field("user_id", self.user_id())
|
||||
.field("user_id", &self.user_id())
|
||||
.field("device_id", &self.device_id())
|
||||
.field("display_name", &self.display_name())
|
||||
.field("keys", self.keys())
|
||||
@@ -290,7 +290,7 @@ impl Device {
|
||||
/// A read only view over all devices belonging to a user.
|
||||
#[derive(Debug)]
|
||||
pub struct UserDevices {
|
||||
pub(crate) inner: HashMap<DeviceIdBox, ReadOnlyDevice>,
|
||||
pub(crate) inner: HashMap<Box<DeviceId>, ReadOnlyDevice>,
|
||||
pub(crate) verification_machine: VerificationMachine,
|
||||
pub(crate) own_identity: Option<ReadOnlyOwnUserIdentity>,
|
||||
pub(crate) device_owner_identity: Option<ReadOnlyUserIdentities>,
|
||||
@@ -330,7 +330,7 @@ impl UserDevices {
|
||||
}
|
||||
|
||||
/// Iterator over all the device ids of the user devices.
|
||||
pub fn keys(&self) -> impl Iterator<Item = &DeviceIdBox> {
|
||||
pub fn keys(&self) -> impl Iterator<Item = &Box<DeviceId>> {
|
||||
self.inner.keys()
|
||||
}
|
||||
|
||||
@@ -404,12 +404,12 @@ impl ReadOnlyDevice {
|
||||
}
|
||||
|
||||
/// Get a map containing all the device keys.
|
||||
pub fn keys(&self) -> &BTreeMap<DeviceKeyId, String> {
|
||||
pub fn keys(&self) -> &BTreeMap<Box<DeviceKeyId>, String> {
|
||||
&self.inner.keys
|
||||
}
|
||||
|
||||
/// Get a map containing all the device signatures.
|
||||
pub fn signatures(&self) -> &BTreeMap<UserId, BTreeMap<DeviceKeyId, String>> {
|
||||
pub fn signatures(&self) -> &BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>> {
|
||||
&self.inner.signatures
|
||||
}
|
||||
|
||||
@@ -651,7 +651,7 @@ pub(crate) mod test {
|
||||
|
||||
let device = get_device();
|
||||
|
||||
assert_eq!(&user_id, device.user_id());
|
||||
assert_eq!(user_id, device.user_id());
|
||||
assert_eq!(device_id, device.device_id());
|
||||
assert_eq!(device.algorithms().len(), 2);
|
||||
assert_eq!(LocalTrust::Unset, device.local_trust_state());
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet, HashSet},
|
||||
convert::TryFrom,
|
||||
ops::Deref,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
@@ -22,7 +23,7 @@ use futures_util::future::join_all;
|
||||
use matrix_sdk_common::executor::spawn;
|
||||
use ruma::{
|
||||
api::client::r0::keys::get_keys::Response as KeysQueryResponse, encryption::DeviceKeys,
|
||||
DeviceId, DeviceIdBox, UserId,
|
||||
DeviceId, UserId,
|
||||
};
|
||||
use tracing::{debug, info, trace, warn};
|
||||
|
||||
@@ -76,7 +77,7 @@ impl IdentityManager {
|
||||
response: &KeysQueryResponse,
|
||||
) -> OlmResult<(DeviceChanges, IdentityChanges)> {
|
||||
debug!(
|
||||
users =? response.device_keys.keys().collect::<BTreeSet<&UserId>>(),
|
||||
users =? response.device_keys.keys().collect::<BTreeSet<_>>(),
|
||||
failures =? response.failures,
|
||||
"Handling a keys query response"
|
||||
);
|
||||
@@ -93,7 +94,7 @@ impl IdentityManager {
|
||||
|
||||
// TODO turn this into a single transaction.
|
||||
self.store.save_changes(changes).await?;
|
||||
let updated_users: Vec<&UserId> = response.device_keys.keys().collect();
|
||||
let updated_users: Vec<&UserId> = response.device_keys.keys().map(Deref::deref).collect();
|
||||
|
||||
for user_id in updated_users {
|
||||
self.store.update_tracked_user(user_id, false).await?;
|
||||
@@ -203,14 +204,14 @@ impl IdentityManager {
|
||||
store: Store,
|
||||
own_user_id: Arc<UserId>,
|
||||
own_device_id: Arc<DeviceId>,
|
||||
user_id: UserId,
|
||||
device_map: BTreeMap<DeviceIdBox, DeviceKeys>,
|
||||
user_id: Box<UserId>,
|
||||
device_map: BTreeMap<Box<DeviceId>, DeviceKeys>,
|
||||
) -> StoreResult<DeviceChanges> {
|
||||
let own_device_id = (&*own_device_id).to_owned();
|
||||
|
||||
let mut changes = DeviceChanges::default();
|
||||
|
||||
let current_devices: HashSet<DeviceIdBox> = device_map.keys().cloned().collect();
|
||||
let current_devices: HashSet<Box<DeviceId>> = device_map.keys().cloned().collect();
|
||||
|
||||
let tasks = device_map.into_iter().filter_map(|(device_id, device_keys)| {
|
||||
if user_id != device_keys.user_id || device_id != device_keys.device_id {
|
||||
@@ -239,9 +240,9 @@ impl IdentityManager {
|
||||
}
|
||||
}
|
||||
|
||||
let current_devices: HashSet<&DeviceIdBox> = current_devices.iter().collect();
|
||||
let current_devices: HashSet<&Box<DeviceId>> = current_devices.iter().collect();
|
||||
let stored_devices = store.get_readonly_devices_unfiltered(&user_id).await?;
|
||||
let stored_devices_set: HashSet<&DeviceIdBox> = stored_devices.keys().collect();
|
||||
let stored_devices_set: HashSet<&Box<DeviceId>> = stored_devices.keys().collect();
|
||||
let deleted_devices_set = stored_devices_set.difference(¤t_devices);
|
||||
|
||||
for device_id in deleted_devices_set {
|
||||
@@ -271,7 +272,7 @@ impl IdentityManager {
|
||||
/// they are new, one of their properties has changed or they got deleted.
|
||||
async fn handle_devices_from_key_query(
|
||||
&self,
|
||||
device_keys_map: BTreeMap<UserId, BTreeMap<DeviceIdBox, DeviceKeys>>,
|
||||
device_keys_map: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, DeviceKeys>>,
|
||||
) -> StoreResult<DeviceChanges> {
|
||||
let mut changes = DeviceChanges::default();
|
||||
|
||||
@@ -442,7 +443,7 @@ impl IdentityManager {
|
||||
if users.is_empty() {
|
||||
Vec::new()
|
||||
} else {
|
||||
let users: Vec<UserId> = users.into_iter().collect();
|
||||
let users: Vec<Box<UserId>> = users.into_iter().collect();
|
||||
|
||||
users
|
||||
.chunks(Self::MAX_KEY_QUERY_USERS)
|
||||
@@ -502,7 +503,7 @@ pub(crate) mod test {
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::{
|
||||
api::{client::r0::keys::get_keys::Response as KeyQueryResponse, IncomingResponse},
|
||||
user_id, DeviceIdBox, UserId,
|
||||
device_id, user_id, DeviceId, UserId,
|
||||
};
|
||||
use serde_json::json;
|
||||
|
||||
@@ -514,22 +515,23 @@ pub(crate) mod test {
|
||||
verification::VerificationMachine,
|
||||
};
|
||||
|
||||
fn user_id() -> UserId {
|
||||
fn user_id() -> &'static UserId {
|
||||
user_id!("@example:localhost")
|
||||
}
|
||||
|
||||
fn other_user_id() -> UserId {
|
||||
fn other_user_id() -> &'static UserId {
|
||||
user_id!("@example2:localhost")
|
||||
}
|
||||
|
||||
fn device_id() -> DeviceIdBox {
|
||||
"WSKKLTJZCL".into()
|
||||
fn device_id() -> &'static DeviceId {
|
||||
device_id!("WSKKLTJZCL")
|
||||
}
|
||||
|
||||
fn manager() -> IdentityManager {
|
||||
let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(user_id())));
|
||||
let user_id = Arc::new(user_id());
|
||||
let account = ReadOnlyAccount::new(&user_id, &device_id());
|
||||
let identity =
|
||||
Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(user_id().to_owned())));
|
||||
let user_id = Arc::from(user_id());
|
||||
let account = ReadOnlyAccount::new(&user_id, device_id());
|
||||
let store: Arc<dyn CryptoStore> = Arc::new(MemoryStore::new());
|
||||
let verification = VerificationMachine::new(account, identity.clone(), store);
|
||||
let store =
|
||||
@@ -707,21 +709,21 @@ pub(crate) mod test {
|
||||
async fn test_manager_key_query_response() {
|
||||
let manager = manager();
|
||||
let other_user = other_user_id();
|
||||
let devices = manager.store.get_user_devices(&other_user).await.unwrap();
|
||||
let devices = manager.store.get_user_devices(other_user).await.unwrap();
|
||||
assert_eq!(devices.devices().count(), 0);
|
||||
|
||||
manager.receive_keys_query_response(&other_key_query()).await.unwrap();
|
||||
|
||||
let devices = manager.store.get_user_devices(&other_user).await.unwrap();
|
||||
let devices = manager.store.get_user_devices(other_user).await.unwrap();
|
||||
assert_eq!(devices.devices().count(), 1);
|
||||
|
||||
let device = manager
|
||||
.store
|
||||
.get_readonly_device(&other_user, "SKISMLNIMH".into())
|
||||
.get_readonly_device(other_user, device_id!("SKISMLNIMH"))
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let identity = manager.store.get_user_identity(&other_user).await.unwrap().unwrap();
|
||||
let identity = manager.store.get_user_identity(other_user).await.unwrap().unwrap();
|
||||
let identity = identity.other().unwrap();
|
||||
|
||||
assert!(identity.is_device_signed(&device).is_ok())
|
||||
@@ -731,21 +733,21 @@ pub(crate) mod test {
|
||||
async fn test_manager_own_key_query_response() {
|
||||
let manager = manager();
|
||||
let other_user = other_user_id();
|
||||
let devices = manager.store.get_user_devices(&other_user).await.unwrap();
|
||||
let devices = manager.store.get_user_devices(other_user).await.unwrap();
|
||||
assert_eq!(devices.devices().count(), 0);
|
||||
|
||||
manager.receive_keys_query_response(&other_key_query()).await.unwrap();
|
||||
|
||||
let devices = manager.store.get_user_devices(&other_user).await.unwrap();
|
||||
let devices = manager.store.get_user_devices(other_user).await.unwrap();
|
||||
assert_eq!(devices.devices().count(), 1);
|
||||
|
||||
let device = manager
|
||||
.store
|
||||
.get_readonly_device(&other_user, "SKISMLNIMH".into())
|
||||
.get_readonly_device(other_user, device_id!("SKISMLNIMH"))
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let identity = manager.store.get_user_identity(&other_user).await.unwrap().unwrap();
|
||||
let identity = manager.store.get_user_identity(other_user).await.unwrap().unwrap();
|
||||
let identity = identity.other().unwrap();
|
||||
|
||||
assert!(identity.is_device_signed(&device).is_ok())
|
||||
|
||||
@@ -28,7 +28,7 @@ use ruma::{
|
||||
events::{
|
||||
key::verification::VerificationMethod, room::message::KeyVerificationRequestEventContent,
|
||||
},
|
||||
DeviceIdBox, DeviceKeyId, EventId, RoomId, UserId,
|
||||
DeviceId, DeviceKeyId, EventId, RoomId, UserId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::to_value;
|
||||
@@ -165,7 +165,7 @@ impl OwnUserIdentity {
|
||||
&self,
|
||||
methods: Option<Vec<VerificationMethod>>,
|
||||
) -> Result<(VerificationRequest, OutgoingVerificationRequest), CryptoStoreError> {
|
||||
let devices: Vec<DeviceIdBox> = self
|
||||
let devices: Vec<Box<DeviceId>> = self
|
||||
.verification_machine
|
||||
.store
|
||||
.get_user_devices(self.user_id())
|
||||
@@ -440,7 +440,7 @@ impl MasterPubkey {
|
||||
}
|
||||
|
||||
/// Get the signatures map of this cross signing key.
|
||||
pub fn signatures(&self) -> &BTreeMap<UserId, BTreeMap<String, String>> {
|
||||
pub fn signatures(&self) -> &BTreeMap<Box<UserId>, BTreeMap<String, String>> {
|
||||
&self.0.signatures
|
||||
}
|
||||
|
||||
@@ -475,7 +475,7 @@ impl MasterPubkey {
|
||||
) -> Result<(), SignatureError> {
|
||||
let (key_id, key) = self.0.keys.iter().next().ok_or(SignatureError::MissingSigningKey)?;
|
||||
|
||||
let key_id = DeviceKeyId::try_from(key_id.as_str())?;
|
||||
let key_id = <&DeviceKeyId>::try_from(key_id.as_str())?;
|
||||
|
||||
// FIXME `KeyUsage is missing PartialEq.
|
||||
// if self.0.usage.contains(&KeyUsage::Master) {
|
||||
@@ -483,14 +483,14 @@ impl MasterPubkey {
|
||||
// }
|
||||
let subkey: CrossSigningSubKeys = subkey.into();
|
||||
|
||||
if &self.0.user_id != subkey.user_id() {
|
||||
if self.0.user_id != subkey.user_id() {
|
||||
return Err(SignatureError::UserIdMismatch);
|
||||
}
|
||||
|
||||
let utility = Utility::new();
|
||||
utility.verify_json(
|
||||
&self.0.user_id,
|
||||
&key_id,
|
||||
key_id,
|
||||
key,
|
||||
&mut to_value(subkey.cross_signing_key()).map_err(|_| SignatureError::NotAnObject)?,
|
||||
)
|
||||
@@ -537,7 +537,7 @@ impl UserSigningPubkey {
|
||||
let utility = Utility::new();
|
||||
utility.verify_json(
|
||||
&self.0.user_id,
|
||||
&DeviceKeyId::try_from(key_id.as_str())?,
|
||||
key_id.as_str().try_into()?,
|
||||
key,
|
||||
&mut to_value(&*master_key.0).map_err(|_| SignatureError::NotAnObject)?,
|
||||
)
|
||||
@@ -572,12 +572,7 @@ impl SelfSigningPubkey {
|
||||
|
||||
let utility = Utility::new();
|
||||
|
||||
utility.verify_json(
|
||||
&self.0.user_id,
|
||||
&DeviceKeyId::try_from(key_id.as_str())?,
|
||||
key,
|
||||
&mut device,
|
||||
)
|
||||
utility.verify_json(&self.0.user_id, key_id.as_str().try_into()?, key, &mut device)
|
||||
}
|
||||
|
||||
/// Check if the given device is signed by this self signing key.
|
||||
@@ -718,7 +713,7 @@ impl ReadOnlyUserIdentity {
|
||||
) -> Result<Self, SignatureError> {
|
||||
master_key.verify_subkey(&self_signing_key)?;
|
||||
|
||||
Ok(Self { user_id: Arc::new(master_key.0.user_id.clone()), master_key, self_signing_key })
|
||||
Ok(Self { user_id: master_key.0.user_id.clone().into(), master_key, self_signing_key })
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -727,7 +722,7 @@ impl ReadOnlyUserIdentity {
|
||||
let self_signing_key =
|
||||
identity.self_signing_key.lock().await.as_ref().unwrap().public_key.clone();
|
||||
|
||||
Self { user_id: Arc::new(identity.user_id().clone()), master_key, self_signing_key }
|
||||
Self { user_id: identity.user_id().into(), master_key, self_signing_key }
|
||||
}
|
||||
|
||||
/// Get the user id of this identity.
|
||||
@@ -831,7 +826,7 @@ impl ReadOnlyOwnUserIdentity {
|
||||
master_key.verify_subkey(&user_signing_key)?;
|
||||
|
||||
Ok(Self {
|
||||
user_id: Arc::new(master_key.0.user_id.clone()),
|
||||
user_id: master_key.0.user_id.clone().into(),
|
||||
master_key,
|
||||
self_signing_key,
|
||||
user_signing_key,
|
||||
@@ -969,9 +964,9 @@ pub(crate) mod test {
|
||||
fn own_identity(response: &KeyQueryResponse) -> ReadOnlyOwnUserIdentity {
|
||||
let user_id = user_id!("@example:localhost");
|
||||
|
||||
let master_key = response.master_keys.get(&user_id).unwrap();
|
||||
let user_signing = response.user_signing_keys.get(&user_id).unwrap();
|
||||
let self_signing = response.self_signing_keys.get(&user_id).unwrap();
|
||||
let master_key = response.master_keys.get(user_id).unwrap();
|
||||
let user_signing = response.user_signing_keys.get(user_id).unwrap();
|
||||
let self_signing = response.self_signing_keys.get(user_id).unwrap();
|
||||
|
||||
ReadOnlyOwnUserIdentity::new(master_key.into(), self_signing.into(), user_signing.into())
|
||||
.unwrap()
|
||||
@@ -985,8 +980,8 @@ pub(crate) mod test {
|
||||
let user_id = user_id!("@example2:localhost");
|
||||
let response = other_key_query();
|
||||
|
||||
let master_key = response.master_keys.get(&user_id).unwrap();
|
||||
let self_signing = response.self_signing_keys.get(&user_id).unwrap();
|
||||
let master_key = response.master_keys.get(user_id).unwrap();
|
||||
let self_signing = response.self_signing_keys.get(user_id).unwrap();
|
||||
|
||||
ReadOnlyUserIdentity::new(master_key.into(), self_signing.into()).unwrap()
|
||||
}
|
||||
@@ -996,9 +991,9 @@ pub(crate) mod test {
|
||||
let user_id = user_id!("@example:localhost");
|
||||
let response = own_key_query();
|
||||
|
||||
let master_key = response.master_keys.get(&user_id).unwrap();
|
||||
let user_signing = response.user_signing_keys.get(&user_id).unwrap();
|
||||
let self_signing = response.self_signing_keys.get(&user_id).unwrap();
|
||||
let master_key = response.master_keys.get(user_id).unwrap();
|
||||
let user_signing = response.user_signing_keys.get(user_id).unwrap();
|
||||
let self_signing = response.self_signing_keys.get(user_id).unwrap();
|
||||
|
||||
ReadOnlyOwnUserIdentity::new(master_key.into(), self_signing.into(), user_signing.into())
|
||||
.unwrap();
|
||||
@@ -1019,7 +1014,7 @@ pub(crate) mod test {
|
||||
assert!(identity.is_device_signed(&second).is_ok());
|
||||
|
||||
let private_identity =
|
||||
Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(second.user_id().clone())));
|
||||
Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(second.user_id().to_owned())));
|
||||
let verification_machine = VerificationMachine::new(
|
||||
ReadOnlyAccount::new(second.user_id(), second.device_id()),
|
||||
private_identity,
|
||||
|
||||
@@ -55,14 +55,14 @@ pub struct RoomKeyImportResult {
|
||||
///
|
||||
/// It's a map from room id to a map of the sender key to a set of session
|
||||
/// ids.
|
||||
pub keys: BTreeMap<RoomId, BTreeMap<String, BTreeSet<String>>>,
|
||||
pub keys: BTreeMap<Box<RoomId>, BTreeMap<String, BTreeSet<String>>>,
|
||||
}
|
||||
|
||||
impl RoomKeyImportResult {
|
||||
pub(crate) fn new(
|
||||
imported_count: usize,
|
||||
total_count: usize,
|
||||
keys: BTreeMap<RoomId, BTreeMap<String, BTreeSet<String>>>,
|
||||
keys: BTreeMap<Box<RoomId>, BTreeMap<String, BTreeSet<String>>>,
|
||||
) -> Self {
|
||||
Self { imported_count, total_count, keys }
|
||||
}
|
||||
|
||||
@@ -46,8 +46,7 @@ use ruma::{
|
||||
secret::request::SecretName,
|
||||
AnyMessageEventContent, AnyRoomEvent, AnyToDeviceEvent, EventContent,
|
||||
},
|
||||
DeviceId, DeviceIdBox, DeviceKeyAlgorithm, DeviceKeyId, EventEncryptionAlgorithm, RoomId, UInt,
|
||||
UserId,
|
||||
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, EventEncryptionAlgorithm, RoomId, UInt, UserId,
|
||||
};
|
||||
use serde_json::Value;
|
||||
use tracing::{debug, error, info, trace, warn};
|
||||
@@ -135,7 +134,7 @@ impl OlmMachine {
|
||||
/// * `device_id` - The unique id of the device that owns this machine.
|
||||
pub fn new(user_id: &UserId, device_id: &DeviceId) -> Self {
|
||||
let store: Box<dyn CryptoStore> = Box::new(MemoryStore::new());
|
||||
let device_id: DeviceIdBox = device_id.into();
|
||||
let device_id: Box<DeviceId> = device_id.into();
|
||||
let account = ReadOnlyAccount::new(user_id, &device_id);
|
||||
|
||||
OlmMachine::new_helper(
|
||||
@@ -149,12 +148,12 @@ impl OlmMachine {
|
||||
|
||||
fn new_helper(
|
||||
user_id: &UserId,
|
||||
device_id: DeviceIdBox,
|
||||
device_id: Box<DeviceId>,
|
||||
store: Box<dyn CryptoStore>,
|
||||
account: ReadOnlyAccount,
|
||||
user_identity: PrivateCrossSigningIdentity,
|
||||
) -> Self {
|
||||
let user_id = Arc::new(user_id.clone());
|
||||
let user_id: Arc<UserId> = user_id.into();
|
||||
let user_identity = Arc::new(Mutex::new(user_identity));
|
||||
|
||||
let store: Arc<dyn CryptoStore> = store.into();
|
||||
@@ -225,8 +224,8 @@ impl OlmMachine {
|
||||
///
|
||||
/// [`Cryptostore`]: trait.CryptoStore.html
|
||||
pub async fn new_with_store(
|
||||
user_id: UserId,
|
||||
device_id: DeviceIdBox,
|
||||
user_id: Box<UserId>,
|
||||
device_id: Box<DeviceId>,
|
||||
store: Box<dyn CryptoStore>,
|
||||
) -> StoreResult<Self> {
|
||||
let account = match store.load_account().await? {
|
||||
@@ -308,7 +307,7 @@ impl OlmMachine {
|
||||
}
|
||||
|
||||
/// Get all the tracked users we know about
|
||||
pub fn tracked_users(&self) -> HashSet<UserId> {
|
||||
pub fn tracked_users(&self) -> HashSet<Box<UserId>> {
|
||||
self.store.tracked_users()
|
||||
}
|
||||
|
||||
@@ -455,8 +454,8 @@ impl OlmMachine {
|
||||
/// # use matrix_sdk_crypto::OlmMachine;
|
||||
/// # use ruma::UserId;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = UserId::try_from("@alice:example.org").unwrap();
|
||||
/// # let machine = OlmMachine::new(&alice, "DEVICEID".into());
|
||||
/// # let alice = Box::<UserId>::try_from("@alice:example.org").unwrap();
|
||||
/// # let machine = OlmMachine::new(&alice, device_id!("DEVICEID"));
|
||||
/// # block_on(async {
|
||||
/// if machine.should_upload_keys().await {
|
||||
/// let request = machine
|
||||
@@ -1069,7 +1068,7 @@ impl OlmMachine {
|
||||
VerificationState::UnknownDevice
|
||||
};
|
||||
|
||||
let sender = sender.clone();
|
||||
let sender = sender.to_owned();
|
||||
let device_id = device_id.to_owned();
|
||||
|
||||
Ok(EncryptionInfo {
|
||||
@@ -1227,10 +1226,10 @@ impl OlmMachine {
|
||||
/// # use matrix_sdk_crypto::OlmMachine;
|
||||
/// # use ruma::UserId;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = UserId::try_from("@alice:example.org").unwrap();
|
||||
/// # let machine = OlmMachine::new(&alice, "DEVICEID".into());
|
||||
/// # let alice = Box::<UserId>::try_from("@alice:example.org").unwrap();
|
||||
/// # let machine = OlmMachine::new(&alice, device_id!("DEVICEID"));
|
||||
/// # block_on(async {
|
||||
/// let device = machine.get_device(&alice, "DEVICEID".into()).await;
|
||||
/// let device = machine.get_device(&alice, device_id!("DEVICEID")).await;
|
||||
///
|
||||
/// println!("{:?}", device);
|
||||
/// # });
|
||||
@@ -1268,8 +1267,8 @@ impl OlmMachine {
|
||||
/// # use matrix_sdk_crypto::OlmMachine;
|
||||
/// # use ruma::UserId;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = UserId::try_from("@alice:example.org").unwrap();
|
||||
/// # let machine = OlmMachine::new(&alice, "DEVICEID".into());
|
||||
/// # let alice = Box::<UserId>::try_from("@alice:example.org").unwrap();
|
||||
/// # let machine = OlmMachine::new(&alice, device_id!("DEVICEID"));
|
||||
/// # block_on(async {
|
||||
/// let devices = machine.get_user_devices(&alice).await.unwrap();
|
||||
///
|
||||
@@ -1305,7 +1304,7 @@ impl OlmMachine {
|
||||
/// # use ruma::user_id;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # let machine = OlmMachine::new(&alice, "DEVICEID".into());
|
||||
/// # let machine = OlmMachine::new(&alice, device_id!("DEVICEID"));
|
||||
/// # block_on(async {
|
||||
/// # let export = Cursor::new("".to_owned());
|
||||
/// let exported_keys = decrypt_key_export(export, "1234").unwrap();
|
||||
@@ -1417,7 +1416,7 @@ impl OlmMachine {
|
||||
/// # use ruma::{user_id, room_id};
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = user_id!("@alice:example.org");
|
||||
/// # let machine = OlmMachine::new(&alice, "DEVICEID".into());
|
||||
/// # let machine = OlmMachine::new(&alice, device_id!("DEVICEID"));
|
||||
/// # block_on(async {
|
||||
/// let room_id = room_id!("!test:localhost");
|
||||
/// let exported_keys = machine.export_keys(|s| s.room_id() == &room_id).await.unwrap();
|
||||
@@ -1489,7 +1488,7 @@ impl OlmMachine {
|
||||
async fn sign_account(
|
||||
&self,
|
||||
message: &str,
|
||||
signatures: &mut BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>,
|
||||
signatures: &mut BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>,
|
||||
) {
|
||||
let device_key_id = DeviceKeyId::from_parts(DeviceKeyAlgorithm::Ed25519, self.device_id());
|
||||
let signature = self.account.sign(message).await;
|
||||
@@ -1500,11 +1499,11 @@ impl OlmMachine {
|
||||
async fn sign_master(
|
||||
&self,
|
||||
message: &str,
|
||||
signatures: &mut BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>,
|
||||
signatures: &mut BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>,
|
||||
) -> Result<(), crate::SignatureError> {
|
||||
let identity = &*self.user_identity.lock().await;
|
||||
|
||||
let master_key: DeviceIdBox = identity
|
||||
let master_key: Box<DeviceId> = identity
|
||||
.master_public_key()
|
||||
.await
|
||||
.and_then(|m| m.get_first_key().map(|k| k.to_owned()))
|
||||
@@ -1521,7 +1520,10 @@ impl OlmMachine {
|
||||
|
||||
/// Sign the given message using our device key and if available cross
|
||||
/// signing master key.
|
||||
pub async fn sign(&self, message: &str) -> BTreeMap<UserId, BTreeMap<DeviceKeyId, String>> {
|
||||
pub async fn sign(
|
||||
&self,
|
||||
message: &str,
|
||||
) -> BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>> {
|
||||
let mut signatures: BTreeMap<_, BTreeMap<_, _>> = BTreeMap::new();
|
||||
|
||||
self.sign_account(message, &mut signatures).await;
|
||||
@@ -1545,13 +1547,7 @@ impl OlmMachine {
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod test {
|
||||
static USER_ID: &str = "@bob:example.org";
|
||||
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
convert::{TryFrom, TryInto},
|
||||
sync::Arc,
|
||||
};
|
||||
use std::{collections::BTreeMap, convert::TryInto, iter, sync::Arc};
|
||||
|
||||
use http::Response;
|
||||
use matrix_sdk_test::test_json;
|
||||
@@ -1560,6 +1556,7 @@ pub(crate) mod test {
|
||||
client::r0::keys::{claim_keys, get_keys, upload_keys},
|
||||
IncomingResponse,
|
||||
},
|
||||
device_id,
|
||||
encryption::OneTimeKey,
|
||||
event_id,
|
||||
events::{
|
||||
@@ -1584,18 +1581,18 @@ pub(crate) mod test {
|
||||
};
|
||||
|
||||
/// These keys need to be periodically uploaded to the server.
|
||||
type OneTimeKeys = BTreeMap<DeviceKeyId, OneTimeKey>;
|
||||
type OneTimeKeys = BTreeMap<Box<DeviceKeyId>, OneTimeKey>;
|
||||
|
||||
fn alice_id() -> UserId {
|
||||
fn alice_id() -> &'static UserId {
|
||||
user_id!("@alice:example.org")
|
||||
}
|
||||
|
||||
fn alice_device_id() -> Box<DeviceId> {
|
||||
"JLAFKJWSCS".into()
|
||||
fn alice_device_id() -> &'static DeviceId {
|
||||
device_id!("JLAFKJWSCS")
|
||||
}
|
||||
|
||||
fn user_id() -> UserId {
|
||||
UserId::try_from(USER_ID).unwrap()
|
||||
fn user_id() -> &'static UserId {
|
||||
user_id!("@bob:example.com")
|
||||
}
|
||||
|
||||
pub fn response_from_file(json: &serde_json::Value) -> Response<Vec<u8>> {
|
||||
@@ -1632,7 +1629,7 @@ pub(crate) mod test {
|
||||
}
|
||||
|
||||
pub(crate) async fn get_prepared_machine() -> (OlmMachine, OneTimeKeys) {
|
||||
let machine = OlmMachine::new(&user_id(), &alice_device_id());
|
||||
let machine = OlmMachine::new(user_id(), alice_device_id());
|
||||
machine.account.inner.update_uploaded_key_count(0);
|
||||
let request = machine.keys_for_upload().await.expect("Can't prepare initial key upload");
|
||||
let response = keys_upload_response();
|
||||
@@ -1655,7 +1652,7 @@ pub(crate) mod test {
|
||||
|
||||
let alice_id = alice_id();
|
||||
let alice_device = alice_device_id();
|
||||
let alice = OlmMachine::new(&alice_id, &alice_device);
|
||||
let alice = OlmMachine::new(alice_id, alice_device);
|
||||
|
||||
let alice_device = ReadOnlyDevice::from_machine(&alice).await;
|
||||
let bob_device = ReadOnlyDevice::from_machine(&bob).await;
|
||||
@@ -1676,7 +1673,7 @@ pub(crate) mod test {
|
||||
bob_keys.insert(bob.device_id().into(), keys);
|
||||
|
||||
let mut one_time_keys = BTreeMap::new();
|
||||
one_time_keys.insert(bob.user_id().clone(), bob_keys);
|
||||
one_time_keys.insert(bob.user_id().to_owned(), bob_keys);
|
||||
|
||||
let response = claim_keys::Response::new(one_time_keys);
|
||||
|
||||
@@ -1696,7 +1693,7 @@ pub(crate) mod test {
|
||||
.unwrap();
|
||||
alice.store.save_sessions(&[session]).await.unwrap();
|
||||
|
||||
let event = ToDeviceEvent { sender: alice.user_id().clone(), content };
|
||||
let event = ToDeviceEvent { sender: alice.user_id().to_owned(), content };
|
||||
|
||||
let decrypted = bob.decrypt_to_device_event(&event).await.unwrap();
|
||||
bob.store.save_sessions(&[decrypted.session.session()]).await.unwrap();
|
||||
@@ -1706,13 +1703,13 @@ pub(crate) mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn create_olm_machine() {
|
||||
let machine = OlmMachine::new(&user_id(), &alice_device_id());
|
||||
let machine = OlmMachine::new(user_id(), alice_device_id());
|
||||
assert!(machine.should_upload_keys().await);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn receive_keys_upload_response() {
|
||||
let machine = OlmMachine::new(&user_id(), &alice_device_id());
|
||||
let machine = OlmMachine::new(user_id(), alice_device_id());
|
||||
let mut response = keys_upload_response();
|
||||
|
||||
response.one_time_key_counts.remove(&DeviceKeyAlgorithm::SignedCurve25519).unwrap();
|
||||
@@ -1736,7 +1733,7 @@ pub(crate) mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn generate_one_time_keys() {
|
||||
let machine = OlmMachine::new(&user_id(), &alice_device_id());
|
||||
let machine = OlmMachine::new(user_id(), alice_device_id());
|
||||
|
||||
let mut response = keys_upload_response();
|
||||
|
||||
@@ -1753,7 +1750,7 @@ pub(crate) mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_device_key_signing() {
|
||||
let machine = OlmMachine::new(&user_id(), &alice_device_id());
|
||||
let machine = OlmMachine::new(user_id(), alice_device_id());
|
||||
|
||||
let mut device_keys = machine.account.device_keys().await;
|
||||
let identity_keys = machine.account.identity_keys();
|
||||
@@ -1771,24 +1768,24 @@ pub(crate) mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn tests_session_invalidation() {
|
||||
let machine = OlmMachine::new(&user_id(), &alice_device_id());
|
||||
let machine = OlmMachine::new(user_id(), alice_device_id());
|
||||
let room_id = room_id!("!test:example.org");
|
||||
|
||||
machine.create_outbound_group_session_with_defaults(&room_id).await.unwrap();
|
||||
assert!(machine.group_session_manager.get_outbound_group_session(&room_id).is_some());
|
||||
machine.create_outbound_group_session_with_defaults(room_id).await.unwrap();
|
||||
assert!(machine.group_session_manager.get_outbound_group_session(room_id).is_some());
|
||||
|
||||
machine.invalidate_group_session(&room_id).await.unwrap();
|
||||
machine.invalidate_group_session(room_id).await.unwrap();
|
||||
|
||||
assert!(machine
|
||||
.group_session_manager
|
||||
.get_outbound_group_session(&room_id)
|
||||
.get_outbound_group_session(room_id)
|
||||
.unwrap()
|
||||
.invalidated());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_invalid_signature() {
|
||||
let machine = OlmMachine::new(&user_id(), &alice_device_id());
|
||||
let machine = OlmMachine::new(user_id(), alice_device_id());
|
||||
|
||||
let mut device_keys = machine.account.device_keys().await;
|
||||
|
||||
@@ -1804,7 +1801,7 @@ pub(crate) mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_one_time_key_signing() {
|
||||
let machine = OlmMachine::new(&user_id(), &alice_device_id());
|
||||
let machine = OlmMachine::new(user_id(), alice_device_id());
|
||||
machine.account.inner.update_uploaded_key_count(49);
|
||||
|
||||
let mut one_time_keys = machine.account.signed_one_time_keys().await.unwrap();
|
||||
@@ -1825,7 +1822,7 @@ pub(crate) mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_keys_for_upload() {
|
||||
let machine = OlmMachine::new(&user_id(), &alice_device_id());
|
||||
let machine = OlmMachine::new(user_id(), alice_device_id());
|
||||
machine.account.inner.update_uploaded_key_count(0);
|
||||
|
||||
let identity_keys = machine.account.identity_keys();
|
||||
@@ -1869,15 +1866,15 @@ pub(crate) mod test {
|
||||
let (machine, _) = get_prepared_machine().await;
|
||||
let response = keys_query_response();
|
||||
let alice_id = user_id!("@alice:example.org");
|
||||
let alice_device_id: &DeviceId = "JLAFKJWSCS".into();
|
||||
let alice_device_id: &DeviceId = device_id!("JLAFKJWSCS");
|
||||
|
||||
let alice_devices = machine.store.get_user_devices(&alice_id).await.unwrap();
|
||||
let alice_devices = machine.store.get_user_devices(alice_id).await.unwrap();
|
||||
assert!(alice_devices.devices().peekable().peek().is_none());
|
||||
|
||||
machine.receive_keys_query_response(&response).await.unwrap();
|
||||
|
||||
let device = machine.store.get_device(&alice_id, alice_device_id).await.unwrap().unwrap();
|
||||
assert_eq!(device.user_id(), &alice_id);
|
||||
let device = machine.store.get_device(alice_id, alice_device_id).await.unwrap().unwrap();
|
||||
assert_eq!(device.user_id(), alice_id);
|
||||
assert_eq!(device.device_id(), alice_device_id);
|
||||
}
|
||||
|
||||
@@ -1889,11 +1886,11 @@ pub(crate) mod test {
|
||||
let alice_device = alice_device_id();
|
||||
|
||||
let (_, missing_sessions) =
|
||||
machine.get_missing_sessions(&mut [alice.clone()].iter()).await.unwrap().unwrap();
|
||||
machine.get_missing_sessions(iter::once(alice)).await.unwrap().unwrap();
|
||||
|
||||
assert!(missing_sessions.one_time_keys.contains_key(&alice));
|
||||
let user_sessions = missing_sessions.one_time_keys.get(&alice).unwrap();
|
||||
assert!(user_sessions.contains_key(&alice_device));
|
||||
assert!(missing_sessions.one_time_keys.contains_key(alice));
|
||||
let user_sessions = missing_sessions.one_time_keys.get(alice).unwrap();
|
||||
assert!(user_sessions.contains_key(alice_device));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -1908,7 +1905,7 @@ pub(crate) mod test {
|
||||
bob_keys.insert(bob_machine.device_id().into(), keys);
|
||||
|
||||
let mut one_time_keys = BTreeMap::new();
|
||||
one_time_keys.insert(bob_machine.user_id().clone(), bob_keys);
|
||||
one_time_keys.insert(bob_machine.user_id().to_owned(), bob_keys);
|
||||
|
||||
let response = claim_keys::Response::new(one_time_keys);
|
||||
|
||||
@@ -1931,7 +1928,7 @@ pub(crate) mod test {
|
||||
let bob_device = alice.get_device(&bob.user_id, &bob.device_id).await.unwrap().unwrap();
|
||||
|
||||
let event = ToDeviceEvent {
|
||||
sender: alice.user_id().clone(),
|
||||
sender: alice.user_id().to_owned(),
|
||||
content: bob_device
|
||||
.encrypt(AnyToDeviceEventContent::Dummy(ToDeviceDummyEventContent::new()))
|
||||
.await
|
||||
@@ -1955,21 +1952,17 @@ pub(crate) mod test {
|
||||
let room_id = room_id!("!test:example.org");
|
||||
|
||||
let to_device_requests = alice
|
||||
.share_group_session(
|
||||
&room_id,
|
||||
[bob.user_id().clone()].iter(),
|
||||
EncryptionSettings::default(),
|
||||
)
|
||||
.share_group_session(room_id, iter::once(bob.user_id()), EncryptionSettings::default())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let event = ToDeviceEvent {
|
||||
sender: alice.user_id().clone(),
|
||||
sender: alice.user_id().to_owned(),
|
||||
content: to_device_requests_to_content(to_device_requests),
|
||||
};
|
||||
|
||||
let alice_session =
|
||||
alice.group_session_manager.get_outbound_group_session(&room_id).unwrap();
|
||||
alice.group_session_manager.get_outbound_group_session(room_id).unwrap();
|
||||
|
||||
let decrypted = bob.decrypt_to_device_event(&event).await.unwrap();
|
||||
|
||||
@@ -1990,7 +1983,7 @@ pub(crate) mod test {
|
||||
let session = bob
|
||||
.store
|
||||
.get_inbound_group_session(
|
||||
&room_id,
|
||||
room_id,
|
||||
alice.account.identity_keys().curve25519(),
|
||||
alice_session.session_id(),
|
||||
)
|
||||
@@ -2005,16 +1998,12 @@ pub(crate) mod test {
|
||||
let room_id = room_id!("!test:example.org");
|
||||
|
||||
let to_device_requests = alice
|
||||
.share_group_session(
|
||||
&room_id,
|
||||
[bob.user_id().clone()].iter(),
|
||||
EncryptionSettings::default(),
|
||||
)
|
||||
.share_group_session(room_id, iter::once(bob.user_id()), EncryptionSettings::default())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let event = ToDeviceEvent {
|
||||
sender: alice.user_id().clone(),
|
||||
sender: alice.user_id().to_owned(),
|
||||
content: to_device_requests_to_content(to_device_requests),
|
||||
};
|
||||
|
||||
@@ -2027,20 +2016,20 @@ pub(crate) mod test {
|
||||
let content = RoomMessageEventContent::text_plain(plaintext);
|
||||
|
||||
let encrypted_content = alice
|
||||
.encrypt(&room_id, AnyMessageEventContent::RoomMessage(content.clone()))
|
||||
.encrypt(room_id, AnyMessageEventContent::RoomMessage(content.clone()))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let event = SyncMessageEvent {
|
||||
event_id: event_id!("$xxxxx:example.org"),
|
||||
event_id: event_id!("$xxxxx:example.org").to_owned(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
|
||||
sender: alice.user_id().clone(),
|
||||
sender: alice.user_id().to_owned(),
|
||||
content: encrypted_content,
|
||||
unsigned: Unsigned::default(),
|
||||
};
|
||||
|
||||
let decrypted_event =
|
||||
bob.decrypt_room_event(&event, &room_id).await.unwrap().event.deserialize().unwrap();
|
||||
bob.decrypt_room_event(&event, room_id).await.unwrap().event.deserialize().unwrap();
|
||||
|
||||
if let AnySyncRoomEvent::Message(AnySyncMessageEvent::RoomMessage(SyncMessageEvent {
|
||||
sender,
|
||||
@@ -2067,8 +2056,8 @@ pub(crate) mod test {
|
||||
let tmpdir = tempdir().unwrap();
|
||||
|
||||
let machine = OlmMachine::new_with_default_store(
|
||||
&user_id(),
|
||||
&alice_device_id(),
|
||||
user_id(),
|
||||
alice_device_id(),
|
||||
tmpdir.as_ref(),
|
||||
Some("test"),
|
||||
)
|
||||
@@ -2085,7 +2074,7 @@ pub(crate) mod test {
|
||||
|
||||
let machine = OlmMachine::new_with_default_store(
|
||||
&user_id,
|
||||
&alice_device_id(),
|
||||
alice_device_id(),
|
||||
tmpdir.as_ref(),
|
||||
Some("test"),
|
||||
)
|
||||
|
||||
@@ -40,8 +40,7 @@ use ruma::{
|
||||
AnyToDeviceEvent, OlmV1Keys,
|
||||
},
|
||||
serde::{CanonicalJsonValue, Raw},
|
||||
DeviceId, DeviceIdBox, DeviceKeyAlgorithm, DeviceKeyId, EventEncryptionAlgorithm, RoomId, UInt,
|
||||
UserId,
|
||||
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, EventEncryptionAlgorithm, RoomId, UInt, UserId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{json, value::RawValue as RawJsonValue, Value};
|
||||
@@ -85,7 +84,7 @@ impl SessionType {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct OlmDecryptionInfo {
|
||||
pub sender: UserId,
|
||||
pub sender: Box<UserId>,
|
||||
pub session: SessionType,
|
||||
pub message_hash: OlmMessageHash,
|
||||
pub deserialized_event: Option<AnyToDeviceEvent>,
|
||||
@@ -440,8 +439,8 @@ impl Account {
|
||||
) -> OlmResult<(Raw<AnyToDeviceEvent>, String)> {
|
||||
#[derive(Deserialize)]
|
||||
struct DecryptedEvent {
|
||||
sender: UserId,
|
||||
recipient: UserId,
|
||||
sender: Box<UserId>,
|
||||
recipient: Box<UserId>,
|
||||
recipient_keys: OlmV1Keys,
|
||||
keys: OlmV1Keys,
|
||||
}
|
||||
@@ -449,9 +448,9 @@ impl Account {
|
||||
let event: DecryptedEvent = serde_json::from_str(&plaintext)?;
|
||||
let identity_keys = self.inner.identity_keys();
|
||||
|
||||
if &event.recipient != self.user_id() {
|
||||
if event.recipient != self.user_id() {
|
||||
Err(EventError::MismatchedSender(event.recipient, self.user_id().to_owned()).into())
|
||||
} else if &event.sender != sender {
|
||||
} else if event.sender != sender {
|
||||
Err(EventError::MismatchedSender(event.sender, sender.to_owned()).into())
|
||||
} else if identity_keys.ed25519() != event.recipient_keys.ed25519 {
|
||||
Err(EventError::MismatchedKeys(
|
||||
@@ -508,9 +507,9 @@ impl From<String> for AccountPickle {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PickledAccount {
|
||||
/// The user id of the account owner.
|
||||
pub user_id: UserId,
|
||||
pub user_id: Box<UserId>,
|
||||
/// The device id of the account owner.
|
||||
pub device_id: DeviceIdBox,
|
||||
pub device_id: Box<DeviceId>,
|
||||
/// The pickled version of the Olm account.
|
||||
pub pickle: AccountPickle,
|
||||
/// Was the account shared.
|
||||
@@ -542,8 +541,8 @@ impl ReadOnlyAccount {
|
||||
let identity_keys = account.parsed_identity_keys();
|
||||
|
||||
Self {
|
||||
user_id: Arc::new(user_id.to_owned()),
|
||||
device_id: device_id.to_owned().into(),
|
||||
user_id: user_id.into(),
|
||||
device_id: device_id.into(),
|
||||
inner: Arc::new(Mutex::new(account)),
|
||||
identity_keys: Arc::new(identity_keys),
|
||||
shared: Arc::new(AtomicBool::new(false)),
|
||||
@@ -662,7 +661,7 @@ impl ReadOnlyAccount {
|
||||
/// Returns None if no keys need to be uploaded.
|
||||
pub(crate) async fn keys_for_upload(
|
||||
&self,
|
||||
) -> Option<(Option<DeviceKeys>, Option<BTreeMap<DeviceKeyId, OneTimeKey>>)> {
|
||||
) -> Option<(Option<DeviceKeys>, Option<BTreeMap<Box<DeviceKeyId>, OneTimeKey>>)> {
|
||||
if !self.should_upload_keys().await {
|
||||
return None;
|
||||
}
|
||||
@@ -735,7 +734,7 @@ impl ReadOnlyAccount {
|
||||
let identity_keys = account.parsed_identity_keys();
|
||||
|
||||
Ok(Self {
|
||||
user_id: Arc::new(pickle.user_id),
|
||||
user_id: pickle.user_id.into(),
|
||||
device_id: pickle.device_id.into(),
|
||||
inner: Arc::new(Mutex::new(account)),
|
||||
identity_keys: Arc::new(identity_keys),
|
||||
@@ -758,7 +757,7 @@ impl ReadOnlyAccount {
|
||||
]);
|
||||
|
||||
DeviceKeys::new(
|
||||
(*self.user_id).clone(),
|
||||
(*self.user_id).to_owned(),
|
||||
(*self.device_id).to_owned(),
|
||||
Self::ALGORITHMS.iter().map(|a| (&**a).clone()).collect(),
|
||||
keys,
|
||||
@@ -780,10 +779,14 @@ impl ReadOnlyAccount {
|
||||
"keys": device_keys.keys,
|
||||
});
|
||||
|
||||
device_keys.signatures.entry(self.user_id().clone()).or_insert_with(BTreeMap::new).insert(
|
||||
DeviceKeyId::from_parts(DeviceKeyAlgorithm::Ed25519, &self.device_id),
|
||||
self.sign_json(json_device_keys).await,
|
||||
);
|
||||
device_keys
|
||||
.signatures
|
||||
.entry(self.user_id().to_owned())
|
||||
.or_insert_with(BTreeMap::new)
|
||||
.insert(
|
||||
DeviceKeyId::from_parts(DeviceKeyAlgorithm::Ed25519, &self.device_id),
|
||||
self.sign_json(json_device_keys).await,
|
||||
);
|
||||
|
||||
device_keys
|
||||
}
|
||||
@@ -850,7 +853,7 @@ impl ReadOnlyAccount {
|
||||
|
||||
pub(crate) async fn signed_one_time_keys_helper(
|
||||
&self,
|
||||
) -> Result<BTreeMap<DeviceKeyId, OneTimeKey>, ()> {
|
||||
) -> Result<BTreeMap<Box<DeviceKeyId>, OneTimeKey>, ()> {
|
||||
let one_time_keys = self.one_time_keys().await;
|
||||
let mut one_time_key_map = BTreeMap::new();
|
||||
|
||||
@@ -869,7 +872,7 @@ impl ReadOnlyAccount {
|
||||
);
|
||||
|
||||
let mut signatures = BTreeMap::new();
|
||||
signatures.insert((*self.user_id).clone(), signature_map);
|
||||
signatures.insert((*self.user_id).to_owned(), signature_map);
|
||||
|
||||
let signed_key = SignedKey::new(key.to_owned(), signatures);
|
||||
|
||||
@@ -890,7 +893,7 @@ impl ReadOnlyAccount {
|
||||
/// If no one-time keys need to be uploaded returns an empty error.
|
||||
pub(crate) async fn signed_one_time_keys(
|
||||
&self,
|
||||
) -> Result<BTreeMap<DeviceKeyId, OneTimeKey>, ()> {
|
||||
) -> Result<BTreeMap<Box<DeviceKeyId>, OneTimeKey>, ()> {
|
||||
let _ = self.generate_one_time_keys().await?;
|
||||
self.signed_one_time_keys_helper().await
|
||||
}
|
||||
@@ -945,7 +948,7 @@ impl ReadOnlyAccount {
|
||||
pub(crate) async fn create_outbound_session(
|
||||
&self,
|
||||
device: ReadOnlyDevice,
|
||||
key_map: &BTreeMap<DeviceKeyId, OneTimeKey>,
|
||||
key_map: &BTreeMap<Box<DeviceKeyId>, OneTimeKey>,
|
||||
) -> Result<Session, SessionCreationError> {
|
||||
let one_time_key = key_map.values().next().ok_or_else(|| {
|
||||
SessionCreationError::OneTimeKeyMissing(
|
||||
@@ -1152,25 +1155,25 @@ impl PartialEq for ReadOnlyAccount {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::collections::BTreeSet;
|
||||
use std::{collections::BTreeSet, ops::Deref};
|
||||
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::{identifiers::DeviceIdBox, user_id, DeviceKeyId, UserId};
|
||||
use ruma::{device_id, identifiers::DeviceId, user_id, DeviceKeyId, UserId};
|
||||
|
||||
use super::ReadOnlyAccount;
|
||||
use crate::error::OlmResult as Result;
|
||||
|
||||
fn user_id() -> UserId {
|
||||
fn user_id() -> &'static UserId {
|
||||
user_id!("@alice:localhost")
|
||||
}
|
||||
|
||||
fn device_id() -> DeviceIdBox {
|
||||
"DEVICEID".into()
|
||||
fn device_id() -> &'static DeviceId {
|
||||
device_id!("DEVICEID")
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn one_time_key_creation() -> Result<()> {
|
||||
let account = ReadOnlyAccount::new(&user_id(), &device_id());
|
||||
let account = ReadOnlyAccount::new(user_id(), device_id());
|
||||
|
||||
let one_time_keys = account
|
||||
.keys_for_upload()
|
||||
@@ -1184,8 +1187,10 @@ mod test {
|
||||
.and_then(|(_, k)| k)
|
||||
.expect("Second round of one-time keys isn't generated");
|
||||
|
||||
let device_key_ids: BTreeSet<&DeviceKeyId> = one_time_keys.keys().collect();
|
||||
let second_device_key_ids: BTreeSet<&DeviceKeyId> = second_one_time_keys.keys().collect();
|
||||
let device_key_ids: BTreeSet<&DeviceKeyId> =
|
||||
one_time_keys.keys().map(Deref::deref).collect();
|
||||
let second_device_key_ids: BTreeSet<&DeviceKeyId> =
|
||||
second_one_time_keys.keys().map(Deref::deref).collect();
|
||||
|
||||
assert_eq!(device_key_ids, second_device_key_ids);
|
||||
|
||||
@@ -1204,7 +1209,8 @@ mod test {
|
||||
.and_then(|(_, k)| k)
|
||||
.expect("Fourth round of one-time keys isn't generated");
|
||||
|
||||
let fourth_device_key_ids: BTreeSet<&DeviceKeyId> = fourth_one_time_keys.keys().collect();
|
||||
let fourth_device_key_ids: BTreeSet<&DeviceKeyId> =
|
||||
fourth_one_time_keys.keys().map(Deref::deref).collect();
|
||||
|
||||
assert_ne!(device_key_ids, fourth_device_key_ids);
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ impl InboundGroupSession {
|
||||
sender_key: sender_key.to_owned().into(),
|
||||
first_known_index,
|
||||
signing_keys: keys.into(),
|
||||
room_id: room_id.clone().into(),
|
||||
room_id: room_id.into(),
|
||||
forwarding_chains: Vec::new().into(),
|
||||
imported: false,
|
||||
backed_up: AtomicBool::new(false).into(),
|
||||
@@ -201,7 +201,7 @@ impl InboundGroupSession {
|
||||
pickle: InboundGroupSessionPickle::from(pickle),
|
||||
sender_key: self.sender_key.to_string(),
|
||||
signing_key: (&*self.signing_keys).clone(),
|
||||
room_id: (&*self.room_id).clone(),
|
||||
room_id: (&*self.room_id).to_owned(),
|
||||
forwarding_chains: self.forwarding_key_chain().to_vec(),
|
||||
imported: self.imported,
|
||||
backed_up: self.backed_up(),
|
||||
@@ -261,7 +261,7 @@ impl InboundGroupSession {
|
||||
|
||||
ExportedRoomKey {
|
||||
algorithm: EventEncryptionAlgorithm::MegolmV1AesSha2,
|
||||
room_id: (&*self.room_id).clone(),
|
||||
room_id: (&*self.room_id).to_owned(),
|
||||
sender_key: (&*self.sender_key).to_owned(),
|
||||
session_id: self.session_id().to_owned(),
|
||||
forwarding_curve25519_key_chain: self.forwarding_key_chain().to_vec(),
|
||||
@@ -365,11 +365,11 @@ impl InboundGroupSession {
|
||||
|
||||
let room_id = decrypted_object
|
||||
.get("room_id")
|
||||
.and_then(|r| r.as_str().and_then(|r| RoomId::try_from(r).ok()));
|
||||
.and_then(|r| r.as_str().and_then(|r| Box::<RoomId>::try_from(r).ok()));
|
||||
|
||||
// Check that we have a room id and that the event wasn't forwarded from
|
||||
// another room.
|
||||
if room_id.as_ref() != Some(self.room_id()) {
|
||||
if room_id.as_deref() != Some(self.room_id()) {
|
||||
return Err(EventError::MismatchedRoom(self.room_id().to_owned(), room_id).into());
|
||||
}
|
||||
|
||||
@@ -419,7 +419,7 @@ pub struct PickledInboundGroupSession {
|
||||
/// The public ed25519 key of the account that sent us the session.
|
||||
pub signing_key: BTreeMap<DeviceKeyAlgorithm, String>,
|
||||
/// The id of the room that the session is used in.
|
||||
pub room_id: RoomId,
|
||||
pub room_id: Box<RoomId>,
|
||||
/// The list of claimed ed25519 that forwarded us this key. Will be None if
|
||||
/// we directly received this session.
|
||||
#[serde(default)]
|
||||
|
||||
@@ -52,7 +52,7 @@ pub struct ExportedRoomKey {
|
||||
pub algorithm: EventEncryptionAlgorithm,
|
||||
|
||||
/// The room where the session is used.
|
||||
pub room_id: RoomId,
|
||||
pub room_id: Box<RoomId>,
|
||||
|
||||
/// The Curve25519 key of the device which initiated the session originally.
|
||||
pub sender_key: String,
|
||||
@@ -166,7 +166,7 @@ mod test {
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use ruma::{events::room::message::RoomMessageEventContent, room_id, user_id};
|
||||
use ruma::{device_id, events::room::message::RoomMessageEventContent, room_id, user_id};
|
||||
|
||||
use super::EncryptionSettings;
|
||||
use crate::{MegolmError, ReadOnlyAccount};
|
||||
@@ -176,9 +176,9 @@ mod test {
|
||||
async fn expiration() -> Result<(), MegolmError> {
|
||||
let settings = EncryptionSettings { rotation_period_msgs: 1, ..Default::default() };
|
||||
|
||||
let account = ReadOnlyAccount::new(&user_id!("@alice:example.org"), "DEVICEID".into());
|
||||
let account = ReadOnlyAccount::new(user_id!("@alice:example.org"), device_id!("DEVICEID"));
|
||||
let (session, _) = account
|
||||
.create_group_session_pair(&room_id!("!test_room:example.org"), settings)
|
||||
.create_group_session_pair(room_id!("!test_room:example.org"), settings)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -197,7 +197,7 @@ mod test {
|
||||
};
|
||||
|
||||
let (mut session, _) = account
|
||||
.create_group_session_pair(&room_id!("!test_room:example.org"), settings)
|
||||
.create_group_session_pair(room_id!("!test_room:example.org"), settings)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ use ruma::{
|
||||
room_key::ToDeviceRoomKeyEventContent,
|
||||
AnyToDeviceEventContent,
|
||||
},
|
||||
DeviceId, DeviceIdBox, DeviceKeyAlgorithm, EventEncryptionAlgorithm, RoomId, UserId,
|
||||
DeviceId, DeviceKeyAlgorithm, EventEncryptionAlgorithm, RoomId, UserId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{json, Value};
|
||||
@@ -128,7 +128,8 @@ pub struct OutboundGroupSession {
|
||||
shared: Arc<AtomicBool>,
|
||||
invalidated: Arc<AtomicBool>,
|
||||
settings: Arc<EncryptionSettings>,
|
||||
pub(crate) shared_with_set: Arc<DashMap<UserId, DashMap<DeviceIdBox, ShareInfo>>>,
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub(crate) shared_with_set: Arc<DashMap<Box<UserId>, DashMap<Box<DeviceId>, ShareInfo>>>,
|
||||
to_share_with_set: Arc<DashMap<Uuid, (Arc<ToDeviceRequest>, ShareInfoSet)>>,
|
||||
}
|
||||
|
||||
@@ -136,7 +137,7 @@ pub struct OutboundGroupSession {
|
||||
///
|
||||
/// Holds the `ShareInfo` for all the user/device pairs that will receive the
|
||||
/// room key.
|
||||
pub type ShareInfoSet = BTreeMap<UserId, BTreeMap<DeviceIdBox, ShareInfo>>;
|
||||
pub type ShareInfoSet = BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, ShareInfo>>;
|
||||
|
||||
/// Struct holding info about the share state of a outbound group session.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
@@ -174,7 +175,7 @@ impl OutboundGroupSession {
|
||||
|
||||
OutboundGroupSession {
|
||||
inner: Arc::new(Mutex::new(session)),
|
||||
room_id: Arc::new(room_id.to_owned()),
|
||||
room_id: room_id.into(),
|
||||
device_id,
|
||||
account_identity_keys: identity_keys,
|
||||
session_id: session_id.into(),
|
||||
@@ -214,7 +215,7 @@ impl OutboundGroupSession {
|
||||
pub fn mark_request_as_sent(&self, request_id: &Uuid) {
|
||||
if let Some((_, (_, r))) = self.to_share_with_set.remove(request_id) {
|
||||
let recipients: BTreeMap<&UserId, BTreeSet<&DeviceId>> =
|
||||
r.iter().map(|(u, d)| (u, d.keys().map(|d| d.as_ref()).collect())).collect();
|
||||
r.iter().map(|(u, d)| (&**u, d.keys().map(|d| d.as_ref()).collect())).collect();
|
||||
|
||||
info!(
|
||||
?request_id,
|
||||
@@ -589,7 +590,7 @@ pub struct PickledOutboundGroupSession {
|
||||
/// Has the session been invalidated.
|
||||
pub invalidated: bool,
|
||||
/// The set of users the session has been already shared with.
|
||||
pub shared_with_set: BTreeMap<UserId, BTreeMap<DeviceIdBox, ShareInfo>>,
|
||||
pub shared_with_set: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, ShareInfo>>,
|
||||
/// Requests that need to be sent out to share the session.
|
||||
pub requests: BTreeMap<Uuid, (Arc<ToDeviceRequest>, ShareInfoSet)>,
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@ pub(crate) mod test {
|
||||
use matches::assert_matches;
|
||||
use olm_rs::session::OlmMessage;
|
||||
use ruma::{
|
||||
device_id,
|
||||
encryption::SignedKey,
|
||||
event_id,
|
||||
events::{
|
||||
@@ -80,25 +81,25 @@ pub(crate) mod test {
|
||||
MegolmError,
|
||||
};
|
||||
|
||||
fn alice_id() -> UserId {
|
||||
fn alice_id() -> &'static UserId {
|
||||
user_id!("@alice:example.org")
|
||||
}
|
||||
|
||||
fn alice_device_id() -> Box<DeviceId> {
|
||||
"ALICEDEVICE".into()
|
||||
fn alice_device_id() -> &'static DeviceId {
|
||||
device_id!("ALICEDEVICE")
|
||||
}
|
||||
|
||||
fn bob_id() -> UserId {
|
||||
fn bob_id() -> &'static UserId {
|
||||
user_id!("@bob:example.org")
|
||||
}
|
||||
|
||||
fn bob_device_id() -> Box<DeviceId> {
|
||||
"BOBDEVICE".into()
|
||||
fn bob_device_id() -> &'static DeviceId {
|
||||
device_id!("BOBDEVICE")
|
||||
}
|
||||
|
||||
pub(crate) async fn get_account_and_session() -> (ReadOnlyAccount, Session) {
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let bob = ReadOnlyAccount::new(&bob_id(), &bob_device_id());
|
||||
let alice = ReadOnlyAccount::new(alice_id(), alice_device_id());
|
||||
let bob = ReadOnlyAccount::new(bob_id(), bob_device_id());
|
||||
|
||||
bob.generate_one_time_keys_helper(1).await;
|
||||
let one_time_key =
|
||||
@@ -113,7 +114,7 @@ pub(crate) mod test {
|
||||
|
||||
#[test]
|
||||
fn account_creation() {
|
||||
let account = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let account = ReadOnlyAccount::new(alice_id(), alice_device_id());
|
||||
let identity_keys = account.identity_keys();
|
||||
|
||||
assert!(!account.shared());
|
||||
@@ -131,7 +132,7 @@ pub(crate) mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn one_time_keys_creation() {
|
||||
let account = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let account = ReadOnlyAccount::new(alice_id(), alice_device_id());
|
||||
let one_time_keys = account.one_time_keys().await;
|
||||
|
||||
assert!(one_time_keys.curve25519().is_empty());
|
||||
@@ -155,8 +156,8 @@ pub(crate) mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn session_creation() {
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let bob = ReadOnlyAccount::new(&bob_id(), &bob_device_id());
|
||||
let alice = ReadOnlyAccount::new(alice_id(), alice_device_id());
|
||||
let bob = ReadOnlyAccount::new(bob_id(), bob_device_id());
|
||||
let alice_keys = alice.identity_keys();
|
||||
alice.generate_one_time_keys_helper(1).await;
|
||||
let one_time_keys = alice.one_time_keys().await;
|
||||
@@ -196,10 +197,10 @@ pub(crate) mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn group_session_creation() {
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let alice = ReadOnlyAccount::new(alice_id(), alice_device_id());
|
||||
let room_id = room_id!("!test:localhost");
|
||||
|
||||
let (outbound, _) = alice.create_group_session_pair_with_defaults(&room_id).await.unwrap();
|
||||
let (outbound, _) = alice.create_group_session_pair_with_defaults(room_id).await.unwrap();
|
||||
|
||||
assert_eq!(0, outbound.message_index().await);
|
||||
assert!(!outbound.shared());
|
||||
@@ -209,7 +210,7 @@ pub(crate) mod test {
|
||||
let inbound = InboundGroupSession::new(
|
||||
"test_key",
|
||||
"test_key",
|
||||
&room_id,
|
||||
room_id,
|
||||
outbound.session_key().await,
|
||||
None,
|
||||
)
|
||||
@@ -227,11 +228,11 @@ pub(crate) mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn edit_decryption() -> Result<(), MegolmError> {
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let alice = ReadOnlyAccount::new(alice_id(), alice_device_id());
|
||||
let room_id = room_id!("!test:localhost");
|
||||
let event_id = event_id!("$1234adfad:asdf");
|
||||
|
||||
let (outbound, _) = alice.create_group_session_pair_with_defaults(&room_id).await.unwrap();
|
||||
let (outbound, _) = alice.create_group_session_pair_with_defaults(room_id).await.unwrap();
|
||||
|
||||
assert_eq!(0, outbound.message_index().await);
|
||||
assert!(!outbound.shared());
|
||||
@@ -240,14 +241,14 @@ pub(crate) mod test {
|
||||
|
||||
let mut content = RoomMessageEventContent::text_plain("Hello");
|
||||
content.relates_to = Some(Relation::Replacement(Replacement::new(
|
||||
event_id.clone(),
|
||||
event_id.to_owned(),
|
||||
RoomMessageEventContent::text_plain("Hello edit").into(),
|
||||
)));
|
||||
|
||||
let inbound = InboundGroupSession::new(
|
||||
"test_key",
|
||||
"test_key",
|
||||
&room_id,
|
||||
room_id,
|
||||
outbound.session_key().await,
|
||||
None,
|
||||
)?;
|
||||
@@ -293,10 +294,10 @@ pub(crate) mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn group_session_export() {
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let alice = ReadOnlyAccount::new(alice_id(), alice_device_id());
|
||||
let room_id = room_id!("!test:localhost");
|
||||
|
||||
let (_, inbound) = alice.create_group_session_pair_with_defaults(&room_id).await.unwrap();
|
||||
let (_, inbound) = alice.create_group_session_pair_with_defaults(room_id).await.unwrap();
|
||||
|
||||
let export = inbound.export().await;
|
||||
let export: ToDeviceForwardedRoomKeyEventContent = export.try_into().unwrap();
|
||||
|
||||
@@ -87,7 +87,7 @@ impl ClearResult {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PickledCrossSigningIdentity {
|
||||
/// The user id of the identity owner.
|
||||
pub user_id: UserId,
|
||||
pub user_id: Box<UserId>,
|
||||
/// Have the public keys of the identity been shared.
|
||||
pub shared: bool,
|
||||
/// The encrypted pickle of the identity.
|
||||
@@ -220,7 +220,7 @@ impl PrivateCrossSigningIdentity {
|
||||
let master = if let Some(master_key) = master_key {
|
||||
let seed = decode(master_key)?;
|
||||
|
||||
let master = MasterSigning::from_seed(self.user_id().clone(), seed);
|
||||
let master = MasterSigning::from_seed(self.user_id().to_owned(), seed);
|
||||
|
||||
if public_identity.master_key() == &master.public_key {
|
||||
Ok(Some(master))
|
||||
@@ -233,7 +233,7 @@ impl PrivateCrossSigningIdentity {
|
||||
|
||||
let user_signing = if let Some(user_signing_key) = user_signing_key {
|
||||
let seed = decode(user_signing_key)?;
|
||||
let subkey = UserSigning::from_seed(self.user_id().clone(), seed);
|
||||
let subkey = UserSigning::from_seed(self.user_id().to_owned(), seed);
|
||||
|
||||
if public_identity.user_signing_key() == &subkey.public_key {
|
||||
Ok(Some(subkey))
|
||||
@@ -246,7 +246,7 @@ impl PrivateCrossSigningIdentity {
|
||||
|
||||
let self_signing = if let Some(self_signing_key) = self_signing_key {
|
||||
let seed = decode(self_signing_key)?;
|
||||
let subkey = SelfSigning::from_seed(self.user_id().clone(), seed);
|
||||
let subkey = SelfSigning::from_seed(self.user_id().to_owned(), seed);
|
||||
|
||||
if public_identity.self_signing_key() == &subkey.public_key {
|
||||
Ok(Some(subkey))
|
||||
@@ -344,9 +344,9 @@ impl PrivateCrossSigningIdentity {
|
||||
}
|
||||
|
||||
/// Create a new empty identity.
|
||||
pub(crate) fn empty(user_id: UserId) -> Self {
|
||||
pub(crate) fn empty(user_id: Box<UserId>) -> Self {
|
||||
Self {
|
||||
user_id: Arc::new(user_id),
|
||||
user_id: user_id.into(),
|
||||
shared: Arc::new(AtomicBool::new(false)),
|
||||
master_key: Arc::new(Mutex::new(None)),
|
||||
self_signing_key: Arc::new(Mutex::new(None)),
|
||||
@@ -521,7 +521,7 @@ impl PrivateCrossSigningIdentity {
|
||||
let self_signing = SelfSigning { inner: self_signing, public_key: public_key.into() };
|
||||
|
||||
Self {
|
||||
user_id: Arc::new(user_id.to_owned()),
|
||||
user_id: user_id.into(),
|
||||
shared: Arc::new(AtomicBool::new(false)),
|
||||
master_key: Arc::new(Mutex::new(Some(master))),
|
||||
self_signing_key: Arc::new(Mutex::new(Some(self_signing))),
|
||||
@@ -532,7 +532,7 @@ impl PrivateCrossSigningIdentity {
|
||||
/// Create a new cross signing identity without signing the device that
|
||||
/// created it.
|
||||
#[cfg(test)]
|
||||
pub(crate) async fn new(user_id: UserId) -> Self {
|
||||
pub(crate) async fn new(user_id: Box<UserId>) -> Self {
|
||||
let master = Signing::new();
|
||||
|
||||
let public_key = master.cross_signing_key(user_id.clone(), KeyUsage::Master);
|
||||
@@ -628,7 +628,7 @@ impl PrivateCrossSigningIdentity {
|
||||
.transpose()?;
|
||||
|
||||
Ok(Self {
|
||||
user_id: Arc::new(pickle.user_id),
|
||||
user_id: pickle.user_id.into(),
|
||||
shared: Arc::new(AtomicBool::from(pickle.shared)),
|
||||
master_key: Arc::new(Mutex::new(master)),
|
||||
self_signing_key: Arc::new(Mutex::new(self_signing)),
|
||||
@@ -655,7 +655,7 @@ impl PrivateCrossSigningIdentity {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::{user_id, UserId};
|
||||
use ruma::{device_id, user_id, UserId};
|
||||
|
||||
use super::{PrivateCrossSigningIdentity, Signing};
|
||||
use crate::{
|
||||
@@ -663,7 +663,7 @@ mod test {
|
||||
olm::ReadOnlyAccount,
|
||||
};
|
||||
|
||||
fn user_id() -> UserId {
|
||||
fn user_id() -> &'static UserId {
|
||||
user_id!("@example:localhost")
|
||||
}
|
||||
|
||||
@@ -699,7 +699,7 @@ mod test {
|
||||
|
||||
#[async_test]
|
||||
async fn private_identity_creation() {
|
||||
let identity = PrivateCrossSigningIdentity::new(user_id()).await;
|
||||
let identity = PrivateCrossSigningIdentity::new(user_id().to_owned()).await;
|
||||
|
||||
let master_key = identity.master_key.lock().await;
|
||||
let master_key = master_key.as_ref().unwrap();
|
||||
@@ -717,7 +717,7 @@ mod test {
|
||||
|
||||
#[async_test]
|
||||
async fn identity_pickling() {
|
||||
let identity = PrivateCrossSigningIdentity::new(user_id()).await;
|
||||
let identity = PrivateCrossSigningIdentity::new(user_id().to_owned()).await;
|
||||
|
||||
let pickled = identity.pickle(pickle_key()).await.unwrap();
|
||||
|
||||
@@ -738,7 +738,7 @@ mod test {
|
||||
|
||||
#[async_test]
|
||||
async fn private_identity_signed_by_account() {
|
||||
let account = ReadOnlyAccount::new(&user_id(), "DEVICEID".into());
|
||||
let account = ReadOnlyAccount::new(user_id(), device_id!("DEVICEID"));
|
||||
let (identity, _, _) = PrivateCrossSigningIdentity::new_with_account(&account).await;
|
||||
let master = identity.master_key.lock().await;
|
||||
let master = master.as_ref().unwrap();
|
||||
@@ -748,7 +748,7 @@ mod test {
|
||||
|
||||
#[async_test]
|
||||
async fn sign_device() {
|
||||
let account = ReadOnlyAccount::new(&user_id(), "DEVICEID".into());
|
||||
let account = ReadOnlyAccount::new(user_id(), device_id!("DEVICEID"));
|
||||
let (identity, _, _) = PrivateCrossSigningIdentity::new_with_account(&account).await;
|
||||
|
||||
let mut device = ReadOnlyDevice::from_account(&account).await;
|
||||
@@ -765,10 +765,10 @@ mod test {
|
||||
|
||||
#[async_test]
|
||||
async fn sign_user_identity() {
|
||||
let account = ReadOnlyAccount::new(&user_id(), "DEVICEID".into());
|
||||
let account = ReadOnlyAccount::new(user_id(), device_id!("DEVICEID"));
|
||||
let (identity, _, _) = PrivateCrossSigningIdentity::new_with_account(&account).await;
|
||||
|
||||
let bob_account = ReadOnlyAccount::new(&user_id!("@bob:localhost"), "DEVICEID".into());
|
||||
let bob_account = ReadOnlyAccount::new(user_id!("@bob:localhost"), device_id!("DEVICEID"));
|
||||
let (bob_private, _, _) = PrivateCrossSigningIdentity::new_with_account(&bob_account).await;
|
||||
let mut bob_public = ReadOnlyUserIdentity::from_private(&bob_private).await;
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ impl MasterSigning {
|
||||
encode(self.inner.seed.as_slice())
|
||||
}
|
||||
|
||||
pub fn from_seed(user_id: UserId, seed: Vec<u8>) -> Self {
|
||||
pub fn from_seed(user_id: Box<UserId>, seed: Vec<u8>) -> Self {
|
||||
let inner = Signing::from_seed(seed);
|
||||
let public_key = inner.cross_signing_key(user_id, KeyUsage::Master).into();
|
||||
|
||||
@@ -196,7 +196,7 @@ impl UserSigning {
|
||||
encode(self.inner.seed.as_slice())
|
||||
}
|
||||
|
||||
pub fn from_seed(user_id: UserId, seed: Vec<u8>) -> Self {
|
||||
pub fn from_seed(user_id: Box<UserId>, seed: Vec<u8>) -> Self {
|
||||
let inner = Signing::from_seed(seed);
|
||||
let public_key = inner.cross_signing_key(user_id, KeyUsage::UserSigning).into();
|
||||
|
||||
@@ -260,7 +260,7 @@ impl SelfSigning {
|
||||
encode(self.inner.seed.as_slice())
|
||||
}
|
||||
|
||||
pub fn from_seed(user_id: UserId, seed: Vec<u8>) -> Self {
|
||||
pub fn from_seed(user_id: Box<UserId>, seed: Vec<u8>) -> Self {
|
||||
let inner = Signing::from_seed(seed);
|
||||
let public_key = inner.cross_signing_key(user_id, KeyUsage::SelfSigning).into();
|
||||
|
||||
@@ -387,7 +387,7 @@ impl Signing {
|
||||
&self.public_key
|
||||
}
|
||||
|
||||
pub fn cross_signing_key(&self, user_id: UserId, usage: KeyUsage) -> CrossSigningKey {
|
||||
pub fn cross_signing_key(&self, user_id: Box<UserId>, usage: KeyUsage) -> CrossSigningKey {
|
||||
let keys = BTreeMap::from([(
|
||||
DeviceKeyId::from_parts(DeviceKeyAlgorithm::Ed25519, self.public_key().as_str().into())
|
||||
.to_string(),
|
||||
|
||||
@@ -95,7 +95,7 @@ impl Utility {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use ruma::{user_id, DeviceKeyAlgorithm, DeviceKeyId};
|
||||
use ruma::{device_id, user_id, DeviceKeyAlgorithm, DeviceKeyId};
|
||||
use serde_json::json;
|
||||
|
||||
use super::Utility;
|
||||
@@ -129,8 +129,8 @@ mod test {
|
||||
|
||||
utility
|
||||
.verify_json(
|
||||
&user_id!("@example:localhost"),
|
||||
&DeviceKeyId::from_parts(DeviceKeyAlgorithm::Ed25519, "GBEWHQOYGS".into()),
|
||||
user_id!("@example:localhost"),
|
||||
&DeviceKeyId::from_parts(DeviceKeyAlgorithm::Ed25519, device_id!("GBEWHQOYGS")),
|
||||
signing_key,
|
||||
&mut device_keys,
|
||||
)
|
||||
|
||||
@@ -34,7 +34,7 @@ use ruma::{
|
||||
events::{AnyMessageEventContent, AnyToDeviceEventContent, EventContent, EventType},
|
||||
serde::Raw,
|
||||
to_device::DeviceIdOrAllDevices,
|
||||
DeviceIdBox, RoomId, UserId,
|
||||
DeviceId, RoomId, UserId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -56,7 +56,8 @@ pub struct ToDeviceRequest {
|
||||
/// The content's type for this field will be updated in a future
|
||||
/// release, until then you can create a value using
|
||||
/// `serde_json::value::to_raw_value`.
|
||||
pub messages: BTreeMap<UserId, BTreeMap<DeviceIdOrAllDevices, Raw<AnyToDeviceEventContent>>>,
|
||||
pub messages:
|
||||
BTreeMap<Box<UserId>, BTreeMap<DeviceIdOrAllDevices, Raw<AnyToDeviceEventContent>>>,
|
||||
}
|
||||
|
||||
impl ToDeviceRequest {
|
||||
@@ -81,7 +82,7 @@ impl ToDeviceRequest {
|
||||
|
||||
pub(crate) fn new_for_recipients(
|
||||
recipient: &UserId,
|
||||
recipient_devices: Vec<DeviceIdBox>,
|
||||
recipient_devices: Vec<Box<DeviceId>>,
|
||||
content: AnyToDeviceEventContent,
|
||||
txn_id: Uuid,
|
||||
) -> Self {
|
||||
@@ -113,7 +114,7 @@ impl ToDeviceRequest {
|
||||
let raw_content = Raw::new(&content).expect("Failed to serialize to-device event");
|
||||
|
||||
let user_messages = iter::once((recipient_device.into(), raw_content)).collect();
|
||||
let messages = iter::once((recipient.clone(), user_messages)).collect();
|
||||
let messages = iter::once((recipient.to_owned(), user_messages)).collect();
|
||||
|
||||
ToDeviceRequest { event_type, txn_id, messages }
|
||||
}
|
||||
@@ -160,7 +161,7 @@ pub struct KeysQueryRequest {
|
||||
|
||||
/// The keys to be downloaded. An empty list indicates all devices for
|
||||
/// the corresponding user.
|
||||
pub device_keys: BTreeMap<UserId, Vec<DeviceIdBox>>,
|
||||
pub device_keys: BTreeMap<Box<UserId>, Vec<Box<DeviceId>>>,
|
||||
|
||||
/// If the client is fetching keys as a result of a device update
|
||||
/// received in a sync request, this should be the 'since' token of that
|
||||
@@ -171,7 +172,7 @@ pub struct KeysQueryRequest {
|
||||
}
|
||||
|
||||
impl KeysQueryRequest {
|
||||
pub(crate) fn new(device_keys: BTreeMap<UserId, Vec<DeviceIdBox>>) -> Self {
|
||||
pub(crate) fn new(device_keys: BTreeMap<Box<UserId>, Vec<Box<DeviceId>>>) -> Self {
|
||||
Self { timeout: None, device_keys, token: None }
|
||||
}
|
||||
}
|
||||
@@ -360,7 +361,7 @@ impl OutgoingRequest {
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RoomMessageRequest {
|
||||
/// The room to send the event to.
|
||||
pub room_id: RoomId,
|
||||
pub room_id: Box<RoomId>,
|
||||
|
||||
/// The transaction ID for this event.
|
||||
///
|
||||
@@ -380,7 +381,7 @@ pub struct KeysBackupRequest {
|
||||
pub version: String,
|
||||
/// The map from room id to a backed up room key that we're going to upload
|
||||
/// to the server.
|
||||
pub rooms: BTreeMap<RoomId, RoomKeyBackup>,
|
||||
pub rooms: BTreeMap<Box<RoomId>, RoomKeyBackup>,
|
||||
}
|
||||
|
||||
/// An enum over the different outgoing verification based requests.
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
|
||||
ops::Deref,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
@@ -27,7 +28,7 @@ use ruma::{
|
||||
},
|
||||
serde::Raw,
|
||||
to_device::DeviceIdOrAllDevices,
|
||||
DeviceId, DeviceIdBox, RoomId, UserId,
|
||||
DeviceId, RoomId, UserId,
|
||||
};
|
||||
use serde_json::Value;
|
||||
use tracing::{debug, info, trace};
|
||||
@@ -42,7 +43,7 @@ use crate::{
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct GroupSessionCache {
|
||||
store: Store,
|
||||
sessions: Arc<DashMap<RoomId, OutboundGroupSession>>,
|
||||
sessions: Arc<DashMap<Box<RoomId>, OutboundGroupSession>>,
|
||||
/// A map from the request id to the group session that the request belongs
|
||||
/// to. Used to mark requests belonging to the session as shared.
|
||||
sessions_being_shared: Arc<DashMap<Uuid, OutboundGroupSession>>,
|
||||
@@ -73,7 +74,7 @@ impl GroupSessionCache {
|
||||
self.sessions_being_shared.insert(request_id, s.clone());
|
||||
}
|
||||
|
||||
self.sessions.insert(room_id.clone(), s.clone());
|
||||
self.sessions.insert(room_id.to_owned(), s.clone());
|
||||
|
||||
Ok(Some(s))
|
||||
} else {
|
||||
@@ -222,7 +223,7 @@ impl GroupSessionManager {
|
||||
) -> OlmResult<(
|
||||
Uuid,
|
||||
ToDeviceRequest,
|
||||
BTreeMap<UserId, BTreeMap<DeviceIdBox, ShareInfo>>,
|
||||
BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, ShareInfo>>,
|
||||
Vec<Session>,
|
||||
)> {
|
||||
let mut messages = BTreeMap::new();
|
||||
@@ -312,9 +313,9 @@ impl GroupSessionManager {
|
||||
users: impl Iterator<Item = &UserId>,
|
||||
history_visibility: HistoryVisibility,
|
||||
outbound: &OutboundGroupSession,
|
||||
) -> OlmResult<(bool, HashMap<UserId, Vec<Device>>)> {
|
||||
) -> OlmResult<(bool, HashMap<Box<UserId>, Vec<Device>>)> {
|
||||
let users: HashSet<&UserId> = users.collect();
|
||||
let mut devices: HashMap<UserId, Vec<Device>> = HashMap::new();
|
||||
let mut devices: HashMap<Box<UserId>, Vec<Device>> = HashMap::new();
|
||||
|
||||
trace!(
|
||||
users = ?users,
|
||||
@@ -324,10 +325,11 @@ impl GroupSessionManager {
|
||||
"Calculating group session recipients"
|
||||
);
|
||||
|
||||
let users_shared_with: HashSet<UserId> =
|
||||
let users_shared_with: HashSet<Box<UserId>> =
|
||||
outbound.shared_with_set.iter().map(|k| k.key().clone()).collect();
|
||||
|
||||
let users_shared_with: HashSet<&UserId> = users_shared_with.iter().collect();
|
||||
let users_shared_with: HashSet<&UserId> =
|
||||
users_shared_with.iter().map(Deref::deref).collect();
|
||||
|
||||
// A user left if a user is missing from the set of users that should
|
||||
// get the session but is in the set of users that received the session.
|
||||
@@ -360,7 +362,7 @@ impl GroupSessionManager {
|
||||
|
||||
if let Some(shared) = outbound.shared_with_set.get(user_id) {
|
||||
// Devices that received this session
|
||||
let shared: HashSet<DeviceIdBox> =
|
||||
let shared: HashSet<Box<DeviceId>> =
|
||||
shared.iter().map(|d| d.key().clone()).collect();
|
||||
let shared: HashSet<&DeviceId> = shared.iter().map(|d| d.as_ref()).collect();
|
||||
|
||||
@@ -380,7 +382,10 @@ impl GroupSessionManager {
|
||||
};
|
||||
}
|
||||
|
||||
devices.entry(user_id.clone()).or_insert_with(Vec::new).extend(non_blacklisted_devices);
|
||||
devices
|
||||
.entry(user_id.to_owned())
|
||||
.or_insert_with(Vec::new)
|
||||
.extend(non_blacklisted_devices);
|
||||
}
|
||||
|
||||
trace!(
|
||||
@@ -572,6 +577,8 @@ impl GroupSessionManager {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::ops::Deref;
|
||||
|
||||
use matrix_sdk_common::uuid::Uuid;
|
||||
use matrix_sdk_test::response_from_file;
|
||||
use ruma::{
|
||||
@@ -579,18 +586,18 @@ mod test {
|
||||
client::r0::keys::{claim_keys, get_keys},
|
||||
IncomingResponse,
|
||||
},
|
||||
room_id, user_id, DeviceIdBox, UserId,
|
||||
device_id, room_id, user_id, DeviceId, UserId,
|
||||
};
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::{EncryptionSettings, OlmMachine};
|
||||
|
||||
fn alice_id() -> UserId {
|
||||
fn alice_id() -> &'static UserId {
|
||||
user_id!("@alice:example.org")
|
||||
}
|
||||
|
||||
fn alice_device_id() -> DeviceIdBox {
|
||||
"JLAFKJWSCS".into()
|
||||
fn alice_device_id() -> &'static DeviceId {
|
||||
device_id!("JLAFKJWSCS")
|
||||
}
|
||||
|
||||
fn keys_query_response() -> get_keys::Response {
|
||||
@@ -614,7 +621,7 @@ mod test {
|
||||
let keys_claim = keys_claim_response();
|
||||
let uuid = Uuid::new_v4();
|
||||
|
||||
let machine = OlmMachine::new(&alice_id(), &alice_device_id());
|
||||
let machine = OlmMachine::new(alice_id(), alice_device_id());
|
||||
|
||||
machine.mark_request_as_sent(&uuid, &keys_query).await.unwrap();
|
||||
machine.mark_request_as_sent(&uuid, &keys_claim).await.unwrap();
|
||||
@@ -628,10 +635,10 @@ mod test {
|
||||
let room_id = room_id!("!test:localhost");
|
||||
let keys_claim = keys_claim_response();
|
||||
|
||||
let users: Vec<_> = keys_claim.one_time_keys.keys().collect();
|
||||
let users = keys_claim.one_time_keys.keys().map(Deref::deref);
|
||||
|
||||
let requests = machine
|
||||
.share_group_session(&room_id, users.clone().into_iter(), EncryptionSettings::default())
|
||||
.share_group_session(room_id, users, EncryptionSettings::default())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ use ruma::{
|
||||
},
|
||||
assign,
|
||||
events::{dummy::ToDeviceDummyEventContent, AnyToDeviceEventContent},
|
||||
DeviceId, DeviceIdBox, DeviceKeyAlgorithm, EventEncryptionAlgorithm, UserId,
|
||||
DeviceId, DeviceKeyAlgorithm, EventEncryptionAlgorithm, UserId,
|
||||
};
|
||||
use tracing::{debug, error, info, warn};
|
||||
|
||||
@@ -47,8 +47,8 @@ pub(crate) struct SessionManager {
|
||||
/// Submodules can insert user/device pairs into this map and the
|
||||
/// user/device paris will be added to the list of users when
|
||||
/// [`get_missing_sessions`](#method.get_missing_sessions) is called.
|
||||
users_for_key_claim: Arc<DashMap<UserId, DashSet<DeviceIdBox>>>,
|
||||
wedged_devices: Arc<DashMap<UserId, DashSet<DeviceIdBox>>>,
|
||||
users_for_key_claim: Arc<DashMap<Box<UserId>, DashSet<Box<DeviceId>>>>,
|
||||
wedged_devices: Arc<DashMap<Box<UserId>, DashSet<Box<DeviceId>>>>,
|
||||
key_request_machine: GossipMachine,
|
||||
outgoing_to_device_requests: Arc<DashMap<Uuid, OutgoingRequest>>,
|
||||
}
|
||||
@@ -59,7 +59,7 @@ impl SessionManager {
|
||||
|
||||
pub fn new(
|
||||
account: Account,
|
||||
users_for_key_claim: Arc<DashMap<UserId, DashSet<DeviceIdBox>>>,
|
||||
users_for_key_claim: Arc<DashMap<Box<UserId>, DashSet<Box<DeviceId>>>>,
|
||||
key_request_machine: GossipMachine,
|
||||
store: Store,
|
||||
) -> Self {
|
||||
@@ -97,7 +97,7 @@ impl SessionManager {
|
||||
|
||||
if session.creation_time.elapsed() > Self::UNWEDGING_INTERVAL {
|
||||
self.users_for_key_claim
|
||||
.entry(device.user_id().clone())
|
||||
.entry(device.user_id().to_owned())
|
||||
.or_insert_with(DashSet::new)
|
||||
.insert(device.device_id().into());
|
||||
self.wedged_devices
|
||||
@@ -333,14 +333,14 @@ impl SessionManager {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::{collections::BTreeMap, sync::Arc};
|
||||
use std::{collections::BTreeMap, iter, sync::Arc};
|
||||
|
||||
use dashmap::DashMap;
|
||||
use matrix_sdk_common::locks::Mutex;
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::{
|
||||
api::client::r0::keys::claim_keys::Response as KeyClaimResponse, user_id, DeviceIdBox,
|
||||
UserId,
|
||||
api::client::r0::keys::claim_keys::Response as KeyClaimResponse, device_id, user_id,
|
||||
DeviceId, UserId,
|
||||
};
|
||||
|
||||
use super::SessionManager;
|
||||
@@ -353,31 +353,31 @@ mod test {
|
||||
verification::VerificationMachine,
|
||||
};
|
||||
|
||||
fn user_id() -> UserId {
|
||||
fn user_id() -> &'static UserId {
|
||||
user_id!("@example:localhost")
|
||||
}
|
||||
|
||||
fn device_id() -> DeviceIdBox {
|
||||
"DEVICEID".into()
|
||||
fn device_id() -> &'static DeviceId {
|
||||
device_id!("DEVICEID")
|
||||
}
|
||||
|
||||
fn bob_account() -> ReadOnlyAccount {
|
||||
ReadOnlyAccount::new(&user_id!("@bob:localhost"), "BOBDEVICE".into())
|
||||
ReadOnlyAccount::new(user_id!("@bob:localhost"), device_id!("BOBDEVICE"))
|
||||
}
|
||||
|
||||
async fn session_manager() -> SessionManager {
|
||||
let user_id = user_id();
|
||||
let user_id = user_id().to_owned();
|
||||
let device_id = device_id();
|
||||
|
||||
let users_for_key_claim = Arc::new(DashMap::new());
|
||||
let account = ReadOnlyAccount::new(&user_id, &device_id);
|
||||
let account = ReadOnlyAccount::new(&user_id, device_id);
|
||||
let store: Arc<dyn CryptoStore> = Arc::new(MemoryStore::new());
|
||||
store.save_account(account.clone()).await.unwrap();
|
||||
let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(user_id.clone())));
|
||||
let verification =
|
||||
VerificationMachine::new(account.clone(), identity.clone(), store.clone());
|
||||
|
||||
let user_id = Arc::new(user_id);
|
||||
let user_id: Arc<UserId> = user_id.into();
|
||||
let device_id = device_id.into();
|
||||
|
||||
let store = Store::new(user_id.clone(), identity, store, verification);
|
||||
@@ -406,11 +406,8 @@ mod test {
|
||||
|
||||
manager.store.save_devices(&[bob_device]).await.unwrap();
|
||||
|
||||
let (_, request) = manager
|
||||
.get_missing_sessions(&mut [bob.user_id().clone()].iter())
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let (_, request) =
|
||||
manager.get_missing_sessions(iter::once(bob.user_id())).await.unwrap().unwrap();
|
||||
|
||||
assert!(request.one_time_keys.contains_key(bob.user_id()));
|
||||
|
||||
@@ -420,19 +417,15 @@ mod test {
|
||||
|
||||
let mut one_time_keys = BTreeMap::new();
|
||||
one_time_keys
|
||||
.entry(bob.user_id().clone())
|
||||
.entry(bob.user_id().to_owned())
|
||||
.or_insert_with(BTreeMap::new)
|
||||
.insert(bob.device_id().into(), one_time);
|
||||
.insert(bob.device_id().to_owned(), one_time);
|
||||
|
||||
let response = KeyClaimResponse::new(one_time_keys);
|
||||
|
||||
manager.receive_keys_claim_response(&response).await.unwrap();
|
||||
|
||||
assert!(manager
|
||||
.get_missing_sessions(&mut [bob.user_id().clone()].iter())
|
||||
.await
|
||||
.unwrap()
|
||||
.is_none());
|
||||
assert!(manager.get_missing_sessions(iter::once(bob.user_id())).await.unwrap().is_none());
|
||||
}
|
||||
|
||||
// This test doesn't run on macos because we're modifying the session
|
||||
@@ -453,11 +446,7 @@ mod test {
|
||||
manager.store.save_devices(&[bob_device.clone()]).await.unwrap();
|
||||
manager.store.save_sessions(&[session]).await.unwrap();
|
||||
|
||||
assert!(manager
|
||||
.get_missing_sessions(&mut [bob.user_id().clone()].iter())
|
||||
.await
|
||||
.unwrap()
|
||||
.is_none());
|
||||
assert!(manager.get_missing_sessions(iter::once(bob.user_id())).await.unwrap().is_none());
|
||||
|
||||
let curve_key = bob_device.get_key(DeviceKeyAlgorithm::Curve25519).unwrap();
|
||||
|
||||
@@ -467,11 +456,8 @@ mod test {
|
||||
assert!(manager.is_device_wedged(&bob_device));
|
||||
assert!(manager.users_for_key_claim.contains_key(bob.user_id()));
|
||||
|
||||
let (_, request) = manager
|
||||
.get_missing_sessions(&mut [bob.user_id().clone()].iter())
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let (_, request) =
|
||||
manager.get_missing_sessions(iter::once(bob.user_id())).await.unwrap().unwrap();
|
||||
|
||||
assert!(request.one_time_keys.contains_key(bob.user_id()));
|
||||
|
||||
@@ -481,9 +467,9 @@ mod test {
|
||||
|
||||
let mut one_time_keys = BTreeMap::new();
|
||||
one_time_keys
|
||||
.entry(bob.user_id().clone())
|
||||
.entry(bob.user_id().to_owned())
|
||||
.or_insert_with(BTreeMap::new)
|
||||
.insert(bob.device_id().into(), one_time);
|
||||
.insert(bob.device_id().to_owned(), one_time);
|
||||
|
||||
let response = KeyClaimResponse::new(one_time_keys);
|
||||
|
||||
@@ -492,11 +478,7 @@ mod test {
|
||||
manager.receive_keys_claim_response(&response).await.unwrap();
|
||||
|
||||
assert!(!manager.is_device_wedged(&bob_device));
|
||||
assert!(manager
|
||||
.get_missing_sessions(&mut [bob.user_id().clone()].iter())
|
||||
.await
|
||||
.unwrap()
|
||||
.is_none());
|
||||
assert!(manager.get_missing_sessions(iter::once(bob.user_id())).await.unwrap().is_none());
|
||||
assert!(!manager.outgoing_to_device_requests.is_empty())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
use dashmap::DashMap;
|
||||
use matrix_sdk_common::locks::Mutex;
|
||||
use ruma::{DeviceId, DeviceIdBox, RoomId, UserId};
|
||||
use ruma::{DeviceId, RoomId, UserId};
|
||||
|
||||
use crate::{
|
||||
identities::ReadOnlyDevice,
|
||||
@@ -75,7 +75,7 @@ impl SessionStore {
|
||||
/// In-memory store that holds inbound group sessions.
|
||||
pub struct GroupSessionStore {
|
||||
#[allow(clippy::type_complexity)]
|
||||
entries: Arc<DashMap<RoomId, HashMap<String, HashMap<String, InboundGroupSession>>>>,
|
||||
entries: Arc<DashMap<Box<RoomId>, HashMap<String, HashMap<String, InboundGroupSession>>>>,
|
||||
}
|
||||
|
||||
impl GroupSessionStore {
|
||||
@@ -90,7 +90,7 @@ impl GroupSessionStore {
|
||||
/// already in the store.
|
||||
pub fn add(&self, session: InboundGroupSession) -> bool {
|
||||
self.entries
|
||||
.entry((&*session.room_id).clone())
|
||||
.entry((&*session.room_id).to_owned())
|
||||
.or_insert_with(HashMap::new)
|
||||
.entry(session.sender_key.to_string())
|
||||
.or_insert_with(HashMap::new)
|
||||
@@ -139,7 +139,8 @@ impl GroupSessionStore {
|
||||
/// In-memory store holding the devices of users.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct DeviceStore {
|
||||
entries: Arc<DashMap<UserId, DashMap<Box<DeviceId>, ReadOnlyDevice>>>,
|
||||
#[allow(clippy::type_complexity)]
|
||||
entries: Arc<DashMap<Box<UserId>, DashMap<Box<DeviceId>, ReadOnlyDevice>>>,
|
||||
}
|
||||
|
||||
impl DeviceStore {
|
||||
@@ -174,9 +175,9 @@ impl DeviceStore {
|
||||
}
|
||||
|
||||
/// Get a read-only view over all devices of the given user.
|
||||
pub fn user_devices(&self, user_id: &UserId) -> HashMap<DeviceIdBox, ReadOnlyDevice> {
|
||||
pub fn user_devices(&self, user_id: &UserId) -> HashMap<Box<DeviceId>, ReadOnlyDevice> {
|
||||
self.entries
|
||||
.entry(user_id.clone())
|
||||
.entry(user_id.to_owned())
|
||||
.or_insert_with(DashMap::new)
|
||||
.iter()
|
||||
.map(|i| (i.key().to_owned(), i.value().clone()))
|
||||
@@ -231,8 +232,7 @@ mod test {
|
||||
let (account, _) = get_account_and_session().await;
|
||||
let room_id = room_id!("!test:localhost");
|
||||
|
||||
let (outbound, _) =
|
||||
account.create_group_session_pair_with_defaults(&room_id).await.unwrap();
|
||||
let (outbound, _) = account.create_group_session_pair_with_defaults(room_id).await.unwrap();
|
||||
|
||||
assert_eq!(0, outbound.message_index().await);
|
||||
assert!(!outbound.shared());
|
||||
@@ -242,7 +242,7 @@ mod test {
|
||||
let inbound = InboundGroupSession::new(
|
||||
"test_key",
|
||||
"test_key",
|
||||
&room_id,
|
||||
room_id,
|
||||
outbound.session_key().await,
|
||||
None,
|
||||
)
|
||||
@@ -251,7 +251,7 @@ mod test {
|
||||
let store = GroupSessionStore::new();
|
||||
store.add(inbound.clone());
|
||||
|
||||
let loaded_session = store.get(&room_id, "test_key", outbound.session_id()).unwrap();
|
||||
let loaded_session = store.get(room_id, "test_key", outbound.session_id()).unwrap();
|
||||
assert_eq!(inbound, loaded_session);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ use std::{
|
||||
|
||||
use dashmap::{DashMap, DashSet};
|
||||
use matrix_sdk_common::{async_trait, locks::Mutex, uuid::Uuid};
|
||||
use ruma::{DeviceId, DeviceIdBox, RoomId, UserId};
|
||||
use ruma::{DeviceId, RoomId, UserId};
|
||||
|
||||
use super::{
|
||||
caches::{DeviceStore, GroupSessionStore, SessionStore},
|
||||
@@ -46,11 +46,11 @@ fn encode_key_info(info: &SecretInfo) -> String {
|
||||
pub struct MemoryStore {
|
||||
sessions: SessionStore,
|
||||
inbound_group_sessions: GroupSessionStore,
|
||||
tracked_users: Arc<DashSet<UserId>>,
|
||||
users_for_key_query: Arc<DashSet<UserId>>,
|
||||
tracked_users: Arc<DashSet<Box<UserId>>>,
|
||||
users_for_key_query: Arc<DashSet<Box<UserId>>>,
|
||||
olm_hashes: Arc<DashMap<String, DashSet<String>>>,
|
||||
devices: DeviceStore,
|
||||
identities: Arc<DashMap<UserId, ReadOnlyUserIdentities>>,
|
||||
identities: Arc<DashMap<Box<UserId>, ReadOnlyUserIdentities>>,
|
||||
outgoing_key_requests: Arc<DashMap<Uuid, GossipRequest>>,
|
||||
key_requests_by_info: Arc<DashMap<String, Uuid>>,
|
||||
}
|
||||
@@ -207,11 +207,11 @@ impl CryptoStore for MemoryStore {
|
||||
!self.users_for_key_query.is_empty()
|
||||
}
|
||||
|
||||
fn users_for_key_query(&self) -> HashSet<UserId> {
|
||||
fn users_for_key_query(&self) -> HashSet<Box<UserId>> {
|
||||
self.users_for_key_query.iter().map(|u| u.clone()).collect()
|
||||
}
|
||||
|
||||
fn tracked_users(&self) -> HashSet<UserId> {
|
||||
fn tracked_users(&self) -> HashSet<Box<UserId>> {
|
||||
self.tracked_users.iter().map(|u| u.to_owned()).collect()
|
||||
}
|
||||
|
||||
@@ -229,12 +229,12 @@ impl CryptoStore for MemoryStore {
|
||||
// The counter would top out at 2 since there won't be a race between 3
|
||||
// different key queries syncs.
|
||||
if dirty {
|
||||
self.users_for_key_query.insert(user.clone());
|
||||
self.users_for_key_query.insert(user.to_owned());
|
||||
} else {
|
||||
self.users_for_key_query.remove(user);
|
||||
}
|
||||
|
||||
Ok(self.tracked_users.insert(user.clone()))
|
||||
Ok(self.tracked_users.insert(user.to_owned()))
|
||||
}
|
||||
|
||||
async fn get_device(
|
||||
@@ -248,7 +248,7 @@ impl CryptoStore for MemoryStore {
|
||||
async fn get_user_devices(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
) -> Result<HashMap<DeviceIdBox, ReadOnlyDevice>> {
|
||||
) -> Result<HashMap<Box<DeviceId>, ReadOnlyDevice>> {
|
||||
Ok(self.devices.user_devices(user_id))
|
||||
}
|
||||
|
||||
@@ -339,12 +339,11 @@ mod test {
|
||||
let (account, _) = get_account_and_session().await;
|
||||
let room_id = room_id!("!test:localhost");
|
||||
|
||||
let (outbound, _) =
|
||||
account.create_group_session_pair_with_defaults(&room_id).await.unwrap();
|
||||
let (outbound, _) = account.create_group_session_pair_with_defaults(room_id).await.unwrap();
|
||||
let inbound = InboundGroupSession::new(
|
||||
"test_key",
|
||||
"test_key",
|
||||
&room_id,
|
||||
room_id,
|
||||
outbound.session_key().await,
|
||||
None,
|
||||
)
|
||||
@@ -354,7 +353,7 @@ mod test {
|
||||
let _ = store.save_inbound_group_sessions(vec![inbound.clone()]).await;
|
||||
|
||||
let loaded_session = store
|
||||
.get_inbound_group_session(&room_id, "test_key", outbound.session_id())
|
||||
.get_inbound_group_session(room_id, "test_key", outbound.session_id())
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
//! # OlmMachine,
|
||||
//! # store::MemoryStore,
|
||||
//! # };
|
||||
//! # use ruma::{user_id, DeviceIdBox};
|
||||
//! # use ruma::{user_id, DeviceId};
|
||||
//! # let user_id = user_id!("@example:localhost");
|
||||
//! # let device_id: DeviceIdBox = "TEST".into();
|
||||
//! # let device_id: Box<DeviceId> = device_id!("TEST");
|
||||
//! let store = Box::new(MemoryStore::new());
|
||||
//!
|
||||
//! let machine = OlmMachine::new_with_store(user_id, device_id, store);
|
||||
@@ -58,7 +58,7 @@ use olm_rs::errors::{OlmAccountError, OlmGroupSessionError, OlmSessionError};
|
||||
pub use pickle_key::{EncryptedPickleKey, PickleKey};
|
||||
use ruma::{
|
||||
events::secret::request::SecretName, identifiers::Error as IdentifierValidationError, DeviceId,
|
||||
DeviceIdBox, DeviceKeyAlgorithm, RoomId, UserId,
|
||||
DeviceKeyAlgorithm, RoomId, UserId,
|
||||
};
|
||||
use serde_json::Error as SerdeError;
|
||||
use thiserror::Error;
|
||||
@@ -309,7 +309,7 @@ impl Store {
|
||||
pub async fn get_readonly_devices_filtered(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
) -> Result<HashMap<DeviceIdBox, ReadOnlyDevice>> {
|
||||
) -> Result<HashMap<Box<DeviceId>, ReadOnlyDevice>> {
|
||||
self.inner.get_user_devices(user_id).await.map(|mut d| {
|
||||
if user_id == self.user_id() {
|
||||
d.remove(self.device_id());
|
||||
@@ -324,7 +324,7 @@ impl Store {
|
||||
pub async fn get_readonly_devices_unfiltered(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
) -> Result<HashMap<DeviceIdBox, ReadOnlyDevice>> {
|
||||
) -> Result<HashMap<Box<DeviceId>, ReadOnlyDevice>> {
|
||||
self.inner.get_user_devices(user_id).await
|
||||
}
|
||||
|
||||
@@ -648,10 +648,10 @@ pub trait CryptoStore: AsyncTraitDeps {
|
||||
|
||||
/// Set of users that we need to query keys for. This is a subset of
|
||||
/// the tracked users.
|
||||
fn users_for_key_query(&self) -> HashSet<UserId>;
|
||||
fn users_for_key_query(&self) -> HashSet<Box<UserId>>;
|
||||
|
||||
/// Get all tracked users we know about.
|
||||
fn tracked_users(&self) -> HashSet<UserId>;
|
||||
fn tracked_users(&self) -> HashSet<Box<UserId>>;
|
||||
|
||||
/// Add an user for tracking.
|
||||
///
|
||||
@@ -685,7 +685,7 @@ pub trait CryptoStore: AsyncTraitDeps {
|
||||
async fn get_user_devices(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
) -> Result<HashMap<DeviceIdBox, ReadOnlyDevice>>;
|
||||
) -> Result<HashMap<Box<DeviceId>, ReadOnlyDevice>>;
|
||||
|
||||
/// Get the user identity that is attached to the given user id.
|
||||
///
|
||||
|
||||
@@ -25,7 +25,7 @@ use olm_rs::{account::IdentityKeys, PicklingMode};
|
||||
use ruma::{
|
||||
encryption::DeviceKeys,
|
||||
events::{room_key_request::RequestedKeyInfo, secret::request::SecretName},
|
||||
DeviceId, DeviceIdBox, DeviceKeyId, EventEncryptionAlgorithm, RoomId, UserId,
|
||||
DeviceId, DeviceKeyId, EventEncryptionAlgorithm, RoomId, UserId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
pub use sled::Error;
|
||||
@@ -154,8 +154,8 @@ pub struct SledStore {
|
||||
pickle_key: Arc<PickleKey>,
|
||||
|
||||
session_cache: SessionStore,
|
||||
tracked_users_cache: Arc<DashSet<UserId>>,
|
||||
users_for_key_query_cache: Arc<DashSet<UserId>>,
|
||||
tracked_users_cache: Arc<DashSet<Box<UserId>>>,
|
||||
users_for_key_query_cache: Arc<DashSet<Box<UserId>>>,
|
||||
|
||||
account: Tree,
|
||||
private_identity: Tree,
|
||||
@@ -274,11 +274,11 @@ impl SledStore {
|
||||
if version <= 1 {
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct OldReadOnlyDevice {
|
||||
user_id: UserId,
|
||||
device_id: DeviceIdBox,
|
||||
user_id: Box<UserId>,
|
||||
device_id: Box<DeviceId>,
|
||||
algorithms: Vec<EventEncryptionAlgorithm>,
|
||||
keys: BTreeMap<DeviceKeyId, String>,
|
||||
signatures: BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>,
|
||||
keys: BTreeMap<Box<DeviceKeyId>, String>,
|
||||
signatures: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>,
|
||||
display_name: Option<String>,
|
||||
deleted: bool,
|
||||
trust_state: LocalTrust,
|
||||
@@ -424,10 +424,10 @@ impl SledStore {
|
||||
async fn load_tracked_users(&self) -> Result<()> {
|
||||
for value in self.tracked_users.iter() {
|
||||
let (user, dirty) = value?;
|
||||
let user = UserId::try_from(String::from_utf8_lossy(&user).to_string())?;
|
||||
let user = Box::<UserId>::try_from(String::from_utf8_lossy(&user).to_string())?;
|
||||
let dirty = dirty.get(0).map(|d| *d == 1).unwrap_or(true);
|
||||
|
||||
self.tracked_users_cache.insert(user.clone());
|
||||
self.tracked_users_cache.insert(user.to_owned());
|
||||
|
||||
if dirty {
|
||||
self.users_for_key_query_cache.insert(user);
|
||||
@@ -507,7 +507,7 @@ impl SledStore {
|
||||
let room_id = session.room_id();
|
||||
let pickle = session.pickle(self.get_pickle_mode()).await;
|
||||
|
||||
outbound_session_changes.insert(room_id.clone(), pickle);
|
||||
outbound_session_changes.insert(room_id.to_owned(), pickle);
|
||||
}
|
||||
|
||||
let identity_changes = changes.identities;
|
||||
@@ -611,7 +611,7 @@ impl SledStore {
|
||||
|
||||
for (key, session) in &outbound_session_changes {
|
||||
outbound_sessions.insert(
|
||||
key.encode(),
|
||||
(&**key).encode(),
|
||||
serde_json::to_vec(&session)
|
||||
.map_err(ConflictableTransactionError::Abort)?,
|
||||
)?;
|
||||
@@ -853,19 +853,19 @@ impl CryptoStore for SledStore {
|
||||
!self.users_for_key_query_cache.is_empty()
|
||||
}
|
||||
|
||||
fn users_for_key_query(&self) -> HashSet<UserId> {
|
||||
fn users_for_key_query(&self) -> HashSet<Box<UserId>> {
|
||||
self.users_for_key_query_cache.iter().map(|u| u.clone()).collect()
|
||||
}
|
||||
|
||||
fn tracked_users(&self) -> HashSet<UserId> {
|
||||
fn tracked_users(&self) -> HashSet<Box<UserId>> {
|
||||
self.tracked_users_cache.to_owned().iter().map(|u| u.clone()).collect()
|
||||
}
|
||||
|
||||
async fn update_tracked_user(&self, user: &UserId, dirty: bool) -> Result<bool> {
|
||||
let already_added = self.tracked_users_cache.insert(user.clone());
|
||||
let already_added = self.tracked_users_cache.insert(user.to_owned());
|
||||
|
||||
if dirty {
|
||||
self.users_for_key_query_cache.insert(user.clone());
|
||||
self.users_for_key_query_cache.insert(user.to_owned());
|
||||
} else {
|
||||
self.users_for_key_query_cache.remove(user);
|
||||
}
|
||||
@@ -887,7 +887,7 @@ impl CryptoStore for SledStore {
|
||||
async fn get_user_devices(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
) -> Result<HashMap<DeviceIdBox, ReadOnlyDevice>> {
|
||||
) -> Result<HashMap<Box<DeviceId>, ReadOnlyDevice>> {
|
||||
self.devices
|
||||
.scan_prefix(user_id.encode())
|
||||
.map(|d| serde_json::from_slice(&d?.1).map_err(CryptoStoreError::Serialization))
|
||||
@@ -1015,8 +1015,8 @@ mod test {
|
||||
use matrix_sdk_test::async_test;
|
||||
use olm_rs::outbound_group_session::OlmOutboundGroupSession;
|
||||
use ruma::{
|
||||
encryption::SignedKey, events::room_key_request::RequestedKeyInfo, room_id, user_id,
|
||||
DeviceId, EventEncryptionAlgorithm, UserId,
|
||||
device_id, encryption::SignedKey, events::room_key_request::RequestedKeyInfo, room_id,
|
||||
user_id, DeviceId, EventEncryptionAlgorithm, UserId,
|
||||
};
|
||||
use tempfile::tempdir;
|
||||
|
||||
@@ -1034,20 +1034,20 @@ mod test {
|
||||
store::{Changes, DeviceChanges, IdentityChanges},
|
||||
};
|
||||
|
||||
fn alice_id() -> UserId {
|
||||
fn alice_id() -> &'static UserId {
|
||||
user_id!("@alice:example.org")
|
||||
}
|
||||
|
||||
fn alice_device_id() -> Box<DeviceId> {
|
||||
"ALICEDEVICE".into()
|
||||
fn alice_device_id() -> &'static DeviceId {
|
||||
device_id!("ALICEDEVICE")
|
||||
}
|
||||
|
||||
fn bob_id() -> UserId {
|
||||
fn bob_id() -> &'static UserId {
|
||||
user_id!("@bob:example.org")
|
||||
}
|
||||
|
||||
fn bob_device_id() -> Box<DeviceId> {
|
||||
"BOBDEVICE".into()
|
||||
fn bob_device_id() -> &'static DeviceId {
|
||||
device_id!("BOBDEVICE")
|
||||
}
|
||||
|
||||
async fn get_store(passphrase: Option<&str>) -> (SledStore, tempfile::TempDir) {
|
||||
@@ -1069,12 +1069,12 @@ mod test {
|
||||
}
|
||||
|
||||
fn get_account() -> ReadOnlyAccount {
|
||||
ReadOnlyAccount::new(&alice_id(), &alice_device_id())
|
||||
ReadOnlyAccount::new(alice_id(), alice_device_id())
|
||||
}
|
||||
|
||||
async fn get_account_and_session() -> (ReadOnlyAccount, Session) {
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let bob = ReadOnlyAccount::new(&bob_id(), &bob_device_id());
|
||||
let alice = ReadOnlyAccount::new(alice_id(), alice_device_id());
|
||||
let bob = ReadOnlyAccount::new(bob_id(), bob_device_id());
|
||||
|
||||
bob.generate_one_time_keys_helper(1).await;
|
||||
let one_time_key =
|
||||
@@ -1206,7 +1206,7 @@ mod test {
|
||||
let session = InboundGroupSession::new(
|
||||
identity_keys.curve25519(),
|
||||
identity_keys.ed25519(),
|
||||
&room_id!("!test:localhost"),
|
||||
room_id!("!test:localhost"),
|
||||
GroupSessionKey(outbound_session.session_key()),
|
||||
None,
|
||||
)
|
||||
@@ -1226,7 +1226,7 @@ mod test {
|
||||
let session = InboundGroupSession::new(
|
||||
identity_keys.curve25519(),
|
||||
identity_keys.ed25519(),
|
||||
&room_id!("!test:localhost"),
|
||||
room_id!("!test:localhost"),
|
||||
GroupSessionKey(outbound_session.session_key()),
|
||||
None,
|
||||
)
|
||||
@@ -1360,11 +1360,11 @@ mod test {
|
||||
let tmpdir_path = dir.path().to_str().unwrap();
|
||||
|
||||
let user_id = user_id!("@example:localhost");
|
||||
let device_id: &DeviceId = "WSKKLTJZCL".into();
|
||||
let device_id: &DeviceId = device_id!("WSKKLTJZCL");
|
||||
|
||||
let store = SledStore::open_with_passphrase(tmpdir_path, None).expect("Can't create store");
|
||||
|
||||
let account = ReadOnlyAccount::new(&user_id, device_id);
|
||||
let account = ReadOnlyAccount::new(user_id, device_id);
|
||||
|
||||
store.save_account(account.clone()).await.expect("Can't save account");
|
||||
|
||||
@@ -1421,7 +1421,7 @@ mod test {
|
||||
};
|
||||
|
||||
store.save_changes(changes).await.unwrap();
|
||||
let loaded_user = store.get_user_identity(&user_id).await.unwrap().unwrap();
|
||||
let loaded_user = store.get_user_identity(user_id).await.unwrap().unwrap();
|
||||
assert!(loaded_user.own().unwrap().is_verified())
|
||||
}
|
||||
|
||||
@@ -1429,7 +1429,7 @@ mod test {
|
||||
async fn private_identity_saving() {
|
||||
let (_, store, _dir) = get_loaded_store().await;
|
||||
assert!(store.load_identity().await.unwrap().is_none());
|
||||
let identity = PrivateCrossSigningIdentity::new(alice_id()).await;
|
||||
let identity = PrivateCrossSigningIdentity::new(alice_id().to_owned()).await;
|
||||
|
||||
let changes = Changes { private_identity: Some(identity.clone()), ..Default::default() };
|
||||
|
||||
@@ -1460,7 +1460,7 @@ mod test {
|
||||
let id = Uuid::new_v4();
|
||||
let info: SecretInfo = RequestedKeyInfo::new(
|
||||
EventEncryptionAlgorithm::MegolmV1AesSha2,
|
||||
room_id!("!test:localhost"),
|
||||
room_id!("!test:localhost").to_owned(),
|
||||
"test_sender_key".to_string(),
|
||||
"test_session_id".to_string(),
|
||||
)
|
||||
|
||||
@@ -26,7 +26,7 @@ use crate::{OutgoingRequest, OutgoingVerificationRequest, RoomMessageRequest, To
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct VerificationCache {
|
||||
verification: Arc<DashMap<UserId, DashMap<String, Verification>>>,
|
||||
verification: Arc<DashMap<Box<UserId>, DashMap<String, Verification>>>,
|
||||
outgoing_requests: Arc<DashMap<Uuid, OutgoingRequest>>,
|
||||
}
|
||||
|
||||
|
||||
@@ -188,26 +188,26 @@ impl TryFrom<&AnyMessageEvent> for FlowId {
|
||||
| AnyMessageEvent::RoomRedaction(_)
|
||||
| AnyMessageEvent::Sticker(_) => Err(()),
|
||||
AnyMessageEvent::KeyVerificationReady(e) => {
|
||||
Ok(FlowId::from((&e.room_id, &e.content.relates_to.event_id)))
|
||||
Ok(FlowId::from((&*e.room_id, &*e.content.relates_to.event_id)))
|
||||
}
|
||||
AnyMessageEvent::RoomMessage(e) => Ok(FlowId::from((&e.room_id, &e.event_id))),
|
||||
AnyMessageEvent::RoomMessage(e) => Ok(FlowId::from((&*e.room_id, &*e.event_id))),
|
||||
AnyMessageEvent::KeyVerificationStart(e) => {
|
||||
Ok(FlowId::from((&e.room_id, &e.content.relates_to.event_id)))
|
||||
Ok(FlowId::from((&*e.room_id, &*e.content.relates_to.event_id)))
|
||||
}
|
||||
AnyMessageEvent::KeyVerificationCancel(e) => {
|
||||
Ok(FlowId::from((&e.room_id, &e.content.relates_to.event_id)))
|
||||
Ok(FlowId::from((&*e.room_id, &*e.content.relates_to.event_id)))
|
||||
}
|
||||
AnyMessageEvent::KeyVerificationAccept(e) => {
|
||||
Ok(FlowId::from((&e.room_id, &e.content.relates_to.event_id)))
|
||||
Ok(FlowId::from((&*e.room_id, &*e.content.relates_to.event_id)))
|
||||
}
|
||||
AnyMessageEvent::KeyVerificationKey(e) => {
|
||||
Ok(FlowId::from((&e.room_id, &e.content.relates_to.event_id)))
|
||||
Ok(FlowId::from((&*e.room_id, &*e.content.relates_to.event_id)))
|
||||
}
|
||||
AnyMessageEvent::KeyVerificationMac(e) => {
|
||||
Ok(FlowId::from((&e.room_id, &e.content.relates_to.event_id)))
|
||||
Ok(FlowId::from((&*e.room_id, &*e.content.relates_to.event_id)))
|
||||
}
|
||||
AnyMessageEvent::KeyVerificationDone(e) => {
|
||||
Ok(FlowId::from((&e.room_id, &e.content.relates_to.event_id)))
|
||||
Ok(FlowId::from((&*e.room_id, &*e.content.relates_to.event_id)))
|
||||
}
|
||||
_ => Err(()),
|
||||
}
|
||||
@@ -589,7 +589,7 @@ impl CancelContent<'_> {
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum OwnedStartContent {
|
||||
ToDevice(ToDeviceKeyVerificationStartEventContent),
|
||||
Room(RoomId, KeyVerificationStartEventContent),
|
||||
Room(Box<RoomId>, KeyVerificationStartEventContent),
|
||||
}
|
||||
|
||||
impl OwnedStartContent {
|
||||
@@ -631,8 +631,8 @@ impl OwnedStartContent {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(RoomId, KeyVerificationStartEventContent)> for OwnedStartContent {
|
||||
fn from(tuple: (RoomId, KeyVerificationStartEventContent)) -> Self {
|
||||
impl From<(Box<RoomId>, KeyVerificationStartEventContent)> for OwnedStartContent {
|
||||
fn from(tuple: (Box<RoomId>, KeyVerificationStartEventContent)) -> Self {
|
||||
Self::Room(tuple.0, tuple.1)
|
||||
}
|
||||
}
|
||||
@@ -646,7 +646,7 @@ impl From<ToDeviceKeyVerificationStartEventContent> for OwnedStartContent {
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum OwnedAcceptContent {
|
||||
ToDevice(ToDeviceKeyVerificationAcceptEventContent),
|
||||
Room(RoomId, KeyVerificationAcceptEventContent),
|
||||
Room(Box<RoomId>, KeyVerificationAcceptEventContent),
|
||||
}
|
||||
|
||||
impl From<ToDeviceKeyVerificationAcceptEventContent> for OwnedAcceptContent {
|
||||
@@ -655,8 +655,8 @@ impl From<ToDeviceKeyVerificationAcceptEventContent> for OwnedAcceptContent {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(RoomId, KeyVerificationAcceptEventContent)> for OwnedAcceptContent {
|
||||
fn from(content: (RoomId, KeyVerificationAcceptEventContent)) -> Self {
|
||||
impl From<(Box<RoomId>, KeyVerificationAcceptEventContent)> for OwnedAcceptContent {
|
||||
fn from(content: (Box<RoomId>, KeyVerificationAcceptEventContent)) -> Self {
|
||||
Self::Room(content.0, content.1)
|
||||
}
|
||||
}
|
||||
@@ -672,7 +672,7 @@ impl OwnedAcceptContent {
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum OutgoingContent {
|
||||
Room(RoomId, AnyMessageEventContent),
|
||||
Room(Box<RoomId>, AnyMessageEventContent),
|
||||
ToDevice(AnyToDeviceEventContent),
|
||||
}
|
||||
|
||||
@@ -695,8 +695,8 @@ impl From<AnyToDeviceEventContent> for OutgoingContent {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(RoomId, AnyMessageEventContent)> for OutgoingContent {
|
||||
fn from(content: (RoomId, AnyMessageEventContent)) -> Self {
|
||||
impl From<(Box<RoomId>, AnyMessageEventContent)> for OutgoingContent {
|
||||
fn from(content: (Box<RoomId>, AnyMessageEventContent)) -> Self {
|
||||
OutgoingContent::Room(content.0, content.1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ use ruma::{
|
||||
ToDeviceEvent,
|
||||
},
|
||||
serde::Raw,
|
||||
DeviceId, DeviceIdBox, EventId, MilliSecondsSinceUnixEpoch, RoomId, UserId,
|
||||
DeviceId, EventId, MilliSecondsSinceUnixEpoch, RoomId, UserId,
|
||||
};
|
||||
use tracing::{info, trace, warn};
|
||||
|
||||
@@ -49,7 +49,7 @@ pub struct VerificationMachine {
|
||||
pub(crate) private_identity: Arc<Mutex<PrivateCrossSigningIdentity>>,
|
||||
pub(crate) store: VerificationStore,
|
||||
verifications: VerificationCache,
|
||||
requests: Arc<DashMap<UserId, DashMap<String, VerificationRequest>>>,
|
||||
requests: Arc<DashMap<Box<UserId>, DashMap<String, VerificationRequest>>>,
|
||||
}
|
||||
|
||||
impl VerificationMachine {
|
||||
@@ -77,7 +77,7 @@ impl VerificationMachine {
|
||||
pub(crate) async fn request_to_device_verification(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
recipient_devices: Vec<DeviceIdBox>,
|
||||
recipient_devices: Vec<Box<DeviceId>>,
|
||||
methods: Option<Vec<VerificationMethod>>,
|
||||
) -> (VerificationRequest, OutgoingVerificationRequest) {
|
||||
let flow_id = FlowId::from(Uuid::new_v4().to_string());
|
||||
@@ -523,7 +523,7 @@ mod test {
|
||||
};
|
||||
|
||||
use matrix_sdk_common::locks::Mutex;
|
||||
use ruma::{DeviceId, UserId};
|
||||
use ruma::{device_id, user_id, DeviceId, UserId};
|
||||
|
||||
use super::{Sas, VerificationMachine};
|
||||
use crate::{
|
||||
@@ -537,25 +537,25 @@ mod test {
|
||||
ReadOnlyAccount, ReadOnlyDevice,
|
||||
};
|
||||
|
||||
fn alice_id() -> UserId {
|
||||
UserId::try_from("@alice:example.org").unwrap()
|
||||
fn alice_id() -> &'static UserId {
|
||||
user_id!("@alice:example.org")
|
||||
}
|
||||
|
||||
fn alice_device_id() -> Box<DeviceId> {
|
||||
"JLAFKJWSCS".into()
|
||||
fn alice_device_id() -> &'static DeviceId {
|
||||
device_id!("JLAFKJWSCS")
|
||||
}
|
||||
|
||||
fn bob_id() -> UserId {
|
||||
UserId::try_from("@bob:example.org").unwrap()
|
||||
fn bob_id() -> &'static UserId {
|
||||
user_id!("@bob:example.org")
|
||||
}
|
||||
|
||||
fn bob_device_id() -> Box<DeviceId> {
|
||||
"BOBDEVCIE".into()
|
||||
fn bob_device_id() -> &'static DeviceId {
|
||||
device_id!("BOBDEVCIE")
|
||||
}
|
||||
|
||||
async fn setup_verification_machine() -> (VerificationMachine, Sas) {
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let bob = ReadOnlyAccount::new(&bob_id(), &bob_device_id());
|
||||
let alice = ReadOnlyAccount::new(alice_id(), alice_device_id());
|
||||
let bob = ReadOnlyAccount::new(bob_id(), bob_device_id());
|
||||
let store = MemoryStore::new();
|
||||
let bob_store = MemoryStore::new();
|
||||
|
||||
@@ -567,10 +567,11 @@ mod test {
|
||||
|
||||
let bob_store = VerificationStore { account: bob, inner: Arc::new(bob_store) };
|
||||
|
||||
let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(alice_id())));
|
||||
let identity =
|
||||
Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(alice_id().to_owned())));
|
||||
let machine = VerificationMachine::new(alice, identity, Arc::new(store));
|
||||
let (bob_sas, start_content) = Sas::start(
|
||||
PrivateCrossSigningIdentity::empty(bob_id()),
|
||||
PrivateCrossSigningIdentity::empty(bob_id().to_owned()),
|
||||
alice_device,
|
||||
bob_store,
|
||||
None,
|
||||
@@ -590,8 +591,9 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn create() {
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(alice_id())));
|
||||
let alice = ReadOnlyAccount::new(alice_id(), alice_device_id());
|
||||
let identity =
|
||||
Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(alice_id().to_owned())));
|
||||
let store = MemoryStore::new();
|
||||
let _ = VerificationMachine::new(alice, identity, Arc::new(store));
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ use ruma::{
|
||||
},
|
||||
AnyMessageEventContent, AnyToDeviceEventContent,
|
||||
},
|
||||
DeviceId, DeviceIdBox, DeviceKeyId, EventId, RoomId, UserId,
|
||||
DeviceId, DeviceKeyId, EventId, RoomId, UserId,
|
||||
};
|
||||
pub use sas::{AcceptSettings, Sas};
|
||||
use tracing::{error, info, trace, warn};
|
||||
@@ -104,7 +104,7 @@ impl VerificationStore {
|
||||
pub async fn get_user_devices(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
) -> Result<HashMap<DeviceIdBox, ReadOnlyDevice>, CryptoStoreError> {
|
||||
) -> Result<HashMap<Box<DeviceId>, ReadOnlyDevice>, CryptoStoreError> {
|
||||
self.inner.get_user_devices(user_id).await
|
||||
}
|
||||
|
||||
@@ -118,7 +118,8 @@ impl VerificationStore {
|
||||
/// Get the signatures that have signed our own device.
|
||||
pub async fn device_signatures(
|
||||
&self,
|
||||
) -> Result<Option<BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>>, CryptoStoreError> {
|
||||
) -> Result<Option<BTreeMap<Box<UserId>, BTreeMap<Box<DeviceKeyId>, String>>>, CryptoStoreError>
|
||||
{
|
||||
Ok(self
|
||||
.inner
|
||||
.get_device(self.account.user_id(), self.account.device_id())
|
||||
@@ -351,7 +352,7 @@ impl Cancelled {
|
||||
#[derive(Clone, Debug, Hash, PartialEq, PartialOrd)]
|
||||
pub enum FlowId {
|
||||
ToDevice(String),
|
||||
InRoom(RoomId, EventId),
|
||||
InRoom(Box<RoomId>, Box<EventId>),
|
||||
}
|
||||
|
||||
impl FlowId {
|
||||
@@ -377,8 +378,8 @@ impl From<String> for FlowId {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(RoomId, EventId)> for FlowId {
|
||||
fn from(ids: (RoomId, EventId)) -> Self {
|
||||
impl From<(Box<RoomId>, Box<EventId>)> for FlowId {
|
||||
fn from(ids: (Box<RoomId>, Box<EventId>)) -> Self {
|
||||
FlowId::InRoom(ids.0, ids.1)
|
||||
}
|
||||
}
|
||||
@@ -711,31 +712,20 @@ pub(crate) mod test {
|
||||
content: OutgoingContent,
|
||||
) -> AnyToDeviceEvent {
|
||||
let content = if let OutgoingContent::ToDevice(c) = content { c } else { unreachable!() };
|
||||
let sender = sender.to_owned();
|
||||
|
||||
match content {
|
||||
AnyToDeviceEventContent::KeyVerificationKey(c) => {
|
||||
AnyToDeviceEvent::KeyVerificationKey(ToDeviceEvent {
|
||||
sender: sender.clone(),
|
||||
content: c,
|
||||
})
|
||||
AnyToDeviceEvent::KeyVerificationKey(ToDeviceEvent { sender, content: c })
|
||||
}
|
||||
AnyToDeviceEventContent::KeyVerificationStart(c) => {
|
||||
AnyToDeviceEvent::KeyVerificationStart(ToDeviceEvent {
|
||||
sender: sender.clone(),
|
||||
content: c,
|
||||
})
|
||||
AnyToDeviceEvent::KeyVerificationStart(ToDeviceEvent { sender, content: c })
|
||||
}
|
||||
AnyToDeviceEventContent::KeyVerificationAccept(c) => {
|
||||
AnyToDeviceEvent::KeyVerificationAccept(ToDeviceEvent {
|
||||
sender: sender.clone(),
|
||||
content: c,
|
||||
})
|
||||
AnyToDeviceEvent::KeyVerificationAccept(ToDeviceEvent { sender, content: c })
|
||||
}
|
||||
AnyToDeviceEventContent::KeyVerificationMac(c) => {
|
||||
AnyToDeviceEvent::KeyVerificationMac(ToDeviceEvent {
|
||||
sender: sender.clone(),
|
||||
content: c,
|
||||
})
|
||||
AnyToDeviceEvent::KeyVerificationMac(ToDeviceEvent { sender, content: c })
|
||||
}
|
||||
|
||||
_ => unreachable!(),
|
||||
|
||||
@@ -33,7 +33,7 @@ use ruma::{
|
||||
},
|
||||
AnyMessageEventContent, AnyToDeviceEventContent,
|
||||
},
|
||||
DeviceId, DeviceIdBox, DeviceKeyAlgorithm, RoomId, UserId,
|
||||
DeviceId, DeviceKeyAlgorithm, RoomId, UserId,
|
||||
};
|
||||
use thiserror::Error;
|
||||
use tracing::trace;
|
||||
@@ -70,11 +70,11 @@ pub enum ScanError {
|
||||
/// One of the users that is participating in this verification doesn't have
|
||||
/// a valid cross signing identity.
|
||||
#[error("The user {0} is missing a valid cross signing identity")]
|
||||
MissingCrossSigningIdentity(UserId),
|
||||
MissingCrossSigningIdentity(Box<UserId>),
|
||||
/// The device of the user that is participating in this verification
|
||||
/// doesn't have a valid device key.
|
||||
#[error("The user's {0} device {1} is not E2E capable")]
|
||||
MissingDeviceKeys(UserId, DeviceIdBox),
|
||||
MissingDeviceKeys(Box<UserId>, Box<DeviceId>),
|
||||
/// The ID uniquely identifying this verification flow didn't match to the
|
||||
/// one that has been scanned.
|
||||
#[error("The unique verification flow id did not match (expected {expected}, found {found})")]
|
||||
@@ -505,8 +505,8 @@ impl QrVerification {
|
||||
pub(crate) async fn from_scan(
|
||||
store: VerificationStore,
|
||||
private_identity: PrivateCrossSigningIdentity,
|
||||
other_user_id: UserId,
|
||||
other_device_id: DeviceIdBox,
|
||||
other_user_id: Box<UserId>,
|
||||
other_device_id: Box<DeviceId>,
|
||||
flow_id: FlowId,
|
||||
qr_code: QrVerificationData,
|
||||
we_started: bool,
|
||||
@@ -534,7 +534,7 @@ impl QrVerification {
|
||||
|
||||
let check_master_key = |key, identity: &ReadOnlyUserIdentities| {
|
||||
let master_key = identity.master_key().get_first_key().ok_or_else(|| {
|
||||
ScanError::MissingCrossSigningIdentity(identity.user_id().clone())
|
||||
ScanError::MissingCrossSigningIdentity(identity.user_id().to_owned())
|
||||
})?;
|
||||
|
||||
if key != master_key {
|
||||
@@ -658,7 +658,7 @@ struct Confirmed {}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Reciprocated {
|
||||
own_device_id: DeviceIdBox,
|
||||
own_device_id: Box<DeviceId>,
|
||||
secret: String,
|
||||
}
|
||||
|
||||
@@ -798,7 +798,7 @@ mod test {
|
||||
|
||||
use matrix_qrcode::QrVerificationData;
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::{event_id, room_id, user_id, DeviceIdBox, UserId};
|
||||
use ruma::{device_id, event_id, room_id, user_id, DeviceId, UserId};
|
||||
|
||||
use crate::{
|
||||
olm::{PrivateCrossSigningIdentity, ReadOnlyAccount},
|
||||
@@ -810,7 +810,7 @@ mod test {
|
||||
QrVerification, ReadOnlyDevice,
|
||||
};
|
||||
|
||||
fn user_id() -> UserId {
|
||||
fn user_id() -> &'static UserId {
|
||||
user_id!("@example:localhost")
|
||||
}
|
||||
|
||||
@@ -818,18 +818,18 @@ mod test {
|
||||
Arc::new(MemoryStore::new())
|
||||
}
|
||||
|
||||
fn device_id() -> DeviceIdBox {
|
||||
"DEVICEID".into()
|
||||
fn device_id() -> &'static DeviceId {
|
||||
device_id!("DEVICEID")
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_verification_creation() {
|
||||
let store = memory_store();
|
||||
let account = ReadOnlyAccount::new(&user_id(), &device_id());
|
||||
let account = ReadOnlyAccount::new(user_id(), device_id());
|
||||
|
||||
let store = VerificationStore { account: account.clone(), inner: store };
|
||||
|
||||
let private_identity = PrivateCrossSigningIdentity::new(user_id()).await;
|
||||
let private_identity = PrivateCrossSigningIdentity::new(user_id().to_owned()).await;
|
||||
let flow_id = FlowId::ToDevice("test_transaction".to_owned());
|
||||
|
||||
let device_key = account.identity_keys().ed25519().to_owned();
|
||||
@@ -869,11 +869,13 @@ mod test {
|
||||
assert_eq!(verification.inner.first_key(), &master_key);
|
||||
assert_eq!(verification.inner.second_key(), &device_key);
|
||||
|
||||
let bob_identity = PrivateCrossSigningIdentity::new(user_id!("@bob:example")).await;
|
||||
let bob_identity =
|
||||
PrivateCrossSigningIdentity::new(user_id!("@bob:example").to_owned()).await;
|
||||
let bob_master_key = bob_identity.master_public_key().await.unwrap();
|
||||
let bob_master_key = bob_master_key.get_first_key().unwrap().to_owned();
|
||||
|
||||
let flow_id = FlowId::InRoom(room_id!("!test:example"), event_id!("$EVENTID"));
|
||||
let flow_id =
|
||||
FlowId::InRoom(room_id!("!test:example").to_owned(), event_id!("$EVENTID").to_owned());
|
||||
|
||||
let verification = QrVerification::new_cross(
|
||||
flow_id,
|
||||
@@ -891,14 +893,15 @@ mod test {
|
||||
#[async_test]
|
||||
async fn test_reciprocate_receival() {
|
||||
let test = |flow_id: FlowId| async move {
|
||||
let alice_account = ReadOnlyAccount::new(&user_id(), &device_id());
|
||||
let alice_account = ReadOnlyAccount::new(user_id(), device_id());
|
||||
let store = memory_store();
|
||||
|
||||
let store = VerificationStore { account: alice_account.clone(), inner: store };
|
||||
|
||||
let bob_account = ReadOnlyAccount::new(alice_account.user_id(), "BOBDEVICE".into());
|
||||
let bob_account =
|
||||
ReadOnlyAccount::new(alice_account.user_id(), device_id!("BOBDEVICE"));
|
||||
|
||||
let private_identity = PrivateCrossSigningIdentity::new(user_id()).await;
|
||||
let private_identity = PrivateCrossSigningIdentity::new(user_id().to_owned()).await;
|
||||
let identity = private_identity.to_public_identity().await.unwrap();
|
||||
|
||||
let master_key = private_identity.master_public_key().await.unwrap();
|
||||
@@ -994,7 +997,8 @@ mod test {
|
||||
let flow_id = FlowId::ToDevice("test_transaction".to_owned());
|
||||
test(flow_id).await;
|
||||
|
||||
let flow_id = FlowId::InRoom(room_id!("!test:example"), event_id!("$EVENTID"));
|
||||
let flow_id =
|
||||
FlowId::InRoom(room_id!("!test:example").to_owned(), event_id!("$EVENTID").to_owned());
|
||||
test(flow_id).await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ use ruma::{
|
||||
AnyMessageEventContent, AnyToDeviceEventContent,
|
||||
},
|
||||
to_device::DeviceIdOrAllDevices,
|
||||
DeviceId, DeviceIdBox, MilliSecondsSinceUnixEpoch, RoomId, UserId,
|
||||
DeviceId, MilliSecondsSinceUnixEpoch, RoomId, UserId,
|
||||
};
|
||||
use tracing::{info, trace, warn};
|
||||
|
||||
@@ -82,7 +82,7 @@ pub struct VerificationRequest {
|
||||
inner: Arc<Mutex<InnerRequest>>,
|
||||
creation_time: Arc<Instant>,
|
||||
we_started: bool,
|
||||
recipient_devices: Arc<Vec<DeviceIdBox>>,
|
||||
recipient_devices: Arc<Vec<Box<DeviceId>>>,
|
||||
}
|
||||
|
||||
/// A handle to a request so child verification flows can cancel the request.
|
||||
@@ -118,7 +118,7 @@ impl VerificationRequest {
|
||||
store: VerificationStore,
|
||||
flow_id: FlowId,
|
||||
other_user: &UserId,
|
||||
recipient_devices: Vec<DeviceIdBox>,
|
||||
recipient_devices: Vec<Box<DeviceId>>,
|
||||
methods: Option<Vec<VerificationMethod>>,
|
||||
) -> Self {
|
||||
let account = store.account.clone();
|
||||
@@ -207,7 +207,7 @@ impl VerificationRequest {
|
||||
}
|
||||
|
||||
/// The id of the other device that is participating in this verification.
|
||||
pub fn other_device_id(&self) -> Option<DeviceIdBox> {
|
||||
pub fn other_device_id(&self) -> Option<Box<DeviceId>> {
|
||||
match &*self.inner.lock().unwrap() {
|
||||
InnerRequest::Requested(r) => Some(r.state.other_device_id.clone()),
|
||||
InnerRequest::Ready(r) => Some(r.state.other_device_id.clone()),
|
||||
@@ -523,7 +523,7 @@ impl VerificationRequest {
|
||||
let cancel_content = cancelled.as_content(self.flow_id());
|
||||
|
||||
if let OutgoingContent::ToDevice(c) = cancel_content {
|
||||
let recipients: Vec<DeviceIdBox> = self
|
||||
let recipients: Vec<Box<DeviceId>> = self
|
||||
.recipient_devices
|
||||
.to_vec()
|
||||
.into_iter()
|
||||
@@ -767,7 +767,7 @@ struct RequestState<S: Clone> {
|
||||
flow_id: Arc<FlowId>,
|
||||
|
||||
/// The id of the user which is participating in this verification request.
|
||||
pub other_user_id: UserId,
|
||||
pub other_user_id: Box<UserId>,
|
||||
|
||||
/// The verification request state we are in.
|
||||
state: S,
|
||||
@@ -851,7 +851,7 @@ struct Requested {
|
||||
pub their_methods: Vec<VerificationMethod>,
|
||||
|
||||
/// The device id of the device that responded to the verification request.
|
||||
pub other_device_id: DeviceIdBox,
|
||||
pub other_device_id: Box<DeviceId>,
|
||||
}
|
||||
|
||||
impl RequestState<Requested> {
|
||||
@@ -869,7 +869,7 @@ impl RequestState<Requested> {
|
||||
store,
|
||||
verification_cache: cache,
|
||||
flow_id: flow_id.to_owned().into(),
|
||||
other_user_id: sender.clone(),
|
||||
other_user_id: sender.to_owned(),
|
||||
state: Requested {
|
||||
their_methods: content.methods().to_owned(),
|
||||
other_device_id: content.from_device().into(),
|
||||
@@ -937,7 +937,7 @@ struct Ready {
|
||||
pub our_methods: Vec<VerificationMethod>,
|
||||
|
||||
/// The device id of the device that responded to the verification request.
|
||||
pub other_device_id: DeviceIdBox,
|
||||
pub other_device_id: Box<DeviceId>,
|
||||
}
|
||||
|
||||
impl RequestState<Ready> {
|
||||
@@ -1258,7 +1258,7 @@ impl RequestState<Ready> {
|
||||
struct Passive {
|
||||
/// The device id of the device that responded to the verification request.
|
||||
#[allow(dead_code)]
|
||||
pub other_device_id: DeviceIdBox,
|
||||
pub other_device_id: Box<DeviceId>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -1269,7 +1269,7 @@ mod test {
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
|
||||
use matrix_sdk_test::async_test;
|
||||
use ruma::{event_id, room_id, DeviceIdBox, UserId};
|
||||
use ruma::{device_id, event_id, room_id, user_id, DeviceId, UserId};
|
||||
|
||||
use super::VerificationRequest;
|
||||
use crate::{
|
||||
@@ -1283,41 +1283,41 @@ mod test {
|
||||
ReadOnlyDevice,
|
||||
};
|
||||
|
||||
fn alice_id() -> UserId {
|
||||
UserId::try_from("@alice:example.org").unwrap()
|
||||
fn alice_id() -> &'static UserId {
|
||||
user_id!("@alice:example.org")
|
||||
}
|
||||
|
||||
fn alice_device_id() -> DeviceIdBox {
|
||||
"JLAFKJWSCS".into()
|
||||
fn alice_device_id() -> &'static DeviceId {
|
||||
device_id!("JLAFKJWSCS")
|
||||
}
|
||||
|
||||
fn bob_id() -> UserId {
|
||||
UserId::try_from("@bob:example.org").unwrap()
|
||||
fn bob_id() -> &'static UserId {
|
||||
user_id!("@bob:example.org")
|
||||
}
|
||||
|
||||
fn bob_device_id() -> DeviceIdBox {
|
||||
"BOBDEVCIE".into()
|
||||
fn bob_device_id() -> &'static DeviceId {
|
||||
device_id!("BOBDEVCIE")
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_request_accepting() {
|
||||
let event_id = event_id!("$1234localhost");
|
||||
let room_id = room_id!("!test:localhost");
|
||||
let event_id = event_id!("$1234localhost").to_owned();
|
||||
let room_id = room_id!("!test:localhost").to_owned();
|
||||
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let alice = ReadOnlyAccount::new(alice_id(), alice_device_id());
|
||||
let alice_store: Box<dyn CryptoStore> = Box::new(MemoryStore::new());
|
||||
let alice_identity = PrivateCrossSigningIdentity::empty(alice_id());
|
||||
let alice_identity = PrivateCrossSigningIdentity::empty(alice_id().to_owned());
|
||||
|
||||
let alice_store = VerificationStore { account: alice, inner: alice_store.into() };
|
||||
|
||||
let bob = ReadOnlyAccount::new(&bob_id(), &bob_device_id());
|
||||
let bob = ReadOnlyAccount::new(bob_id(), bob_device_id());
|
||||
let bob_store: Box<dyn CryptoStore> = Box::new(MemoryStore::new());
|
||||
let bob_identity = PrivateCrossSigningIdentity::empty(alice_id());
|
||||
let bob_identity = PrivateCrossSigningIdentity::empty(alice_id().to_owned());
|
||||
|
||||
let bob_store = VerificationStore { account: bob.clone(), inner: bob_store.into() };
|
||||
|
||||
let content =
|
||||
VerificationRequest::request(bob.user_id(), bob.device_id(), &alice_id(), None);
|
||||
VerificationRequest::request(bob.user_id(), bob.device_id(), alice_id(), None);
|
||||
|
||||
let flow_id = FlowId::InRoom(room_id, event_id);
|
||||
|
||||
@@ -1326,7 +1326,7 @@ mod test {
|
||||
bob_identity,
|
||||
bob_store,
|
||||
flow_id.clone(),
|
||||
&alice_id(),
|
||||
alice_id(),
|
||||
vec![],
|
||||
None,
|
||||
);
|
||||
@@ -1335,7 +1335,7 @@ mod test {
|
||||
VerificationCache::new(),
|
||||
alice_identity,
|
||||
alice_store,
|
||||
&bob_id(),
|
||||
bob_id(),
|
||||
flow_id,
|
||||
&(&content).into(),
|
||||
);
|
||||
@@ -1343,7 +1343,7 @@ mod test {
|
||||
let content: OutgoingContent = alice_request.accept().unwrap().try_into().unwrap();
|
||||
let content = ReadyContent::try_from(&content).unwrap();
|
||||
|
||||
bob_request.receive_ready(&alice_id(), &content);
|
||||
bob_request.receive_ready(alice_id(), &content);
|
||||
|
||||
assert!(bob_request.is_ready());
|
||||
assert!(alice_request.is_ready());
|
||||
@@ -1354,18 +1354,18 @@ mod test {
|
||||
let event_id = event_id!("$1234localhost");
|
||||
let room_id = room_id!("!test:localhost");
|
||||
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let alice = ReadOnlyAccount::new(alice_id(), alice_device_id());
|
||||
let alice_device = ReadOnlyDevice::from_account(&alice).await;
|
||||
|
||||
let alice_store: Box<dyn CryptoStore> = Box::new(MemoryStore::new());
|
||||
let alice_identity = PrivateCrossSigningIdentity::empty(alice_id());
|
||||
let alice_identity = PrivateCrossSigningIdentity::empty(alice_id().to_owned());
|
||||
|
||||
let alice_store = VerificationStore { account: alice.clone(), inner: alice_store.into() };
|
||||
|
||||
let bob = ReadOnlyAccount::new(&bob_id(), &bob_device_id());
|
||||
let bob = ReadOnlyAccount::new(bob_id(), bob_device_id());
|
||||
let bob_device = ReadOnlyDevice::from_account(&bob).await;
|
||||
let bob_store: Box<dyn CryptoStore> = Box::new(MemoryStore::new());
|
||||
let bob_identity = PrivateCrossSigningIdentity::empty(alice_id());
|
||||
let bob_identity = PrivateCrossSigningIdentity::empty(alice_id().to_owned());
|
||||
|
||||
let bob_store = VerificationStore { account: bob.clone(), inner: bob_store.into() };
|
||||
|
||||
@@ -1378,7 +1378,7 @@ mod test {
|
||||
bob_store.save_changes(changes).await.unwrap();
|
||||
|
||||
let content =
|
||||
VerificationRequest::request(bob.user_id(), bob.device_id(), &alice_id(), None);
|
||||
VerificationRequest::request(bob.user_id(), bob.device_id(), alice_id(), None);
|
||||
let flow_id = FlowId::from((room_id, event_id));
|
||||
|
||||
let bob_request = VerificationRequest::new(
|
||||
@@ -1386,7 +1386,7 @@ mod test {
|
||||
bob_identity,
|
||||
bob_store,
|
||||
flow_id.clone(),
|
||||
&alice_id(),
|
||||
alice_id(),
|
||||
vec![],
|
||||
None,
|
||||
);
|
||||
@@ -1395,7 +1395,7 @@ mod test {
|
||||
VerificationCache::new(),
|
||||
alice_identity,
|
||||
alice_store,
|
||||
&bob_id(),
|
||||
bob_id(),
|
||||
flow_id,
|
||||
&(&content).into(),
|
||||
);
|
||||
@@ -1403,7 +1403,7 @@ mod test {
|
||||
let content: OutgoingContent = alice_request.accept().unwrap().try_into().unwrap();
|
||||
let content = ReadyContent::try_from(&content).unwrap();
|
||||
|
||||
bob_request.receive_ready(&alice_id(), &content);
|
||||
bob_request.receive_ready(alice_id(), &content);
|
||||
|
||||
assert!(bob_request.is_ready());
|
||||
assert!(alice_request.is_ready());
|
||||
@@ -1423,18 +1423,18 @@ mod test {
|
||||
|
||||
#[async_test]
|
||||
async fn test_requesting_until_sas_to_device() {
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let alice = ReadOnlyAccount::new(alice_id(), alice_device_id());
|
||||
let alice_device = ReadOnlyDevice::from_account(&alice).await;
|
||||
|
||||
let alice_store: Box<dyn CryptoStore> = Box::new(MemoryStore::new());
|
||||
let alice_identity = PrivateCrossSigningIdentity::empty(alice_id());
|
||||
let alice_identity = PrivateCrossSigningIdentity::empty(alice_id().to_owned());
|
||||
|
||||
let alice_store = VerificationStore { account: alice.clone(), inner: alice_store.into() };
|
||||
|
||||
let bob = ReadOnlyAccount::new(&bob_id(), &bob_device_id());
|
||||
let bob = ReadOnlyAccount::new(bob_id(), bob_device_id());
|
||||
let bob_device = ReadOnlyDevice::from_account(&bob).await;
|
||||
let bob_store: Box<dyn CryptoStore> = Box::new(MemoryStore::new());
|
||||
let bob_identity = PrivateCrossSigningIdentity::empty(alice_id());
|
||||
let bob_identity = PrivateCrossSigningIdentity::empty(alice_id().to_owned());
|
||||
|
||||
let mut changes = Changes::default();
|
||||
changes.devices.new.push(bob_device.clone());
|
||||
@@ -1453,7 +1453,7 @@ mod test {
|
||||
bob_identity,
|
||||
bob_store,
|
||||
flow_id,
|
||||
&alice_id(),
|
||||
alice_id(),
|
||||
vec![],
|
||||
None,
|
||||
);
|
||||
@@ -1467,7 +1467,7 @@ mod test {
|
||||
VerificationCache::new(),
|
||||
alice_identity,
|
||||
alice_store,
|
||||
&bob_id(),
|
||||
bob_id(),
|
||||
flow_id,
|
||||
&content,
|
||||
);
|
||||
@@ -1475,7 +1475,7 @@ mod test {
|
||||
let content: OutgoingContent = alice_request.accept().unwrap().try_into().unwrap();
|
||||
let content = ReadyContent::try_from(&content).unwrap();
|
||||
|
||||
bob_request.receive_ready(&alice_id(), &content);
|
||||
bob_request.receive_ready(alice_id(), &content);
|
||||
|
||||
assert!(bob_request.is_ready());
|
||||
assert!(alice_request.is_ready());
|
||||
|
||||
@@ -214,7 +214,7 @@ pub fn receive_mac_event(
|
||||
ids.other_device.device_id()
|
||||
);
|
||||
|
||||
let key_id: DeviceKeyId = match key_id.as_str().try_into() {
|
||||
let key_id: Box<DeviceKeyId> = match key_id.as_str().try_into() {
|
||||
Ok(id) => id,
|
||||
Err(_) => continue,
|
||||
};
|
||||
|
||||
@@ -134,8 +134,8 @@ impl InnerSas {
|
||||
}
|
||||
|
||||
pub fn start_in_room(
|
||||
event_id: EventId,
|
||||
room_id: RoomId,
|
||||
event_id: Box<EventId>,
|
||||
room_id: Box<RoomId>,
|
||||
account: ReadOnlyAccount,
|
||||
other_device: ReadOnlyDevice,
|
||||
own_identity: Option<ReadOnlyOwnUserIdentity>,
|
||||
|
||||
@@ -228,8 +228,8 @@ impl Sas {
|
||||
/// sent out through the server to the other device.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn start_in_room(
|
||||
flow_id: EventId,
|
||||
room_id: RoomId,
|
||||
flow_id: Box<EventId>,
|
||||
room_id: Box<RoomId>,
|
||||
private_identity: PrivateCrossSigningIdentity,
|
||||
other_device: ReadOnlyDevice,
|
||||
store: VerificationStore,
|
||||
@@ -557,7 +557,7 @@ impl AcceptSettings {
|
||||
mod test {
|
||||
use std::{convert::TryFrom, sync::Arc};
|
||||
|
||||
use ruma::{DeviceId, UserId};
|
||||
use ruma::{device_id, user_id, DeviceId, UserId};
|
||||
|
||||
use super::Sas;
|
||||
use crate::{
|
||||
@@ -570,28 +570,28 @@ mod test {
|
||||
ReadOnlyAccount, ReadOnlyDevice,
|
||||
};
|
||||
|
||||
fn alice_id() -> UserId {
|
||||
UserId::try_from("@alice:example.org").unwrap()
|
||||
fn alice_id() -> &'static UserId {
|
||||
user_id!("@alice:example.org")
|
||||
}
|
||||
|
||||
fn alice_device_id() -> Box<DeviceId> {
|
||||
"JLAFKJWSCS".into()
|
||||
fn alice_device_id() -> &'static DeviceId {
|
||||
device_id!("JLAFKJWSCS")
|
||||
}
|
||||
|
||||
fn bob_id() -> UserId {
|
||||
UserId::try_from("@bob:example.org").unwrap()
|
||||
fn bob_id() -> &'static UserId {
|
||||
user_id!("@bob:example.org")
|
||||
}
|
||||
|
||||
fn bob_device_id() -> Box<DeviceId> {
|
||||
"BOBDEVCIE".into()
|
||||
fn bob_device_id() -> &'static DeviceId {
|
||||
device_id!("BOBDEVCIE")
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn sas_wrapper_full() {
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let alice = ReadOnlyAccount::new(alice_id(), alice_device_id());
|
||||
let alice_device = ReadOnlyDevice::from_account(&alice).await;
|
||||
|
||||
let bob = ReadOnlyAccount::new(&bob_id(), &bob_device_id());
|
||||
let bob = ReadOnlyAccount::new(bob_id(), bob_device_id());
|
||||
let bob_device = ReadOnlyDevice::from_account(&bob).await;
|
||||
|
||||
let alice_store =
|
||||
@@ -603,7 +603,7 @@ mod test {
|
||||
let bob_store = VerificationStore { account: bob.clone(), inner: Arc::new(bob_store) };
|
||||
|
||||
let (alice, content) = Sas::start(
|
||||
PrivateCrossSigningIdentity::empty(alice_id()),
|
||||
PrivateCrossSigningIdentity::empty(alice_id().to_owned()),
|
||||
bob_device,
|
||||
alice_store,
|
||||
None,
|
||||
@@ -620,7 +620,7 @@ mod test {
|
||||
flow_id,
|
||||
&content,
|
||||
bob_store,
|
||||
PrivateCrossSigningIdentity::empty(bob_id()),
|
||||
PrivateCrossSigningIdentity::empty(bob_id().to_owned()),
|
||||
alice_device,
|
||||
None,
|
||||
None,
|
||||
|
||||
@@ -392,8 +392,8 @@ impl SasState<Created> {
|
||||
///
|
||||
/// * `other_identity` - The identity of the other user if one exists.
|
||||
pub fn new_in_room(
|
||||
room_id: RoomId,
|
||||
event_id: EventId,
|
||||
room_id: Box<RoomId>,
|
||||
event_id: Box<EventId>,
|
||||
account: ReadOnlyAccount,
|
||||
other_device: ReadOnlyDevice,
|
||||
own_identity: Option<ReadOnlyOwnUserIdentity>,
|
||||
@@ -1138,12 +1138,13 @@ mod test {
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use ruma::{
|
||||
device_id,
|
||||
events::key::verification::{
|
||||
accept::{AcceptMethod, ToDeviceKeyVerificationAcceptEventContent},
|
||||
start::{StartMethod, ToDeviceKeyVerificationStartEventContent},
|
||||
ShortAuthenticationString,
|
||||
},
|
||||
DeviceId, UserId,
|
||||
user_id, DeviceId, UserId,
|
||||
};
|
||||
use serde_json::json;
|
||||
|
||||
@@ -1153,27 +1154,27 @@ mod test {
|
||||
ReadOnlyAccount, ReadOnlyDevice,
|
||||
};
|
||||
|
||||
fn alice_id() -> UserId {
|
||||
UserId::try_from("@alice:example.org").unwrap()
|
||||
fn alice_id() -> &'static UserId {
|
||||
user_id!("@alice:example.org")
|
||||
}
|
||||
|
||||
fn alice_device_id() -> Box<DeviceId> {
|
||||
"JLAFKJWSCS".into()
|
||||
fn alice_device_id() -> &'static DeviceId {
|
||||
device_id!("JLAFKJWSCS")
|
||||
}
|
||||
|
||||
fn bob_id() -> UserId {
|
||||
UserId::try_from("@bob:example.org").unwrap()
|
||||
fn bob_id() -> &'static UserId {
|
||||
user_id!("@bob:example.org")
|
||||
}
|
||||
|
||||
fn bob_device_id() -> Box<DeviceId> {
|
||||
"BOBDEVCIE".into()
|
||||
fn bob_device_id() -> &'static DeviceId {
|
||||
device_id!("BOBDEVCIE")
|
||||
}
|
||||
|
||||
async fn get_sas_pair() -> (SasState<Created>, SasState<WeAccepted>) {
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let alice = ReadOnlyAccount::new(alice_id(), alice_device_id());
|
||||
let alice_device = ReadOnlyDevice::from_account(&alice).await;
|
||||
|
||||
let bob = ReadOnlyAccount::new(&bob_id(), &bob_device_id());
|
||||
let bob = ReadOnlyAccount::new(bob_id(), bob_device_id());
|
||||
let bob_device = ReadOnlyDevice::from_account(&bob).await;
|
||||
|
||||
let alice_sas = SasState::<Created>::new(alice.clone(), bob_device, None, None, None);
|
||||
@@ -1307,7 +1308,7 @@ mod test {
|
||||
|
||||
let content = bob.as_content();
|
||||
let content = AcceptContent::from(&content);
|
||||
let sender = UserId::try_from("@malory:example.org").unwrap();
|
||||
let sender = Box::<UserId>::try_from("@malory:example.org").unwrap();
|
||||
alice.into_accepted(&sender, &content).expect_err("Didn't cancel on a invalid sender");
|
||||
}
|
||||
|
||||
@@ -1353,10 +1354,10 @@ mod test {
|
||||
|
||||
#[tokio::test]
|
||||
async fn sas_from_start_unknown_method() {
|
||||
let alice = ReadOnlyAccount::new(&alice_id(), &alice_device_id());
|
||||
let alice = ReadOnlyAccount::new(alice_id(), alice_device_id());
|
||||
let alice_device = ReadOnlyDevice::from_account(&alice).await;
|
||||
|
||||
let bob = ReadOnlyAccount::new(&bob_id(), &bob_device_id());
|
||||
let bob = ReadOnlyAccount::new(bob_id(), bob_device_id());
|
||||
let bob_device = ReadOnlyDevice::from_account(&bob).await;
|
||||
|
||||
let alice_sas = SasState::<Created>::new(alice.clone(), bob_device, None, None, None);
|
||||
|
||||
@@ -18,6 +18,6 @@ appservice = []
|
||||
http = "0.2.4"
|
||||
lazy_static = "1.4.0"
|
||||
matrix-sdk-test-macros = { version = "0.1.0", path = "../matrix-sdk-test-macros" }
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "ac6ecc3e5", features = ["client-api-c"] }
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "6c4892664", features = ["client-api-c"] }
|
||||
serde = "1.0.126"
|
||||
serde_json = "1.0.64"
|
||||
|
||||
@@ -81,11 +81,11 @@ pub enum EventsJson {
|
||||
#[derive(Default)]
|
||||
pub struct EventBuilder {
|
||||
/// The events that determine the state of a `Room`.
|
||||
joined_room_events: HashMap<RoomId, Vec<AnySyncRoomEvent>>,
|
||||
joined_room_events: HashMap<Box<RoomId>, Vec<AnySyncRoomEvent>>,
|
||||
/// The events that determine the state of a `Room`.
|
||||
invited_room_events: HashMap<RoomId, Vec<AnySyncStateEvent>>,
|
||||
invited_room_events: HashMap<Box<RoomId>, Vec<AnySyncStateEvent>>,
|
||||
/// The events that determine the state of a `Room`.
|
||||
left_room_events: HashMap<RoomId, Vec<AnySyncRoomEvent>>,
|
||||
left_room_events: HashMap<Box<RoomId>, Vec<AnySyncRoomEvent>>,
|
||||
/// The presence events that determine the presence state of a `RoomMember`.
|
||||
presence_events: Vec<PresenceEvent>,
|
||||
/// The state events that determine the state of a `Room`.
|
||||
@@ -140,7 +140,7 @@ impl EventBuilder {
|
||||
|
||||
let event = serde_json::from_value::<AnySyncRoomEvent>(val.clone()).unwrap();
|
||||
|
||||
self.add_joined_event(&room_id!("!SVkFJHzfwvuaIEawgC:localhost"), event);
|
||||
self.add_joined_event(room_id!("!SVkFJHzfwvuaIEawgC:localhost"), event);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ impl EventBuilder {
|
||||
}
|
||||
|
||||
fn add_joined_event(&mut self, room_id: &RoomId, event: AnySyncRoomEvent) {
|
||||
self.joined_room_events.entry(room_id.clone()).or_insert_with(Vec::new).push(event);
|
||||
self.joined_room_events.entry(room_id.to_owned()).or_insert_with(Vec::new).push(event);
|
||||
}
|
||||
|
||||
pub fn add_custom_invited_event(
|
||||
@@ -164,7 +164,7 @@ impl EventBuilder {
|
||||
event: serde_json::Value,
|
||||
) -> &mut Self {
|
||||
let event = serde_json::from_value::<AnySyncStateEvent>(event).unwrap();
|
||||
self.invited_room_events.entry(room_id.clone()).or_insert_with(Vec::new).push(event);
|
||||
self.invited_room_events.entry(room_id.to_owned()).or_insert_with(Vec::new).push(event);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ impl EventBuilder {
|
||||
event: serde_json::Value,
|
||||
) -> &mut Self {
|
||||
let event = serde_json::from_value::<AnySyncRoomEvent>(event).unwrap();
|
||||
self.left_room_events.entry(room_id.clone()).or_insert_with(Vec::new).push(event);
|
||||
self.left_room_events.entry(room_id.to_owned()).or_insert_with(Vec::new).push(event);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ impl EventBuilder {
|
||||
"events": self.state_events
|
||||
},
|
||||
"timeline": {
|
||||
"events": self.joined_room_events.remove(&main_room_id).unwrap_or_default(),
|
||||
"events": self.joined_room_events.remove(main_room_id).unwrap_or_default(),
|
||||
"limited": true,
|
||||
"prev_batch": prev_batch
|
||||
},
|
||||
@@ -248,9 +248,9 @@ impl EventBuilder {
|
||||
}
|
||||
});
|
||||
|
||||
let mut joined_rooms: HashMap<RoomId, serde_json::Value> = HashMap::new();
|
||||
let mut joined_rooms: HashMap<Box<RoomId>, serde_json::Value> = HashMap::new();
|
||||
|
||||
joined_rooms.insert(main_room_id, joined_room);
|
||||
joined_rooms.insert(main_room_id.to_owned(), joined_room);
|
||||
|
||||
for (room_id, events) in self.joined_room_events.drain() {
|
||||
let joined_room = serde_json::json!({
|
||||
@@ -277,7 +277,7 @@ impl EventBuilder {
|
||||
joined_rooms.insert(room_id, joined_room);
|
||||
}
|
||||
|
||||
let mut left_rooms: HashMap<RoomId, serde_json::Value> = HashMap::new();
|
||||
let mut left_rooms: HashMap<Box<RoomId>, serde_json::Value> = HashMap::new();
|
||||
|
||||
for (room_id, events) in self.left_room_events.drain() {
|
||||
let room = serde_json::json!({
|
||||
@@ -293,7 +293,7 @@ impl EventBuilder {
|
||||
left_rooms.insert(room_id, room);
|
||||
}
|
||||
|
||||
let mut invited_rooms: HashMap<RoomId, serde_json::Value> = HashMap::new();
|
||||
let mut invited_rooms: HashMap<Box<RoomId>, serde_json::Value> = HashMap::new();
|
||||
|
||||
for (room_id, events) in self.invited_room_events.drain() {
|
||||
let room = serde_json::json!({
|
||||
|
||||
@@ -76,7 +76,7 @@ default_features = false
|
||||
|
||||
[dependencies.ruma]
|
||||
git = "https://github.com/ruma/ruma"
|
||||
rev = "ac6ecc3e5"
|
||||
rev = "6c4892664"
|
||||
features = ["client-api-c", "compat", "unstable-pre-spec"]
|
||||
|
||||
[dependencies.tokio-stream]
|
||||
|
||||
@@ -33,7 +33,7 @@ use matrix_sdk::{
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
let alice = UserId::try_from("@alice:example.org")?;
|
||||
let alice = Box::<UserId>::try_from("@alice:example.org")?;
|
||||
let client = Client::new_from_user_id(&alice).await?;
|
||||
|
||||
// First we need to log in.
|
||||
|
||||
@@ -7,7 +7,7 @@ use std::{
|
||||
use matrix_sdk::{config::SyncSettings, ruma::UserId, Client, LoopCtrl};
|
||||
use url::Url;
|
||||
|
||||
async fn bootstrap(client: Client, user_id: UserId, password: String) {
|
||||
async fn bootstrap(client: Client, user_id: Box<UserId>, password: String) {
|
||||
println!("Bootstrapping a new cross signing identity, press enter to continue.");
|
||||
|
||||
let mut input = String::new();
|
||||
|
||||
@@ -9,7 +9,7 @@ use url::Url;
|
||||
#[derive(Debug)]
|
||||
#[allow(dead_code)]
|
||||
struct UserProfile {
|
||||
avatar_url: Option<MxcUri>,
|
||||
avatar_url: Option<Box<MxcUri>>,
|
||||
displayname: Option<String>,
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ async fn main() -> Result<(), matrix_sdk::Error> {
|
||||
|
||||
let client = login(homeserver_url, &username, &password).await?;
|
||||
|
||||
let user_id = UserId::try_from(username).expect("Couldn't parse the MXID");
|
||||
let user_id = Box::<UserId>::try_from(username).expect("Couldn't parse the MXID");
|
||||
let profile = get_profile(client, &user_id).await?;
|
||||
println!("{:#?}", profile);
|
||||
Ok(())
|
||||
|
||||
@@ -60,7 +60,7 @@ use ruma::{
|
||||
},
|
||||
assign,
|
||||
presence::PresenceState,
|
||||
DeviceIdBox, MxcUri, RoomId, RoomIdOrAliasId, ServerName, UInt, UserId,
|
||||
DeviceId, MxcUri, RoomId, RoomOrAliasId, ServerName, UInt, UserId,
|
||||
};
|
||||
use serde::de::DeserializeOwned;
|
||||
use tracing::{error, info, instrument, warn};
|
||||
@@ -121,12 +121,12 @@ pub(crate) struct ClientInner {
|
||||
/// Locks making sure we only have one group session sharing request in
|
||||
/// flight per room.
|
||||
#[cfg(feature = "encryption")]
|
||||
pub(crate) group_session_locks: DashMap<RoomId, Arc<Mutex<()>>>,
|
||||
pub(crate) group_session_locks: DashMap<Box<RoomId>, Arc<Mutex<()>>>,
|
||||
#[cfg(feature = "encryption")]
|
||||
/// Lock making sure we're only doing one key claim request at a time.
|
||||
pub(crate) key_claim_lock: Mutex<()>,
|
||||
pub(crate) members_request_locks: DashMap<RoomId, Arc<Mutex<()>>>,
|
||||
pub(crate) typing_notice_times: DashMap<RoomId, Instant>,
|
||||
pub(crate) members_request_locks: DashMap<Box<RoomId>, Arc<Mutex<()>>>,
|
||||
pub(crate) typing_notice_times: DashMap<Box<RoomId>, Instant>,
|
||||
/// Event handlers. See `register_event_handler`.
|
||||
event_handlers: RwLock<EventHandlerMap>,
|
||||
/// Custom event handler context. See `register_event_handler_context`.
|
||||
@@ -229,7 +229,7 @@ impl Client {
|
||||
/// use matrix_sdk::{Client, ruma::UserId};
|
||||
///
|
||||
/// // First let's try to construct an user id, presumably from user input.
|
||||
/// let alice = UserId::try_from("@alice:example.org")?;
|
||||
/// let alice = Box::<UserId>::try_from("@alice:example.org")?;
|
||||
///
|
||||
/// // Now let's try to discover the homeserver and create a client object.
|
||||
/// let client = Client::new_from_user_id(&alice).await?;
|
||||
@@ -356,13 +356,13 @@ impl Client {
|
||||
}
|
||||
|
||||
/// Get the user id of the current owner of the client.
|
||||
pub async fn user_id(&self) -> Option<UserId> {
|
||||
pub async fn user_id(&self) -> Option<Box<UserId>> {
|
||||
let session = self.inner.base_client.session().read().await;
|
||||
session.as_ref().cloned().map(|s| s.user_id)
|
||||
}
|
||||
|
||||
/// Get the device id that identifies the current session.
|
||||
pub async fn device_id(&self) -> Option<DeviceIdBox> {
|
||||
pub async fn device_id(&self) -> Option<Box<DeviceId>> {
|
||||
let session = self.inner.base_client.session().read().await;
|
||||
session.as_ref().map(|s| s.device_id.clone())
|
||||
}
|
||||
@@ -443,7 +443,7 @@ impl Client {
|
||||
/// }
|
||||
/// # })
|
||||
/// ```
|
||||
pub async fn avatar_url(&self) -> Result<Option<MxcUri>> {
|
||||
pub async fn avatar_url(&self) -> Result<Option<Box<MxcUri>>> {
|
||||
let user_id = self.user_id().await.ok_or(Error::AuthenticationRequired)?;
|
||||
let request = get_avatar_url::Request::new(&user_id);
|
||||
|
||||
@@ -1241,7 +1241,7 @@ impl Client {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// use matrix_sdk::{Client, Session, ruma::{DeviceIdBox, user_id}};
|
||||
/// use matrix_sdk::{Client, Session, ruma::{device_id, user_id}};
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
@@ -1251,8 +1251,8 @@ impl Client {
|
||||
///
|
||||
/// let session = Session {
|
||||
/// access_token: "My-Token".to_owned(),
|
||||
/// user_id: user_id!("@example:localhost"),
|
||||
/// device_id: DeviceIdBox::from("MYDEVICEID"),
|
||||
/// user_id: user_id!("@example:localhost").to_owned(),
|
||||
/// device_id: device_id!("MYDEVICEID").to_owned(),
|
||||
/// };
|
||||
///
|
||||
/// client.restore_login(session).await?;
|
||||
@@ -1263,7 +1263,7 @@ impl Client {
|
||||
/// [`Client::login()`] method returns:
|
||||
///
|
||||
/// ```no_run
|
||||
/// use matrix_sdk::{Client, Session, ruma::{DeviceIdBox, user_id}};
|
||||
/// use matrix_sdk::{Client, Session};
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
@@ -1433,7 +1433,7 @@ impl Client {
|
||||
/// An alias looks like `#name:example.com`.
|
||||
pub async fn join_room_by_id_or_alias(
|
||||
&self,
|
||||
alias: &RoomIdOrAliasId,
|
||||
alias: &RoomOrAliasId,
|
||||
server_names: &[Box<ServerName>],
|
||||
) -> HttpResult<join_room_by_id_or_alias::Response> {
|
||||
let request = assign!(join_room_by_id_or_alias::Request::new(alias), {
|
||||
@@ -1720,7 +1720,7 @@ impl Client {
|
||||
/// # client::r0::uiaa,
|
||||
/// # error::{FromHttpResponseError, ServerError},
|
||||
/// # },
|
||||
/// # assign,
|
||||
/// # assign, device_id,
|
||||
/// # },
|
||||
/// # Client, Error, config::SyncSettings,
|
||||
/// # };
|
||||
@@ -1731,7 +1731,7 @@ impl Client {
|
||||
/// # block_on(async {
|
||||
/// # let homeserver = Url::parse("http://localhost:8080")?;
|
||||
/// # let mut client = Client::new(homeserver)?;
|
||||
/// let devices = &["DEVICEID".into()];
|
||||
/// let devices = &[device_id!("DEVICEID").to_owned()];
|
||||
///
|
||||
/// if let Err(e) = client.delete_devices(devices, None).await {
|
||||
/// if let Some(info) = e.uiaa_response() {
|
||||
@@ -1748,7 +1748,7 @@ impl Client {
|
||||
/// # Result::<_, matrix_sdk::Error>::Ok(()) });
|
||||
pub async fn delete_devices(
|
||||
&self,
|
||||
devices: &[DeviceIdBox],
|
||||
devices: &[Box<DeviceId>],
|
||||
auth_data: Option<AuthData<'_>>,
|
||||
) -> HttpResult<delete_devices::Response> {
|
||||
let mut request = delete_devices::Request::new(devices);
|
||||
@@ -2371,7 +2371,7 @@ pub(crate) mod test {
|
||||
},
|
||||
error::{FromHttpResponseError, ServerError},
|
||||
},
|
||||
assign,
|
||||
assign, device_id,
|
||||
directory::Filter,
|
||||
event_id,
|
||||
events::{
|
||||
@@ -2394,8 +2394,8 @@ pub(crate) mod test {
|
||||
pub(crate) async fn logged_in_client() -> Client {
|
||||
let session = Session {
|
||||
access_token: "1234".to_owned(),
|
||||
user_id: user_id!("@example:localhost"),
|
||||
device_id: "DEVICEID".into(),
|
||||
user_id: user_id!("@example:localhost").to_owned(),
|
||||
device_id: device_id!("DEVICEID").to_owned(),
|
||||
};
|
||||
let homeserver = url::Url::parse(&mockito::server_url()).unwrap();
|
||||
let config = ClientConfig::new().request_config(RequestConfig::new().disable_retry());
|
||||
@@ -2422,7 +2422,7 @@ pub(crate) mod test {
|
||||
async fn successful_discovery() {
|
||||
let server_url = mockito::server_url();
|
||||
let domain = server_url.strip_prefix("http://").unwrap();
|
||||
let alice = UserId::try_from("@alice:".to_string() + domain).unwrap();
|
||||
let alice = Box::<UserId>::try_from("@alice:".to_string() + domain).unwrap();
|
||||
|
||||
let _m_well_known = mock("GET", "/.well-known/matrix/client")
|
||||
.with_status(200)
|
||||
@@ -2444,7 +2444,7 @@ pub(crate) mod test {
|
||||
async fn discovery_broken_server() {
|
||||
let server_url = mockito::server_url();
|
||||
let domain = server_url.strip_prefix("http://").unwrap();
|
||||
let alice = UserId::try_from("@alice:".to_string() + domain).unwrap();
|
||||
let alice = Box::<UserId>::try_from("@alice:".to_string() + domain).unwrap();
|
||||
|
||||
let _m = mock("GET", "/.well-known/matrix/client")
|
||||
.with_status(200)
|
||||
@@ -2630,15 +2630,15 @@ pub(crate) mod test {
|
||||
let client = logged_in_client().await;
|
||||
let session = client.session().await.unwrap();
|
||||
|
||||
let room = client.get_joined_room(&room_id);
|
||||
let room = client.get_joined_room(room_id);
|
||||
assert!(room.is_none());
|
||||
|
||||
client.sync_once(SyncSettings::default()).await.unwrap();
|
||||
|
||||
let room = client.get_left_room(&room_id);
|
||||
let room = client.get_left_room(room_id);
|
||||
assert!(room.is_none());
|
||||
|
||||
let room = client.get_joined_room(&room_id);
|
||||
let room = client.get_joined_room(room_id);
|
||||
assert!(room.is_some());
|
||||
|
||||
// test store reloads with correct room state from the sled store
|
||||
@@ -2651,7 +2651,7 @@ pub(crate) mod test {
|
||||
|
||||
// joined room reloaded from state store
|
||||
joined_client.sync_once(SyncSettings::default()).await.unwrap();
|
||||
let room = joined_client.get_joined_room(&room_id);
|
||||
let room = joined_client.get_joined_room(room_id);
|
||||
assert!(room.is_some());
|
||||
|
||||
let _m = mock("GET", Matcher::Regex(r"^/_matrix/client/r0/sync\?.*$".to_string()))
|
||||
@@ -2661,10 +2661,10 @@ pub(crate) mod test {
|
||||
|
||||
joined_client.sync_once(SyncSettings::default()).await.unwrap();
|
||||
|
||||
let room = joined_client.get_joined_room(&room_id);
|
||||
let room = joined_client.get_joined_room(room_id);
|
||||
assert!(room.is_none());
|
||||
|
||||
let room = joined_client.get_left_room(&room_id);
|
||||
let room = joined_client.get_left_room(room_id);
|
||||
assert!(room.is_some());
|
||||
}
|
||||
|
||||
@@ -2700,7 +2700,7 @@ pub(crate) mod test {
|
||||
|
||||
assert_eq!(client.homeserver().await, Url::parse(&mockito::server_url()).unwrap());
|
||||
|
||||
let room = client.get_joined_room(&room_id);
|
||||
let room = client.get_joined_room(room_id);
|
||||
assert!(room.is_some());
|
||||
}
|
||||
|
||||
@@ -2787,7 +2787,7 @@ pub(crate) mod test {
|
||||
assert_eq!(
|
||||
// this is the `join_by_room_id::Response` but since no PartialEq we check the RoomId
|
||||
// field
|
||||
client.join_room_by_id(&room_id).await.unwrap().room_id,
|
||||
client.join_room_by_id(room_id).await.unwrap().room_id,
|
||||
room_id
|
||||
);
|
||||
}
|
||||
@@ -2808,7 +2808,7 @@ pub(crate) mod test {
|
||||
// this is the `join_by_room_id::Response` but since no PartialEq we check the RoomId
|
||||
// field
|
||||
client
|
||||
.join_room_by_id_or_alias(&room_id, &["server.com".try_into().unwrap()])
|
||||
.join_room_by_id_or_alias(room_id, &["server.com".try_into().unwrap()])
|
||||
.await
|
||||
.unwrap()
|
||||
.room_id,
|
||||
@@ -2837,9 +2837,9 @@ pub(crate) mod test {
|
||||
let _response = client.sync_once(sync_settings).await.unwrap();
|
||||
|
||||
let user = user_id!("@example:localhost");
|
||||
let room = client.get_joined_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
let room = client.get_joined_room(room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
|
||||
room.invite_user_by_id(&user).await.unwrap();
|
||||
room.invite_user_by_id(user).await.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -2863,7 +2863,7 @@ pub(crate) mod test {
|
||||
|
||||
let _response = client.sync_once(sync_settings).await.unwrap();
|
||||
|
||||
let room = client.get_joined_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
let room = client.get_joined_room(room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
|
||||
room.invite_user_by_3pid(
|
||||
Invite3pidInit {
|
||||
@@ -2933,7 +2933,7 @@ pub(crate) mod test {
|
||||
|
||||
let _response = client.sync_once(sync_settings).await.unwrap();
|
||||
|
||||
let room = client.get_joined_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
let room = client.get_joined_room(room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
|
||||
room.leave().await.unwrap();
|
||||
}
|
||||
@@ -2960,9 +2960,9 @@ pub(crate) mod test {
|
||||
let _response = client.sync_once(sync_settings).await.unwrap();
|
||||
|
||||
let user = user_id!("@example:localhost");
|
||||
let room = client.get_joined_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
let room = client.get_joined_room(room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
|
||||
room.ban_user(&user, None).await.unwrap();
|
||||
room.ban_user(user, None).await.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -2987,9 +2987,9 @@ pub(crate) mod test {
|
||||
let _response = client.sync_once(sync_settings).await.unwrap();
|
||||
|
||||
let user = user_id!("@example:localhost");
|
||||
let room = client.get_joined_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
let room = client.get_joined_room(room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
|
||||
room.kick_user(&user, None).await.unwrap();
|
||||
room.kick_user(user, None).await.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -3013,7 +3013,7 @@ pub(crate) mod test {
|
||||
|
||||
let _response = client.sync_once(sync_settings).await.unwrap();
|
||||
|
||||
let room = client.get_left_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
let room = client.get_left_room(room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
|
||||
room.forget().await.unwrap();
|
||||
}
|
||||
@@ -3040,9 +3040,9 @@ pub(crate) mod test {
|
||||
let _response = client.sync_once(sync_settings).await.unwrap();
|
||||
|
||||
let event_id = event_id!("$xxxxxx:example.org");
|
||||
let room = client.get_joined_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
let room = client.get_joined_room(room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
|
||||
room.read_receipt(&event_id).await.unwrap();
|
||||
room.read_receipt(event_id).await.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -3068,9 +3068,9 @@ pub(crate) mod test {
|
||||
let _response = client.sync_once(sync_settings).await.unwrap();
|
||||
|
||||
let event_id = event_id!("$xxxxxx:example.org");
|
||||
let room = client.get_joined_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
let room = client.get_joined_room(room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
|
||||
room.read_marker(&event_id, None).await.unwrap();
|
||||
room.read_marker(event_id, None).await.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -3094,7 +3094,7 @@ pub(crate) mod test {
|
||||
|
||||
let _response = client.sync_once(sync_settings).await.unwrap();
|
||||
|
||||
let room = client.get_joined_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
let room = client.get_joined_room(room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
|
||||
room.typing_notice(true).await.unwrap();
|
||||
}
|
||||
@@ -3123,11 +3123,11 @@ pub(crate) mod test {
|
||||
|
||||
let room_id = room_id!("!SVkFJHzfwvuaIEawgC:localhost");
|
||||
|
||||
let room = client.get_joined_room(&room_id).unwrap();
|
||||
let room = client.get_joined_room(room_id).unwrap();
|
||||
|
||||
let avatar_url = mxc_uri!("mxc://example.org/avA7ar");
|
||||
let member_event = assign!(RoomMemberEventContent::new(MembershipState::Join), {
|
||||
avatar_url: Some(avatar_url)
|
||||
avatar_url: Some(avatar_url.to_owned())
|
||||
});
|
||||
let response = room.send_state_event(member_event, "").await.unwrap();
|
||||
assert_eq!(event_id!("$h29iv0s8:example.com"), response.event_id);
|
||||
@@ -3155,7 +3155,7 @@ pub(crate) mod test {
|
||||
|
||||
let _response = client.sync_once(sync_settings).await.unwrap();
|
||||
|
||||
let room = client.get_joined_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
let room = client.get_joined_room(room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
|
||||
let content = RoomMessageEventContent::text_plain("Hello world");
|
||||
let txn_id = Uuid::new_v4();
|
||||
@@ -3195,7 +3195,7 @@ pub(crate) mod test {
|
||||
|
||||
let _response = client.sync_once(sync_settings).await.unwrap();
|
||||
|
||||
let room = client.get_joined_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
let room = client.get_joined_room(room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
|
||||
let mut media = Cursor::new("Hello world");
|
||||
|
||||
@@ -3228,13 +3228,13 @@ pub(crate) mod test {
|
||||
|
||||
let _response = client.sync_once(sync_settings).await.unwrap();
|
||||
|
||||
let room = client.get_joined_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
let room = client.get_joined_room(room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
|
||||
let event_id = event_id!("$xxxxxxxx:example.com");
|
||||
|
||||
let txn_id = Uuid::new_v4();
|
||||
let reason = Some("Indecent material");
|
||||
let response = room.redact(&event_id, reason, Some(txn_id)).await.unwrap();
|
||||
let response = room.redact(event_id, reason, Some(txn_id)).await.unwrap();
|
||||
|
||||
assert_eq!(event_id!("$h29iv0s8:example.com"), response.event_id)
|
||||
}
|
||||
@@ -3259,7 +3259,7 @@ pub(crate) mod test {
|
||||
|
||||
let _response = client.sync_once(sync_settings).await.unwrap();
|
||||
|
||||
let room = client.get_joined_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
let room = client.get_joined_room(room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
let members: Vec<RoomMember> = room.active_members().await.unwrap();
|
||||
|
||||
assert_eq!(1, members.len());
|
||||
@@ -3278,7 +3278,7 @@ pub(crate) mod test {
|
||||
|
||||
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
|
||||
let _response = client.sync_once(sync_settings).await.unwrap();
|
||||
let room = client.get_joined_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
let room = client.get_joined_room(room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
|
||||
assert_eq!("example2", room.display_name().await.unwrap());
|
||||
}
|
||||
@@ -3299,7 +3299,7 @@ pub(crate) mod test {
|
||||
assert!(client.left_rooms().is_empty());
|
||||
assert!(!client.invited_rooms().is_empty());
|
||||
|
||||
assert!(client.get_invited_room(&room_id!("!696r7674:example.com")).is_some());
|
||||
assert!(client.get_invited_room(room_id!("!696r7674:example.com")).is_some());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -3318,7 +3318,7 @@ pub(crate) mod test {
|
||||
assert!(!client.left_rooms().is_empty());
|
||||
assert!(client.invited_rooms().is_empty());
|
||||
|
||||
assert!(client.get_left_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost")).is_some())
|
||||
assert!(client.get_left_room(room_id!("!SVkFJHzfwvuaIEawgC:localhost")).is_some())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -3355,7 +3355,7 @@ pub(crate) mod test {
|
||||
|
||||
let _response = client.sync_once(sync_settings).await.unwrap();
|
||||
|
||||
let room = client.get_joined_room(&room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
let room = client.get_joined_room(room_id!("!SVkFJHzfwvuaIEawgC:localhost")).unwrap();
|
||||
|
||||
assert_eq!("tutorial".to_string(), room.display_name().await.unwrap());
|
||||
|
||||
@@ -3368,7 +3368,7 @@ pub(crate) mod test {
|
||||
|
||||
let _response = client.sync_once(SyncSettings::new()).await.unwrap();
|
||||
|
||||
let invited_room = client.get_invited_room(&room_id!("!696r7674:example.com")).unwrap();
|
||||
let invited_room = client.get_invited_room(room_id!("!696r7674:example.com")).unwrap();
|
||||
|
||||
assert_eq!("My Room Name".to_string(), invited_room.display_name().await.unwrap());
|
||||
}
|
||||
@@ -3403,7 +3403,7 @@ pub(crate) mod test {
|
||||
.with_body(test_json::LOGOUT.to_string())
|
||||
.create();
|
||||
|
||||
let devices = &["DEVICEID".into()];
|
||||
let devices = &[device_id!("DEVICEID").to_owned()];
|
||||
|
||||
if let Err(e) = client.delete_devices(devices, None).await {
|
||||
if let Some(info) = e.uiaa_response() {
|
||||
@@ -3483,7 +3483,7 @@ pub(crate) mod test {
|
||||
let client = logged_in_client().await;
|
||||
|
||||
let request = MediaRequest {
|
||||
media_type: MediaType::Uri(mxc_uri!("mxc://localhost/textfile")),
|
||||
media_type: MediaType::Uri(mxc_uri!("mxc://localhost/textfile").to_owned()),
|
||||
format: MediaFormat::File,
|
||||
};
|
||||
|
||||
@@ -3508,7 +3508,7 @@ pub(crate) mod test {
|
||||
|
||||
let event_content = ImageMessageEventContent::plain(
|
||||
"filename.jpg".into(),
|
||||
mxc_uri!("mxc://example.org/image"),
|
||||
mxc_uri!("mxc://example.org/image").to_owned(),
|
||||
Some(Box::new(assign!(ImageInfo::new(), {
|
||||
height: Some(uint!(398)),
|
||||
width: Some(uint!(394)),
|
||||
@@ -3570,8 +3570,8 @@ pub(crate) mod test {
|
||||
|
||||
let session = Session {
|
||||
access_token: "1234".to_owned(),
|
||||
user_id: user_id!("@example:localhost"),
|
||||
device_id: "DEVICEID".into(),
|
||||
user_id: user_id!("@example:localhost").to_owned(),
|
||||
device_id: device_id!("DEVICEID").to_owned(),
|
||||
};
|
||||
|
||||
let sync = json!({
|
||||
@@ -3638,12 +3638,12 @@ pub(crate) mod test {
|
||||
let client = Client::new_with_config(homeserver.clone(), config).unwrap();
|
||||
client.restore_login(session.clone()).await.unwrap();
|
||||
|
||||
let room = client.get_joined_room(&room_id);
|
||||
let room = client.get_joined_room(room_id);
|
||||
assert!(room.is_none());
|
||||
|
||||
client.sync_once(SyncSettings::default()).await.unwrap();
|
||||
|
||||
let room = client.get_joined_room(&room_id).unwrap();
|
||||
let room = client.get_joined_room(room_id).unwrap();
|
||||
|
||||
let state_events = room.get_state_events(EventType::RoomEncryption).await.unwrap();
|
||||
assert_eq!(state_events.len(), 1);
|
||||
|
||||
@@ -18,7 +18,7 @@ use matrix_sdk_base::crypto::{
|
||||
store::CryptoStoreError, Device as BaseDevice, LocalTrust, ReadOnlyDevice,
|
||||
UserDevices as BaseUserDevices,
|
||||
};
|
||||
use ruma::{events::key::verification::VerificationMethod, DeviceId, DeviceIdBox};
|
||||
use ruma::{events::key::verification::VerificationMethod, DeviceId};
|
||||
|
||||
use super::ManualVerifyError;
|
||||
use crate::{
|
||||
@@ -82,14 +82,14 @@ impl Device {
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use std::convert::TryFrom;
|
||||
/// # use matrix_sdk::{Client, ruma::UserId};
|
||||
/// # use matrix_sdk::{Client, ruma::{device_id, UserId}};
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # let alice = UserId::try_from("@alice:example.org")?;
|
||||
/// # let alice = Box::<UserId>::try_from("@alice:example.org")?;
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver)?;
|
||||
/// let device = client.get_device(&alice, "DEVICEID".into()).await?;
|
||||
/// let device = client.get_device(&alice, device_id!("DEVICEID")).await?;
|
||||
///
|
||||
/// if let Some(device) = device {
|
||||
/// let verification = device.request_verification().await?;
|
||||
@@ -127,17 +127,17 @@ impl Device {
|
||||
/// # use matrix_sdk::{
|
||||
/// # Client,
|
||||
/// # ruma::{
|
||||
/// # UserId,
|
||||
/// # device_id, UserId,
|
||||
/// # events::key::verification::VerificationMethod,
|
||||
/// # }
|
||||
/// # };
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # let alice = UserId::try_from("@alice:example.org")?;
|
||||
/// # let alice = Box::<UserId>::try_from("@alice:example.org")?;
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver)?;
|
||||
/// let device = client.get_device(&alice, "DEVICEID".into()).await?;
|
||||
/// let device = client.get_device(&alice, device_id!("DEVICEID")).await?;
|
||||
///
|
||||
/// // We don't want to support showing a QR code, we only support SAS
|
||||
/// // verification
|
||||
@@ -172,14 +172,14 @@ impl Device {
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use std::convert::TryFrom;
|
||||
/// # use matrix_sdk::{Client, ruma::UserId};
|
||||
/// # use matrix_sdk::{Client, ruma::{device_id, UserId}};
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # let alice = UserId::try_from("@alice:example.org")?;
|
||||
/// # let alice = Box::<UserId>::try_from("@alice:example.org")?;
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver)?;
|
||||
/// let device = client.get_device(&alice, "DEVICEID".into()).await?;
|
||||
/// let device = client.get_device(&alice, device_id!("DEVICEID")).await?;
|
||||
///
|
||||
/// if let Some(device) = device {
|
||||
/// let verification = device.start_verification().await?;
|
||||
@@ -233,17 +233,17 @@ impl Device {
|
||||
/// # use matrix_sdk::{
|
||||
/// # Client,
|
||||
/// # ruma::{
|
||||
/// # UserId,
|
||||
/// # device_id, UserId,
|
||||
/// # events::key::verification::VerificationMethod,
|
||||
/// # }
|
||||
/// # };
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # let alice = UserId::try_from("@alice:example.org")?;
|
||||
/// # let alice = Box::<UserId>::try_from("@alice:example.org")?;
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver)?;
|
||||
/// let device = client.get_device(&alice, "DEVICEID".into()).await?;
|
||||
/// let device = client.get_device(&alice, device_id!("DEVICEID")).await?;
|
||||
///
|
||||
/// if let Some(device) = device {
|
||||
/// device.verify().await?;
|
||||
@@ -348,17 +348,17 @@ impl Device {
|
||||
/// # use matrix_sdk::{
|
||||
/// # Client,
|
||||
/// # ruma::{
|
||||
/// # UserId,
|
||||
/// # device_id, UserId,
|
||||
/// # events::key::verification::VerificationMethod,
|
||||
/// # }
|
||||
/// # };
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # let alice = UserId::try_from("@alice:example.org")?;
|
||||
/// # let alice = Box::<UserId>::try_from("@alice:example.org")?;
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver)?;
|
||||
/// let device = client.get_device(&alice, "DEVICEID".into()).await?;
|
||||
/// let device = client.get_device(&alice, device_id!("DEVICEID")).await?;
|
||||
///
|
||||
/// if let Some(device) = device {
|
||||
/// if device.verified() {
|
||||
@@ -410,7 +410,7 @@ impl UserDevices {
|
||||
}
|
||||
|
||||
/// Iterator over all the device ids of the user devices.
|
||||
pub fn keys(&self) -> impl Iterator<Item = &DeviceIdBox> {
|
||||
pub fn keys(&self) -> impl Iterator<Item = &Box<DeviceId>> {
|
||||
self.inner.keys()
|
||||
}
|
||||
|
||||
|
||||
@@ -36,14 +36,14 @@
|
||||
//!
|
||||
//! ```no_run
|
||||
//! # use std::convert::TryFrom;
|
||||
//! # use matrix_sdk::{Client, ruma::UserId};
|
||||
//! # use matrix_sdk::{Client, ruma::{device_id, UserId}};
|
||||
//! # use url::Url;
|
||||
//! # use futures::executor::block_on;
|
||||
//! # let alice = UserId::try_from("@alice:example.org").unwrap();
|
||||
//! # let alice = Box::<UserId>::try_from("@alice:example.org").unwrap();
|
||||
//! # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
//! # let client = Client::new(homeserver).unwrap();
|
||||
//! # block_on(async {
|
||||
//! let device = client.get_device(&alice, "DEVICEID".into()).await?;
|
||||
//! let device = client.get_device(&alice, device_id!("DEVICEID")).await?;
|
||||
//!
|
||||
//! if let Some(device) = device {
|
||||
//! // Let's request the device to be verified.
|
||||
@@ -65,7 +65,7 @@
|
||||
//! # use matrix_sdk::{Client, ruma::UserId};
|
||||
//! # use url::Url;
|
||||
//! # use futures::executor::block_on;
|
||||
//! # let alice = UserId::try_from("@alice:example.org").unwrap();
|
||||
//! # let alice = Box::<UserId>::try_from("@alice:example.org").unwrap();
|
||||
//! # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
//! # let client = Client::new(homeserver).unwrap();
|
||||
//! # block_on(async {
|
||||
@@ -116,5 +116,5 @@ pub enum RequestVerificationError {
|
||||
/// Verifying other users requires having a DM open with them, this error
|
||||
/// signals that we didn't have a DM and that we failed to create one.
|
||||
#[error("Couldn't create a DM with user {0} where the verification should take place")]
|
||||
RoomCreation(ruma::UserId),
|
||||
RoomCreation(Box<ruma::UserId>),
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ impl UserIdentity {
|
||||
/// # use std::convert::TryFrom;
|
||||
/// # use matrix_sdk::{Client, ruma::UserId};
|
||||
/// # use url::Url;
|
||||
/// # let alice = UserId::try_from("@alice:example.org").unwrap();
|
||||
/// # let alice = Box::<UserId>::try_from("@alice:example.org").unwrap();
|
||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
/// # let client = Client::new(homeserver).unwrap();
|
||||
/// # futures::executor::block_on(async {
|
||||
@@ -145,7 +145,7 @@ impl UserIdentity {
|
||||
/// # use std::convert::TryFrom;
|
||||
/// # use matrix_sdk::{Client, ruma::UserId};
|
||||
/// # use url::Url;
|
||||
/// # let alice = UserId::try_from("@alice:example.org").unwrap();
|
||||
/// # let alice = Box::<UserId>::try_from("@alice:example.org").unwrap();
|
||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
/// # let client = Client::new(homeserver).unwrap();
|
||||
/// # futures::executor::block_on(async {
|
||||
@@ -204,7 +204,7 @@ impl UserIdentity {
|
||||
/// # };
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = UserId::try_from("@alice:example.org").unwrap();
|
||||
/// # let alice = Box::<UserId>::try_from("@alice:example.org").unwrap();
|
||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
/// # let client = Client::new(homeserver).unwrap();
|
||||
/// # block_on(async {
|
||||
@@ -283,7 +283,7 @@ impl UserIdentity {
|
||||
/// # };
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = UserId::try_from("@alice:example.org").unwrap();
|
||||
/// # let alice = Box::<UserId>::try_from("@alice:example.org").unwrap();
|
||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
/// # let client = Client::new(homeserver).unwrap();
|
||||
/// # block_on(async {
|
||||
@@ -326,7 +326,7 @@ impl UserIdentity {
|
||||
/// # };
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = UserId::try_from("@alice:example.org").unwrap();
|
||||
/// # let alice = Box::<UserId>::try_from("@alice:example.org").unwrap();
|
||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
/// # let client = Client::new(homeserver).unwrap();
|
||||
/// # block_on(async {
|
||||
@@ -366,7 +366,7 @@ impl UserIdentity {
|
||||
/// # };
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # let alice = UserId::try_from("@alice:example.org").unwrap();
|
||||
/// # let alice = Box::<UserId>::try_from("@alice:example.org").unwrap();
|
||||
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||
/// # let client = Client::new(homeserver).unwrap();
|
||||
/// # block_on(async {
|
||||
|
||||
@@ -251,7 +251,7 @@ use std::{
|
||||
collections::{BTreeMap, HashSet},
|
||||
io::{Read,Write},
|
||||
path::PathBuf,
|
||||
result::Result as StdResult,
|
||||
result::Result as StdResult, iter,
|
||||
};
|
||||
|
||||
use futures_util::stream::{self, StreamExt};
|
||||
@@ -277,7 +277,7 @@ use ruma::{
|
||||
assign,
|
||||
events::{AnyMessageEvent, AnyRoomEvent, AnySyncMessageEvent, EventType},
|
||||
serde::Raw,
|
||||
DeviceId, DeviceIdBox, UserId,
|
||||
DeviceId, UserId,
|
||||
};
|
||||
use tracing::{debug, instrument, trace, warn};
|
||||
|
||||
@@ -316,7 +316,7 @@ impl Client {
|
||||
/// Tracked users are users for which we keep the device list of E2EE
|
||||
/// capable devices up to date.
|
||||
#[cfg(feature = "encryption")]
|
||||
pub async fn tracked_users(&self) -> HashSet<UserId> {
|
||||
pub async fn tracked_users(&self) -> HashSet<Box<UserId>> {
|
||||
self.olm_machine().await.map(|o| o.tracked_users()).unwrap_or_default()
|
||||
}
|
||||
|
||||
@@ -366,14 +366,14 @@ impl Client {
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use std::convert::TryFrom;
|
||||
/// # use matrix_sdk::{Client, ruma::UserId};
|
||||
/// # use matrix_sdk::{Client, ruma::{device_id, UserId}};
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # let alice = UserId::try_from("@alice:example.org")?;
|
||||
/// # let alice = Box::<UserId>::try_from("@alice:example.org")?;
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver)?;
|
||||
/// if let Some(device) = client.get_device(&alice, "DEVICEID".into()).await? {
|
||||
/// if let Some(device) = client.get_device(&alice, device_id!("DEVICEID")).await? {
|
||||
/// println!("{:?}", device.verified());
|
||||
///
|
||||
/// if !device.verified() {
|
||||
@@ -410,7 +410,7 @@ impl Client {
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # let alice = UserId::try_from("@alice:example.org")?;
|
||||
/// # let alice = Box::<UserId>::try_from("@alice:example.org")?;
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver)?;
|
||||
/// let devices = client.get_user_devices(&alice).await?;
|
||||
@@ -449,7 +449,7 @@ impl Client {
|
||||
/// # use url::Url;
|
||||
/// # use futures::executor::block_on;
|
||||
/// # block_on(async {
|
||||
/// # let alice = UserId::try_from("@alice:example.org")?;
|
||||
/// # let alice = Box::<UserId>::try_from("@alice:example.org")?;
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver)?;
|
||||
/// let user = client.get_user_identity(&alice).await?;
|
||||
@@ -505,7 +505,7 @@ impl Client {
|
||||
/// # use futures::executor::block_on;
|
||||
/// # use serde_json::json;
|
||||
/// # block_on(async {
|
||||
/// # let user_id = UserId::try_from("@alice:example.org")?;
|
||||
/// # let user_id = Box::<UserId>::try_from("@alice:example.org")?;
|
||||
/// # let homeserver = Url::parse("http://example.com")?;
|
||||
/// # let client = Client::new(homeserver)?;
|
||||
/// if let Err(e) = client.bootstrap_cross_signing(None).await {
|
||||
@@ -590,7 +590,7 @@ impl Client {
|
||||
/// let room_id = room_id!("!test:localhost");
|
||||
///
|
||||
/// client
|
||||
/// .export_keys(path, "secret-passphrase", |s| s.room_id() == &room_id)
|
||||
/// .export_keys(path, "secret-passphrase", |s| s.room_id() == room_id)
|
||||
/// .await?;
|
||||
/// # anyhow::Result::<()>::Ok(()) });
|
||||
/// ```
|
||||
@@ -722,7 +722,7 @@ impl Client {
|
||||
pub(crate) async fn keys_query(
|
||||
&self,
|
||||
request_id: &Uuid,
|
||||
device_keys: BTreeMap<UserId, Vec<DeviceIdBox>>,
|
||||
device_keys: BTreeMap<Box<UserId>, Vec<Box<DeviceId>>>,
|
||||
) -> Result<get_keys::Response> {
|
||||
let request = assign!(get_keys::Request::new(), { device_keys });
|
||||
|
||||
@@ -791,7 +791,7 @@ impl Client {
|
||||
}
|
||||
|
||||
#[cfg(feature = "encryption")]
|
||||
pub(crate) async fn create_dm_room(&self, user_id: UserId) -> Result<Option<room::Joined>> {
|
||||
pub(crate) async fn create_dm_room(&self, user_id: Box<UserId>) -> Result<Option<room::Joined>> {
|
||||
use ruma::{
|
||||
api::client::r0::room::create_room::RoomPreset,
|
||||
events::AnyGlobalAccountDataEventContent,
|
||||
@@ -953,7 +953,7 @@ impl Client {
|
||||
rooms.iter().map(|r| (r.room_id().to_owned(), r.direct_target())).collect();
|
||||
trace!(rooms =? room_pairs, "Finding direct room");
|
||||
|
||||
let room = rooms.into_iter().find(|r| r.direct_target().as_ref() == Some(user_id));
|
||||
let room = rooms.into_iter().find(|r| r.direct_target().as_deref() == Some(user_id));
|
||||
|
||||
trace!(room =? room, "Found room");
|
||||
room
|
||||
@@ -1011,7 +1011,7 @@ impl Client {
|
||||
|
||||
// This is needed because sometimes we need to automatically
|
||||
// claim some one-time keys to unwedge an existing Olm session.
|
||||
if let Err(e) = self.claim_one_time_keys([].iter()).await {
|
||||
if let Err(e) = self.claim_one_time_keys(iter::empty()).await {
|
||||
warn!("Error while claiming one-time keys {:?}", e);
|
||||
}
|
||||
|
||||
|
||||
@@ -547,7 +547,7 @@ mod test {
|
||||
.add_ephemeral(EventsJson::Typing)
|
||||
.add_state_event(EventsJson::PowerLevels)
|
||||
.add_custom_invited_event(
|
||||
&room_id!("!test_invited:example.org"),
|
||||
room_id!("!test_invited:example.org"),
|
||||
json!({
|
||||
"content": {
|
||||
"avatar_url": "mxc://example.org/SEsfnsuifSDFSSEF",
|
||||
|
||||
@@ -193,7 +193,7 @@ impl HttpClient {
|
||||
.try_into_http_request_with_user_id::<BytesMut>(
|
||||
&self.homeserver.read().await.to_string(),
|
||||
access_token,
|
||||
user_id,
|
||||
&user_id,
|
||||
)?
|
||||
.map(|body| body.freeze());
|
||||
|
||||
|
||||
@@ -178,7 +178,7 @@ impl Common {
|
||||
self.client
|
||||
.inner
|
||||
.members_request_locks
|
||||
.insert(self.inner.room_id().clone(), mutex.clone());
|
||||
.insert(self.inner.room_id().to_owned(), mutex.clone());
|
||||
|
||||
let _guard = mutex.lock().await;
|
||||
|
||||
|
||||
@@ -199,7 +199,7 @@ impl Joined {
|
||||
self.client
|
||||
.inner
|
||||
.typing_notice_times
|
||||
.insert(self.inner.room_id().clone(), Instant::now());
|
||||
.insert(self.inner.room_id().to_owned(), Instant::now());
|
||||
Typing::Yes(TYPING_NOTICE_TIMEOUT)
|
||||
} else {
|
||||
self.client.inner.typing_notice_times.remove(self.inner.room_id());
|
||||
@@ -325,7 +325,7 @@ impl Joined {
|
||||
self.client
|
||||
.inner
|
||||
.group_session_locks
|
||||
.insert(self.inner.room_id().clone(), mutex.clone());
|
||||
.insert(self.inner.room_id().to_owned(), mutex.clone());
|
||||
|
||||
let _guard = mutex.lock().await;
|
||||
|
||||
@@ -333,7 +333,7 @@ impl Joined {
|
||||
let joined = self.client.store().get_joined_user_ids(self.inner.room_id()).await?;
|
||||
let invited =
|
||||
self.client.store().get_invited_user_ids(self.inner.room_id()).await?;
|
||||
let members = joined.iter().chain(&invited);
|
||||
let members = joined.iter().chain(&invited).map(Deref::deref);
|
||||
self.client.claim_one_time_keys(members).await?;
|
||||
};
|
||||
|
||||
@@ -684,7 +684,7 @@ impl Joined {
|
||||
/// # let mut client = matrix_sdk::Client::new(homeserver)?;
|
||||
/// # let room_id = matrix_sdk::ruma::room_id!("!test:localhost");
|
||||
///
|
||||
/// let avatar_url = mxc_uri!("mxc://example.org/avatar");
|
||||
/// let avatar_url = mxc_uri!("mxc://example.org/avatar").to_owned();
|
||||
/// let content = assign!(RoomMemberEventContent::new(MembershipState::Join), {
|
||||
/// avatar_url: Some(avatar_url),
|
||||
/// });
|
||||
|
||||
@@ -61,7 +61,7 @@ impl RoomMember {
|
||||
/// ```
|
||||
pub async fn avatar(&self, format: MediaFormat) -> Result<Option<Vec<u8>>> {
|
||||
if let Some(url) = self.avatar_url() {
|
||||
let request = MediaRequest { media_type: MediaType::Uri(url.clone()), format };
|
||||
let request = MediaRequest { media_type: MediaType::Uri(url.to_owned()), format };
|
||||
Ok(Some(self.client.get_media_content(&request, true).await?))
|
||||
} else {
|
||||
Ok(None)
|
||||
|
||||
Reference in New Issue
Block a user