Merge branch 'master' into sas-verification

master
Damir Jelić 2020-08-04 11:23:24 +02:00
commit 2bf8c99dfe
32 changed files with 483 additions and 406 deletions

View File

@ -1,5 +1,4 @@
use std::convert::TryFrom; use std::{convert::TryFrom, env, process::exit};
use std::{env, process::exit};
use url::Url; use url::Url;

View File

@ -15,19 +15,23 @@
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::collections::HashMap; use std::{
use std::convert::{TryFrom, TryInto}; collections::HashMap,
use std::fmt::{self, Debug}; convert::{TryFrom, TryInto},
use std::path::Path; fmt::{self, Debug},
use std::result::Result as StdResult; path::Path,
use std::sync::Arc; result::Result as StdResult,
sync::Arc,
};
use matrix_sdk_common::identifiers::ServerName; use matrix_sdk_common::{
use matrix_sdk_common::instant::{Duration, Instant}; identifiers::ServerName,
use matrix_sdk_common::js_int::UInt; instant::{Duration, Instant},
use matrix_sdk_common::locks::RwLock; js_int::UInt,
use matrix_sdk_common::presence::PresenceState; locks::RwLock,
use matrix_sdk_common::uuid::Uuid; presence::PresenceState,
uuid::Uuid,
};
use futures_timer::Delay as sleep; use futures_timer::Delay as sleep;
use std::future::Future; use std::future::Future;
@ -38,22 +42,18 @@ use tracing::{error, info, instrument};
use reqwest::header::{HeaderValue, InvalidHeaderValue}; use reqwest::header::{HeaderValue, InvalidHeaderValue};
use url::Url; use url::Url;
use crate::events::room::message::MessageEventContent; use crate::{
use crate::events::EventType; events::{room::message::MessageEventContent, EventType},
use crate::identifiers::{EventId, RoomId, RoomIdOrAliasId, UserId}; identifiers::{EventId, RoomId, RoomIdOrAliasId, UserId},
use crate::Endpoint; Endpoint,
};
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use crate::identifiers::DeviceId; use crate::identifiers::DeviceId;
#[cfg(feature = "encryption")]
use crate::Sas;
use crate::api;
use crate::http_client::HttpClient;
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
use crate::VERSION; use crate::VERSION;
use crate::{EventEmitter, Result}; use crate::{api, http_client::HttpClient, sas::Sas, EventEmitter, Result};
use matrix_sdk_base::{BaseClient, BaseClientConfig, Room, Session, StateStore}; use matrix_sdk_base::{BaseClient, BaseClientConfig, Room, Session, StateStore};
const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30); const DEFAULT_SYNC_TIMEOUT: Duration = Duration::from_secs(30);
@ -271,27 +271,27 @@ impl SyncSettings {
} }
} }
use api::r0::account::register;
use api::r0::directory::get_public_rooms;
use api::r0::directory::get_public_rooms_filtered;
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use api::r0::keys::{claim_keys, get_keys, upload_keys, KeyAlgorithm}; use api::r0::keys::{claim_keys, get_keys, upload_keys, KeyAlgorithm};
use api::r0::membership::{
ban_user, forget_room,
invite_user::{self, InvitationRecipient},
join_room_by_id, join_room_by_id_or_alias, kick_user, leave_room, Invite3pid,
};
use api::r0::message::create_message_event;
use api::r0::message::get_message_events;
use api::r0::read_marker::set_read_marker;
use api::r0::receipt::create_receipt;
use api::r0::room::create_room;
use api::r0::session::login;
use api::r0::sync::sync_events;
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use api::r0::to_device::send_event_to_device; use api::r0::to_device::send_event_to_device;
use api::r0::typing::create_typing_event; use api::r0::{
use api::r0::uiaa::UiaaResponse; account::register,
directory::{get_public_rooms, get_public_rooms_filtered},
membership::{
ban_user, forget_room,
invite_user::{self, InvitationRecipient},
join_room_by_id, join_room_by_id_or_alias, kick_user, leave_room, Invite3pid,
},
message::{create_message_event, get_message_events},
read_marker::set_read_marker,
receipt::create_receipt,
room::create_room,
session::login,
sync::sync_events,
typing::create_typing_event,
uiaa::UiaaResponse,
};
impl Client { impl Client {
/// Creates a new client for making HTTP requests to the given homeserver. /// Creates a new client for making HTTP requests to the given homeserver.
@ -315,10 +315,10 @@ impl Client {
homeserver_url: U, homeserver_url: U,
config: ClientConfig, config: ClientConfig,
) -> Result<Self> { ) -> Result<Self> {
#[allow(clippy::match_wild_err_arm)] let homeserver = if let Ok(u) = homeserver_url.try_into() {
let homeserver: Url = match homeserver_url.try_into() { u
Ok(u) => u, } else {
Err(_e) => panic!("Error parsing homeserver url"), panic!("Error parsing homeserver url")
}; };
let http_client = reqwest::Client::builder(); let http_client = reqwest::Client::builder();
@ -1473,23 +1473,27 @@ mod test {
get_public_rooms_filtered::{self, Filter}, get_public_rooms_filtered::{self, Filter},
invite_user, kick_user, leave_room, invite_user, kick_user, leave_room,
register::RegistrationKind, register::RegistrationKind,
set_read_marker, Invite3pid, MessageEventContent, set_read_marker, Client, ClientConfig, Invite3pid, MessageEventContent, Session,
SyncSettings, Url,
}; };
use super::{Client, ClientConfig, Session, SyncSettings, Url};
use crate::events::room::message::TextMessageEventContent; use crate::events::room::message::TextMessageEventContent;
use crate::identifiers::{EventId, RoomId, RoomIdOrAliasId, UserId}; use crate::{
use crate::{RegistrationBuilder, RoomListFilterBuilder}; identifiers::{EventId, RoomId, RoomIdOrAliasId, UserId},
RegistrationBuilder, RoomListFilterBuilder,
};
use matrix_sdk_base::JsonStore; use matrix_sdk_base::JsonStore;
use matrix_sdk_test::{test_json, EventBuilder, EventsJson}; use matrix_sdk_test::{test_json, EventBuilder, EventsJson};
use mockito::{mock, Matcher}; use mockito::{mock, Matcher};
use tempfile::tempdir; use tempfile::tempdir;
use std::convert::{TryFrom, TryInto}; use std::{
use std::path::Path; convert::{TryFrom, TryInto},
use std::str::FromStr; path::Path,
use std::time::Duration; str::FromStr,
time::Duration,
};
#[tokio::test] #[tokio::test]
async fn test_join_leave_room() { async fn test_join_leave_room() {
@ -2395,6 +2399,26 @@ mod test {
assert!(logged_in, "Clint should be logged in"); assert!(logged_in, "Clint should be logged in");
} }
#[tokio::test]
async fn login_with_device() {
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
let _m = mock("POST", "/_matrix/client/r0/login")
.with_status(200)
.with_body(test_json::LOGIN.to_string())
.create();
let client = Client::new(homeserver).unwrap();
client
.login("example", "wordpass", None, None)
.await
.unwrap();
let logged_in = client.logged_in().await;
assert!(logged_in, "Clint should be logged in");
}
#[tokio::test] #[tokio::test]
async fn sync() { async fn sync() {
let homeserver = Url::from_str(&mockito::server_url()).unwrap(); let homeserver = Url::from_str(&mockito::server_url()).unwrap();

View File

@ -14,18 +14,17 @@
//! Error conditions. //! Error conditions.
use matrix_sdk_base::Error as MatrixError;
use matrix_sdk_common::{
api::{r0::uiaa::UiaaResponse as UiaaError, Error as RumaClientError},
FromHttpResponseError as RumaResponseError, IntoHttpError as RumaIntoHttpError,
};
use reqwest::Error as ReqwestError; use reqwest::Error as ReqwestError;
use serde_json::Error as JsonError; use serde_json::Error as JsonError;
use thiserror::Error; use thiserror::Error;
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use matrix_sdk_base::CryptoStoreError; use matrix_sdk_base::CryptoStoreError;
use matrix_sdk_base::Error as MatrixError;
use crate::api::r0::uiaa::UiaaResponse as UiaaError;
use crate::api::Error as RumaClientError;
use crate::FromHttpResponseError as RumaResponseError;
use crate::IntoHttpError as RumaIntoHttpError;
/// Result type of the rust-sdk. /// Result type of the rust-sdk.
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;

View File

@ -12,8 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::convert::TryFrom; use std::{convert::TryFrom, sync::Arc};
use std::sync::Arc;
use http::{Method as HttpMethod, Response as HttpResponse}; use http::{Method as HttpMethod, Response as HttpResponse};
use reqwest::{header::AUTHORIZATION, Client, Response}; use reqwest::{header::AUTHORIZATION, Client, Response};

View File

@ -36,24 +36,23 @@
unused_qualifications unused_qualifications
)] )]
pub use matrix_sdk_base::Error as BaseError;
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
pub use matrix_sdk_base::JsonStore; pub use matrix_sdk_base::JsonStore;
pub use matrix_sdk_base::{CustomOrRawEvent, EventEmitter, Room, Session, SyncRoom}; pub use matrix_sdk_base::{
#[cfg(feature = "messages")] CustomOrRawEvent, Error as BaseError, EventEmitter, Room, RoomState, Session, StateStore,
pub use matrix_sdk_base::{MessageQueue, PossiblyRedactedExt}; SyncRoom,
pub use matrix_sdk_base::{RoomState, StateStore}; };
pub use matrix_sdk_common::*;
pub use reqwest::header::InvalidHeaderValue;
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
pub use matrix_sdk_base::{Device, TrustState}; pub use matrix_sdk_base::{Device, TrustState};
#[cfg(feature = "messages")]
pub use matrix_sdk_base::{MessageQueue, PossiblyRedactedExt};
pub use matrix_sdk_common::*;
pub use reqwest::header::InvalidHeaderValue;
mod client; mod client;
mod error; mod error;
mod http_client; mod http_client;
mod request_builder; mod request_builder;
#[cfg(feature = "encryption")]
mod sas; mod sas;
pub use client::{Client, ClientConfig, SyncSettings}; pub use client::{Client, ClientConfig, SyncSettings};

View File

@ -454,10 +454,13 @@ mod test {
use std::collections::BTreeMap; use std::collections::BTreeMap;
use super::*; use super::*;
use crate::api::r0::filter::{LazyLoadOptions, RoomEventFilter}; use crate::{
use crate::events::room::power_levels::NotificationPowerLevels; api::r0::filter::{LazyLoadOptions, RoomEventFilter},
use crate::js_int::Int; events::room::power_levels::NotificationPowerLevels,
use crate::{identifiers::RoomId, Client, Session}; identifiers::RoomId,
js_int::Int,
Client, Session,
};
use matrix_sdk_test::test_json; use matrix_sdk_test::test_json;
use mockito::{mock, Matcher}; use mockito::{mock, Matcher};

View File

@ -13,58 +13,59 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::collections::HashMap;
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use std::collections::{BTreeMap, HashSet}; use std::collections::{BTreeMap, HashSet};
use std::fmt; use std::{
use std::path::{Path, PathBuf}; collections::HashMap,
use std::sync::Arc; fmt,
use zeroize::Zeroizing; ops::Deref,
path::{Path, PathBuf},
use std::result::Result as StdResult; result::Result as StdResult,
sync::Arc,
use crate::api::r0 as api;
use crate::error::Result;
use crate::events::presence::PresenceEvent;
// `NonRoomEvent` is what it is aliased as
use crate::event_emitter::CustomOrRawEvent;
use crate::events::ignored_user_list::IgnoredUserListEvent;
use crate::events::push_rules::PushRulesEvent;
use crate::events::room::member::MemberEventContent;
use crate::identifiers::{RoomId, UserId};
use crate::models::Room;
use crate::push::Ruleset;
use crate::session::Session;
use crate::state::{AllRooms, ClientState, StateStore};
use crate::EventEmitter;
use matrix_sdk_common::events::{
AnyBasicEvent, AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncMessageEvent,
AnySyncRoomEvent, AnySyncStateEvent,
}; };
use matrix_sdk_common::Raw;
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use matrix_sdk_common::locks::Mutex; use matrix_sdk_common::locks::Mutex;
use matrix_sdk_common::locks::RwLock; use matrix_sdk_common::{
use std::ops::Deref; api::r0 as api,
events::{
#[cfg(feature = "encryption")] ignored_user_list::IgnoredUserListEvent, push_rules::PushRulesEvent,
use crate::api::r0::keys::{ room::member::MemberEventContent, AnyBasicEvent, AnyStrippedStateEvent,
claim_keys::Response as KeysClaimResponse, get_keys::Response as KeysQueryResponse, AnySyncEphemeralRoomEvent, AnySyncMessageEvent, AnySyncRoomEvent, AnySyncStateEvent,
upload_keys::Response as KeysUploadResponse, DeviceKeys, KeyAlgorithm, },
identifiers::{RoomId, UserId},
locks::RwLock,
push::Ruleset,
Raw,
}; };
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use crate::api::r0::to_device::send_event_to_device::Request as ToDeviceRequest; use matrix_sdk_common::{
#[cfg(feature = "encryption")] api::r0::keys::{
use crate::events::room::{ claim_keys::Response as KeysClaimResponse, get_keys::Response as KeysQueryResponse,
encrypted::EncryptedEventContent, message::MessageEventContent as MsgEventContent, upload_keys::Response as KeysUploadResponse, DeviceKeys, KeyAlgorithm,
},
api::r0::to_device::send_event_to_device::Request as ToDeviceRequest,
events::room::{
encrypted::EncryptedEventContent, message::MessageEventContent as MsgEventContent,
},
identifiers::DeviceId,
}; };
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
use crate::identifiers::DeviceId;
#[cfg(not(target_arch = "wasm32"))]
use crate::JsonStore;
#[cfg(feature = "encryption")]
use matrix_sdk_crypto::{CryptoStore, OlmError, OlmMachine, OneTimeKeys, Sas}; use matrix_sdk_crypto::{CryptoStore, OlmError, OlmMachine, OneTimeKeys, Sas};
use zeroize::Zeroizing;
#[cfg(not(target_arch = "wasm32"))]
use crate::JsonStore;
use crate::{
error::Result,
event_emitter::CustomOrRawEvent,
events::presence::PresenceEvent,
models::Room,
session::Session,
state::{AllRooms, ClientState, StateStore},
EventEmitter,
};
pub type Token = String; pub type Token = String;
@ -1867,10 +1868,12 @@ impl BaseClient {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::identifiers::{RoomId, UserId};
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
use crate::{events::AnySyncRoomEvent, identifiers::EventId, BaseClientConfig, JsonStore, Raw}; use crate::{events::AnySyncRoomEvent, identifiers::EventId, BaseClientConfig, JsonStore, Raw};
use crate::{BaseClient, Session}; use crate::{
identifiers::{RoomId, UserId},
BaseClient, Session,
};
use matrix_sdk_common_macros::async_trait; use matrix_sdk_common_macros::async_trait;
use matrix_sdk_test::{async_test, test_json, EventBuilder, EventsJson}; use matrix_sdk_test::{async_test, test_json, EventBuilder, EventsJson};
use serde_json::json; use serde_json::json;
@ -2033,11 +2036,13 @@ mod test {
use super::*; use super::*;
use crate::{EventEmitter, SyncRoom}; use crate::{EventEmitter, SyncRoom};
use matrix_sdk_common::events::{ use matrix_sdk_common::{
room::member::{MemberEventContent, MembershipChange}, events::{
SyncStateEvent, room::member::{MemberEventContent, MembershipChange},
SyncStateEvent,
},
locks::RwLock,
}; };
use matrix_sdk_common::locks::RwLock;
use std::sync::{ use std::sync::{
atomic::{AtomicBool, Ordering}, atomic::{AtomicBool, Ordering},
Arc, Arc,
@ -2289,8 +2294,7 @@ mod test {
use super::*; use super::*;
use crate::{EventEmitter, SyncRoom}; use crate::{EventEmitter, SyncRoom};
use matrix_sdk_common::api::r0::sync::sync_events; use matrix_sdk_common::{api::r0::sync::sync_events, locks::RwLock};
use matrix_sdk_common::locks::RwLock;
use std::sync::{ use std::sync::{
atomic::{AtomicBool, Ordering}, atomic::{AtomicBool, Ordering},
Arc, Arc,

View File

@ -17,29 +17,31 @@ use std::sync::Arc;
use matrix_sdk_common::locks::RwLock; use matrix_sdk_common::locks::RwLock;
use serde_json::value::RawValue as RawJsonValue; use serde_json::value::RawValue as RawJsonValue;
use crate::events::{ use crate::{
custom::CustomEventContent, events::{
fully_read::FullyReadEventContent, custom::CustomEventContent,
ignored_user_list::IgnoredUserListEventContent, fully_read::FullyReadEventContent,
presence::PresenceEvent, ignored_user_list::IgnoredUserListEventContent,
push_rules::PushRulesEventContent, presence::PresenceEvent,
receipt::ReceiptEventContent, push_rules::PushRulesEventContent,
room::{ receipt::ReceiptEventContent,
aliases::AliasesEventContent, room::{
avatar::AvatarEventContent, aliases::AliasesEventContent,
canonical_alias::CanonicalAliasEventContent, avatar::AvatarEventContent,
join_rules::JoinRulesEventContent, canonical_alias::CanonicalAliasEventContent,
member::MemberEventContent, join_rules::JoinRulesEventContent,
message::{feedback::FeedbackEventContent, MessageEventContent as MsgEventContent}, member::MemberEventContent,
name::NameEventContent, message::{feedback::FeedbackEventContent, MessageEventContent as MsgEventContent},
power_levels::PowerLevelsEventContent, name::NameEventContent,
redaction::SyncRedactionEvent, power_levels::PowerLevelsEventContent,
tombstone::TombstoneEventContent, redaction::SyncRedactionEvent,
tombstone::TombstoneEventContent,
},
typing::TypingEventContent,
BasicEvent, StrippedStateEvent, SyncEphemeralRoomEvent, SyncMessageEvent, SyncStateEvent,
}, },
typing::TypingEventContent, Room, RoomState,
BasicEvent, StrippedStateEvent, SyncEphemeralRoomEvent, SyncMessageEvent, SyncStateEvent,
}; };
use crate::{Room, RoomState};
use matrix_sdk_common_macros::async_trait; use matrix_sdk_common_macros::async_trait;
/// Type alias for `RoomState` enum when passed to `EventEmitter` methods. /// Type alias for `RoomState` enum when passed to `EventEmitter` methods.
@ -471,8 +473,7 @@ mod test {
} }
} }
use crate::identifiers::UserId; use crate::{identifiers::UserId, BaseClient, Session};
use crate::{BaseClient, Session};
use std::convert::TryFrom; use std::convert::TryFrom;

View File

@ -35,7 +35,10 @@
unused_qualifications unused_qualifications
)] )]
pub use crate::{error::Error, error::Result, session::Session}; pub use crate::{
error::{Error, Result},
session::Session,
};
pub use matrix_sdk_common::*; pub use matrix_sdk_common::*;
mod client; mod client;

View File

@ -5,11 +5,12 @@
use std::{time::SystemTime, vec::IntoIter}; use std::{time::SystemTime, vec::IntoIter};
use matrix_sdk_common::identifiers::{EventId, UserId}; use matrix_sdk_common::{
events::AnyPossiblyRedactedSyncMessageEvent,
identifiers::{EventId, UserId},
};
use serde::{de, ser, Serialize}; use serde::{de, ser, Serialize};
use crate::events::AnyPossiblyRedactedSyncMessageEvent;
/// Exposes some of the field access methods found in the event held by /// Exposes some of the field access methods found in the event held by
/// `AnyPossiblyRedacted*` enums. /// `AnyPossiblyRedacted*` enums.
/// ///
@ -160,8 +161,7 @@ pub(crate) mod ser_deser {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use std::collections::HashMap; use std::{collections::HashMap, convert::TryFrom};
use std::convert::TryFrom;
use matrix_sdk_common::{ use matrix_sdk_common::{
events::{AnyPossiblyRedactedSyncMessageEvent, AnySyncMessageEvent}, events::{AnyPossiblyRedactedSyncMessageEvent, AnySyncMessageEvent},

View File

@ -13,41 +13,42 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::collections::{BTreeMap, HashMap, HashSet};
use std::convert::TryFrom;
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
use std::ops::DerefMut; use std::ops::DerefMut;
use std::{
collections::{BTreeMap, HashMap, HashSet},
convert::TryFrom,
};
#[cfg(feature = "messages")]
use matrix_sdk_common::events::{
room::redaction::SyncRedactionEvent, AnyPossiblyRedactedSyncMessageEvent, AnySyncMessageEvent,
};
use matrix_sdk_common::{
api::r0::sync::sync_events::{RoomSummary, UnreadNotificationsCount},
events::{
presence::{PresenceEvent, PresenceEventContent},
room::{
aliases::AliasesEventContent,
canonical_alias::CanonicalAliasEventContent,
encryption::EncryptionEventContent,
member::{MemberEventContent, MembershipChange, MembershipState},
name::NameEventContent,
power_levels::{NotificationPowerLevels, PowerLevelsEventContent},
tombstone::TombstoneEventContent,
},
Algorithm, AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType,
StrippedStateEvent, SyncStateEvent,
},
identifiers::{RoomAliasId, RoomId, UserId},
js_int::{int, uint, Int, UInt},
};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::{debug, error, trace}; use tracing::{debug, error, trace};
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
use super::message::MessageQueue; use super::message::MessageQueue;
use super::RoomMember; use super::RoomMember;
use crate::api::r0::sync::sync_events::{RoomSummary, UnreadNotificationsCount};
use crate::events::{
presence::{PresenceEvent, PresenceEventContent},
room::{
aliases::AliasesEventContent,
canonical_alias::CanonicalAliasEventContent,
encryption::EncryptionEventContent,
member::{MemberEventContent, MembershipChange, MembershipState},
name::NameEventContent,
power_levels::{NotificationPowerLevels, PowerLevelsEventContent},
tombstone::TombstoneEventContent,
},
Algorithm, AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventType,
StrippedStateEvent, SyncStateEvent,
};
#[cfg(feature = "messages")]
use crate::events::{
room::redaction::SyncRedactionEvent, AnyPossiblyRedactedSyncMessageEvent, AnySyncMessageEvent,
};
use crate::identifiers::{RoomAliasId, RoomId, UserId};
use crate::js_int::{int, uint, Int, UInt};
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
/// `RoomName` allows the calculation of a text room name. /// `RoomName` allows the calculation of a text room name.
@ -670,8 +671,7 @@ impl Room {
#[cfg(feature = "messages")] #[cfg(feature = "messages")]
#[cfg_attr(docsrs, doc(cfg(feature = "messages")))] #[cfg_attr(docsrs, doc(cfg(feature = "messages")))]
pub fn handle_redaction(&mut self, redacted_event: &SyncRedactionEvent) -> bool { pub fn handle_redaction(&mut self, redacted_event: &SyncRedactionEvent) -> bool {
use crate::identifiers::RoomVersionId; use crate::{identifiers::RoomVersionId, models::message::PossiblyRedactedExt};
use crate::models::message::PossiblyRedactedExt;
if let Some(mut msg) = self if let Some(mut msg) = self
.messages .messages
@ -1080,9 +1080,11 @@ impl Describe for MembershipChange {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use crate::events::{room::encryption::EncryptionEventContent, Unsigned}; use crate::{
use crate::identifiers::{EventId, UserId}; events::{room::encryption::EncryptionEventContent, Unsigned},
use crate::{BaseClient, Raw, Session}; identifiers::{EventId, UserId},
BaseClient, Raw, Session,
};
use matrix_sdk_test::{async_test, sync_response, EventBuilder, EventsJson, SyncResponseFile}; use matrix_sdk_test::{async_test, sync_response, EventBuilder, EventsJson, SyncResponseFile};
use std::time::SystemTime; use std::time::SystemTime;
@ -1090,8 +1092,7 @@ mod test {
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::*; use wasm_bindgen_test::*;
use std::convert::TryFrom; use std::{convert::TryFrom, ops::Deref};
use std::ops::Deref;
async fn get_client() -> BaseClient { async fn get_client() -> BaseClient {
let session = Session { let session = Session {

View File

@ -154,8 +154,10 @@ impl RoomMember {
mod test { mod test {
use matrix_sdk_test::{async_test, EventBuilder, EventsJson}; use matrix_sdk_test::{async_test, EventBuilder, EventsJson};
use crate::identifiers::{RoomId, UserId}; use crate::{
use crate::{BaseClient, Session}; identifiers::{RoomId, UserId},
BaseClient, Session,
};
use crate::js_int::int; use crate::js_int::int;

View File

@ -15,7 +15,7 @@
//! User sessions. //! User sessions.
use crate::identifiers::{DeviceId, UserId}; use matrix_sdk_common::identifiers::{DeviceId, UserId};
/// A user session, containing an access token and information about the /// A user session, containing an access token and information about the
/// associated user account. /// associated user account.

View File

@ -1,16 +1,15 @@
use std::collections::HashMap; use std::{
use std::fmt; collections::HashMap,
use std::fs; fmt, fs,
use std::path::{Path, PathBuf}; path::{Path, PathBuf},
use std::sync::{ sync::{
atomic::{AtomicBool, Ordering}, atomic::{AtomicBool, Ordering},
Arc, Arc,
},
}; };
use matrix_sdk_common::identifiers::RoomId; use matrix_sdk_common::{identifiers::RoomId, locks::RwLock};
use matrix_sdk_common::locks::RwLock; use tokio::{fs as async_fs, io::AsyncWriteExt};
use tokio::fs as async_fs;
use tokio::io::AsyncWriteExt;
use super::{AllRooms, ClientState, StateStore}; use super::{AllRooms, ClientState, StateStore};
use crate::{Error, Result, Room, RoomState, Session}; use crate::{Error, Result, Room, RoomState, Session};
@ -218,14 +217,15 @@ impl StateStore for JsonStore {
mod test { mod test {
use super::*; use super::*;
use std::convert::TryFrom; use std::{convert::TryFrom, path::PathBuf};
use std::path::PathBuf;
use tempfile::tempdir; use tempfile::tempdir;
use crate::identifiers::{RoomId, UserId}; use crate::{
use crate::push::Ruleset; identifiers::{RoomId, UserId},
use crate::{BaseClient, BaseClientConfig, Session}; push::Ruleset,
BaseClient, BaseClientConfig, Session,
};
use matrix_sdk_test::{sync_response, SyncResponseFile}; use matrix_sdk_test::{sync_response, SyncResponseFile};

View File

@ -15,6 +15,10 @@
use std::collections::HashMap; use std::collections::HashMap;
use matrix_sdk_common::{
identifiers::{RoomId, UserId},
push::Ruleset,
};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
@ -22,10 +26,10 @@ mod json_store;
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
pub use json_store::JsonStore; pub use json_store::JsonStore;
use crate::client::{BaseClient, Token}; use crate::{
use crate::identifiers::{RoomId, UserId}; client::{BaseClient, Token},
use crate::push::Ruleset; Result, Room, RoomState, Session,
use crate::{Result, Room, RoomState, Session}; };
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
use matrix_sdk_common_macros::send_sync; use matrix_sdk_common_macros::send_sync;
@ -117,8 +121,7 @@ pub trait StateStore {
mod test { mod test {
use super::*; use super::*;
use std::collections::HashMap; use std::{collections::HashMap, convert::TryFrom};
use std::convert::TryFrom;
use crate::identifiers::RoomId; use crate::identifiers::RoomId;

View File

@ -1,6 +1,5 @@
pub use instant; pub use instant;
pub use js_int; pub use js_int;
pub use ruma::{ pub use ruma::{
api::{ api::{
client as api, client as api,

View File

@ -12,22 +12,27 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::collections::BTreeMap; use std::{
use std::convert::TryFrom; collections::BTreeMap,
use std::sync::atomic::{AtomicBool, Ordering}; convert::TryFrom,
use std::sync::Arc; sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
};
use atomic::Atomic; use atomic::Atomic;
use matrix_sdk_common::{
api::r0::keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, SignedKey},
events::Algorithm,
identifiers::{DeviceId, UserId},
};
use serde_json::{json, Value}; use serde_json::{json, Value};
#[cfg(test)] #[cfg(test)]
use super::{Account, OlmMachine}; use super::{Account, OlmMachine};
use matrix_sdk_common::api::r0::keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, SignedKey};
use matrix_sdk_common::events::Algorithm;
use matrix_sdk_common::identifiers::{DeviceId, UserId};
use crate::error::SignatureError; use crate::{error::SignatureError, verify_json};
use crate::verify_json;
/// A device represents a E2EE capable client of an user. /// A device represents a E2EE capable client of an user.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -243,8 +248,10 @@ pub(crate) mod test {
use std::convert::TryFrom; use std::convert::TryFrom;
use crate::device::{Device, TrustState}; use crate::device::{Device, TrustState};
use matrix_sdk_common::api::r0::keys::{DeviceKeys, KeyAlgorithm}; use matrix_sdk_common::{
use matrix_sdk_common::identifiers::UserId; api::r0::keys::{DeviceKeys, KeyAlgorithm},
identifiers::UserId,
};
fn device_keys() -> DeviceKeys { fn device_keys() -> DeviceKeys {
let device_keys = json!({ let device_keys = json!({

View File

@ -45,8 +45,10 @@ pub use store::{CryptoStore, CryptoStoreError};
pub use verification::Sas; pub use verification::Sas;
use error::SignatureError; use error::SignatureError;
use matrix_sdk_common::api::r0::keys::{AlgorithmAndDeviceId, KeyAlgorithm}; use matrix_sdk_common::{
use matrix_sdk_common::identifiers::UserId; api::r0::keys::{AlgorithmAndDeviceId, KeyAlgorithm},
identifiers::UserId,
};
use olm_rs::utility::OlmUtility; use olm_rs::utility::OlmUtility;
use serde_json::Value; use serde_json::Value;

View File

@ -12,45 +12,53 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::collections::{BTreeMap, HashMap, HashSet};
use std::convert::{TryFrom, TryInto};
use std::mem;
#[cfg(feature = "sqlite-cryptostore")] #[cfg(feature = "sqlite-cryptostore")]
use std::path::Path; use std::path::Path;
use std::result::Result as StdResult; use std::{
use std::sync::Arc; collections::{BTreeMap, HashMap, HashSet},
convert::{TryFrom, TryInto},
use super::error::{EventError, MegolmError, MegolmResult, OlmError, OlmResult}; mem,
use super::olm::{ result::Result as StdResult,
Account, GroupSessionKey, IdentityKeys, InboundGroupSession, OlmMessage, OutboundGroupSession, sync::Arc,
}; };
use super::store::memorystore::MemoryStore;
#[cfg(feature = "sqlite-cryptostore")]
use super::store::sqlite::SqliteStore;
use super::{device::Device, store::Result as StoreResult, CryptoStore};
use crate::verification::{Sas, VerificationMachine};
use matrix_sdk_common::events::{
forwarded_room_key::ForwardedRoomKeyEventContent, room::encrypted::EncryptedEventContent,
room::message::MessageEventContent, room_key::RoomKeyEventContent,
room_key_request::RoomKeyRequestEventContent, Algorithm, AnySyncRoomEvent, AnyToDeviceEvent,
EventType, SyncMessageEvent, ToDeviceEvent,
};
use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId};
use matrix_sdk_common::locks::RwLock;
use matrix_sdk_common::uuid::Uuid;
use matrix_sdk_common::{api, Raw};
use api::r0::keys;
use api::r0::{ use api::r0::{
keys,
keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, OneTimeKey}, keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, OneTimeKey},
sync::sync_events::Response as SyncResponse, sync::sync_events::Response as SyncResponse,
to_device::{send_event_to_device::Request as ToDeviceRequest, DeviceIdOrAllDevices}, to_device::{send_event_to_device::Request as ToDeviceRequest, DeviceIdOrAllDevices},
}; };
use matrix_sdk_common::{
api,
events::{
forwarded_room_key::ForwardedRoomKeyEventContent,
room::{encrypted::EncryptedEventContent, message::MessageEventContent},
room_key::RoomKeyEventContent,
room_key_request::RoomKeyRequestEventContent,
Algorithm, AnySyncRoomEvent, AnyToDeviceEvent, EventType, SyncMessageEvent, ToDeviceEvent,
},
identifiers::{DeviceId, RoomId, UserId},
locks::RwLock,
uuid::Uuid,
Raw,
};
use serde_json::Value; use serde_json::Value;
use tracing::{debug, error, info, instrument, trace, warn}; use tracing::{debug, error, info, instrument, trace, warn};
#[cfg(feature = "sqlite-cryptostore")]
use super::store::sqlite::SqliteStore;
use super::{
device::Device,
error::{EventError, MegolmError, MegolmResult, OlmError, OlmResult},
olm::{
Account, GroupSessionKey, IdentityKeys, InboundGroupSession, OlmMessage,
OutboundGroupSession,
},
store::{memorystore::MemoryStore, Result as StoreResult},
verification::{Sas, VerificationMachine},
CryptoStore,
};
/// A map from the algorithm and device id to a one-time key. /// A map from the algorithm and device id to a one-time key.
/// ///
/// These keys need to be periodically uploaded to the server. /// These keys need to be periodically uploaded to the server.
@ -1262,30 +1270,33 @@ mod test {
static USER_ID: &str = "@bob:example.org"; static USER_ID: &str = "@bob:example.org";
use matrix_sdk_common::js_int::uint; use matrix_sdk_common::js_int::uint;
use std::collections::BTreeMap; use std::{
use std::convert::TryFrom; collections::BTreeMap,
use std::convert::TryInto; convert::{TryFrom, TryInto},
use std::time::SystemTime; time::SystemTime,
};
use http::Response; use http::Response;
use serde_json::json; use serde_json::json;
use crate::machine::{OlmMachine, OneTimeKeys}; use crate::{
use crate::{verify_json, Device}; machine::{OlmMachine, OneTimeKeys},
verify_json, Device,
};
use matrix_sdk_common::api::r0::{ use matrix_sdk_common::{
keys, to_device::send_event_to_device::Request as ToDeviceRequest, api::r0::{keys, to_device::send_event_to_device::Request as ToDeviceRequest},
}; events::{
use matrix_sdk_common::events::{ room::{
room::{ encrypted::EncryptedEventContent,
encrypted::EncryptedEventContent, message::{MessageEventContent, TextMessageEventContent},
message::{MessageEventContent, TextMessageEventContent}, },
AnySyncMessageEvent, AnySyncRoomEvent, AnyToDeviceEvent, EventType, SyncMessageEvent,
ToDeviceEvent, Unsigned,
}, },
AnySyncMessageEvent, AnySyncRoomEvent, AnyToDeviceEvent, EventType, SyncMessageEvent, identifiers::{DeviceId, EventId, RoomId, UserId},
ToDeviceEvent, Unsigned, Raw,
}; };
use matrix_sdk_common::identifiers::{DeviceId, EventId, RoomId, UserId};
use matrix_sdk_common::Raw;
use matrix_sdk_test::test_json; use matrix_sdk_test::test_json;
fn alice_id() -> UserId { fn alice_id() -> UserId {

View File

@ -12,15 +12,18 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::collections::HashMap; use std::{collections::HashMap, sync::Arc};
use std::sync::Arc;
use dashmap::{DashMap, ReadOnlyView}; use dashmap::{DashMap, ReadOnlyView};
use matrix_sdk_common::locks::Mutex; use matrix_sdk_common::{
identifiers::{DeviceId, RoomId, UserId},
locks::Mutex,
};
use super::device::Device; use super::{
use super::olm::{InboundGroupSession, Session}; device::Device,
use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId}; olm::{InboundGroupSession, Session},
};
/// In-memory store for Olm Sessions. /// In-memory store for Olm Sessions.
#[derive(Debug, Default)] #[derive(Debug, Default)]
@ -211,10 +214,11 @@ impl DeviceStore {
mod test { mod test {
use std::convert::TryFrom; use std::convert::TryFrom;
use crate::device::test::get_device; use crate::{
use crate::memory_stores::{DeviceStore, GroupSessionStore, SessionStore}; device::test::get_device,
use crate::olm::test::get_account_and_session; memory_stores::{DeviceStore, GroupSessionStore, SessionStore},
use crate::olm::InboundGroupSession; olm::{test::get_account_and_session, InboundGroupSession},
};
use matrix_sdk_common::identifiers::RoomId; use matrix_sdk_common::identifiers::RoomId;
#[tokio::test] #[tokio::test]

View File

@ -12,36 +12,38 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use matrix_sdk_common::instant::Instant; use std::{
use std::convert::TryFrom; collections::BTreeMap,
use std::convert::TryInto; convert::{TryFrom, TryInto},
use std::fmt; fmt,
use std::sync::atomic::{AtomicBool, AtomicI64, Ordering}; sync::{
use std::sync::Arc; atomic::{AtomicBool, AtomicI64, Ordering},
Arc,
use matrix_sdk_common::locks::Mutex; },
use serde_json::{json, Value};
use std::collections::BTreeMap;
pub use olm_rs::account::IdentityKeys;
use olm_rs::account::{OlmAccount, OneTimeKeys};
use olm_rs::errors::{OlmAccountError, OlmSessionError};
use olm_rs::PicklingMode;
use crate::device::Device;
use crate::error::SessionCreationError;
pub use olm_rs::{
session::{OlmMessage, PreKeyMessage},
utility::OlmUtility,
}; };
use matrix_sdk_common::{ use matrix_sdk_common::{
api::r0::keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, OneTimeKey, SignedKey}, api::r0::keys::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, OneTimeKey, SignedKey},
events::Algorithm, events::Algorithm,
identifiers::{DeviceId, RoomId, UserId}, identifiers::{DeviceId, RoomId, UserId},
instant::Instant,
locks::Mutex,
};
use olm_rs::{
account::{OlmAccount, OneTimeKeys},
errors::{OlmAccountError, OlmSessionError},
PicklingMode,
};
use serde_json::{json, Value};
pub use olm_rs::{
account::IdentityKeys,
session::{OlmMessage, PreKeyMessage},
utility::OlmUtility,
}; };
use super::{InboundGroupSession, OutboundGroupSession, Session}; use super::{InboundGroupSession, OutboundGroupSession, Session};
use crate::{device::Device, error::SessionCreationError};
/// Account holding identity keys for which sessions can be created. /// Account holding identity keys for which sessions can be created.
/// ///

View File

@ -12,27 +12,13 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use matrix_sdk_common::instant::Instant; use std::{
use std::convert::TryInto; convert::TryInto,
use std::fmt; fmt,
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; sync::{
use std::sync::Arc; atomic::{AtomicBool, AtomicUsize, Ordering},
Arc,
use matrix_sdk_common::locks::Mutex; },
use serde::Serialize;
use serde_json::{json, Value};
use zeroize::Zeroize;
pub use olm_rs::account::IdentityKeys;
use olm_rs::errors::OlmGroupSessionError;
use olm_rs::inbound_group_session::OlmInboundGroupSession;
use olm_rs::outbound_group_session::OlmOutboundGroupSession;
use olm_rs::PicklingMode;
use crate::error::{EventError, MegolmResult};
pub use olm_rs::{
session::{OlmMessage, PreKeyMessage},
utility::OlmUtility,
}; };
use matrix_sdk_common::{ use matrix_sdk_common::{
@ -41,8 +27,25 @@ use matrix_sdk_common::{
Algorithm, AnySyncRoomEvent, EventType, SyncMessageEvent, Algorithm, AnySyncRoomEvent, EventType, SyncMessageEvent,
}, },
identifiers::{DeviceId, RoomId}, identifiers::{DeviceId, RoomId},
instant::Instant,
locks::Mutex,
Raw, Raw,
}; };
use olm_rs::{
errors::OlmGroupSessionError, inbound_group_session::OlmInboundGroupSession,
outbound_group_session::OlmOutboundGroupSession, PicklingMode,
};
use serde::Serialize;
use serde_json::{json, Value};
use zeroize::Zeroize;
pub use olm_rs::{
account::IdentityKeys,
session::{OlmMessage, PreKeyMessage},
utility::OlmUtility,
};
use crate::error::{EventError, MegolmResult};
/// The private session key of a group session. /// The private session key of a group session.
/// Can be used to create a new inbound group session. /// Can be used to create a new inbound group session.

View File

@ -23,11 +23,12 @@ pub use session::{OlmMessage, Session};
#[cfg(test)] #[cfg(test)]
pub(crate) mod test { pub(crate) mod test {
use crate::olm::{Account, InboundGroupSession, Session}; use crate::olm::{Account, InboundGroupSession, Session};
use matrix_sdk_common::api::r0::keys::SignedKey; use matrix_sdk_common::{
use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId}; api::r0::keys::SignedKey,
identifiers::{DeviceId, RoomId, UserId},
};
use olm_rs::session::OlmMessage; use olm_rs::session::OlmMessage;
use std::collections::BTreeMap; use std::{collections::BTreeMap, convert::TryFrom};
use std::convert::TryFrom;
fn alice_id() -> UserId { fn alice_id() -> UserId {
UserId::try_from("@alice:example.org").unwrap() UserId::try_from("@alice:example.org").unwrap()

View File

@ -12,24 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::collections::BTreeMap; use std::{collections::BTreeMap, fmt, sync::Arc};
use std::fmt;
use std::sync::Arc;
use olm_rs::errors::OlmSessionError;
use olm_rs::session::OlmSession;
use olm_rs::PicklingMode;
use serde_json::{json, Value};
pub use olm_rs::{
session::{OlmMessage, PreKeyMessage},
utility::OlmUtility,
};
use super::IdentityKeys;
use crate::error::{EventError, OlmResult};
use crate::Device;
use matrix_sdk_common::{ use matrix_sdk_common::{
api::r0::keys::KeyAlgorithm, api::r0::keys::KeyAlgorithm,
@ -41,6 +24,19 @@ use matrix_sdk_common::{
instant::Instant, instant::Instant,
locks::Mutex, locks::Mutex,
}; };
use olm_rs::{errors::OlmSessionError, session::OlmSession, PicklingMode};
use serde_json::{json, Value};
use super::IdentityKeys;
use crate::{
error::{EventError, OlmResult},
Device,
};
pub use olm_rs::{
session::{OlmMessage, PreKeyMessage},
utility::OlmUtility,
};
/// Cryptographic session that enables secure communication between two /// Cryptographic session that enables secure communication between two
/// `Account`s /// `Account`s

View File

@ -12,17 +12,19 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::collections::HashSet; use std::{collections::HashSet, sync::Arc};
use std::sync::Arc;
use async_trait::async_trait; use async_trait::async_trait;
use matrix_sdk_common::locks::Mutex; use matrix_sdk_common::{
identifiers::{DeviceId, RoomId, UserId},
locks::Mutex,
};
use super::{Account, CryptoStore, InboundGroupSession, Result, Session}; use super::{Account, CryptoStore, InboundGroupSession, Result, Session};
use crate::device::Device; use crate::{
use crate::memory_stores::{DeviceStore, GroupSessionStore, SessionStore, UserDevices}; device::Device,
use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId}; memory_stores::{DeviceStore, GroupSessionStore, SessionStore, UserDevices},
};
#[derive(Debug)] #[derive(Debug)]
pub struct MemoryStore { pub struct MemoryStore {
sessions: SessionStore, sessions: SessionStore,
@ -126,11 +128,11 @@ impl CryptoStore for MemoryStore {
mod test { mod test {
use std::convert::TryFrom; use std::convert::TryFrom;
use crate::device::test::get_device; use crate::{
use crate::olm::test::get_account_and_session; device::test::get_device,
use crate::olm::InboundGroupSession; olm::{test::get_account_and_session, InboundGroupSession},
use crate::store::memorystore::MemoryStore; store::{memorystore::MemoryStore, CryptoStore},
use crate::store::CryptoStore; };
use matrix_sdk_common::identifiers::RoomId; use matrix_sdk_common::identifiers::RoomId;
#[tokio::test] #[tokio::test]

View File

@ -12,23 +12,25 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use core::fmt::Debug; use std::{collections::HashSet, io::Error as IoError, sync::Arc};
use std::collections::HashSet;
use std::io::Error as IoError;
use std::sync::Arc;
use url::ParseError;
use async_trait::async_trait; use async_trait::async_trait;
use matrix_sdk_common::locks::Mutex; use core::fmt::Debug;
use serde_json::Error as SerdeError; use matrix_sdk_common::{
use thiserror::Error; identifiers::{DeviceId, RoomId, UserId},
locks::Mutex,
use super::device::Device; };
use super::memory_stores::UserDevices;
use super::olm::{Account, InboundGroupSession, Session};
use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId};
use matrix_sdk_common_macros::send_sync; use matrix_sdk_common_macros::send_sync;
use olm_rs::errors::{OlmAccountError, OlmGroupSessionError, OlmSessionError}; use olm_rs::errors::{OlmAccountError, OlmGroupSessionError, OlmSessionError};
use serde_json::Error as SerdeError;
use thiserror::Error;
use url::ParseError;
use super::{
device::Device,
memory_stores::UserDevices,
olm::{Account, InboundGroupSession, Session},
};
pub mod memorystore; pub mod memorystore;

View File

@ -12,27 +12,33 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use matrix_sdk_common::instant::{Duration, Instant}; use std::{
use std::collections::{BTreeMap, HashSet}; collections::{BTreeMap, HashSet},
use std::convert::TryFrom; convert::TryFrom,
use std::path::{Path, PathBuf}; path::{Path, PathBuf},
use std::result::Result as StdResult; result::Result as StdResult,
use std::sync::Arc; sync::Arc,
use url::Url; };
use async_trait::async_trait; use async_trait::async_trait;
use matrix_sdk_common::locks::Mutex; use matrix_sdk_common::{
api::r0::keys::{AlgorithmAndDeviceId, KeyAlgorithm},
events::Algorithm,
identifiers::{DeviceId, RoomId, UserId},
instant::{Duration, Instant},
locks::Mutex,
};
use olm_rs::PicklingMode; use olm_rs::PicklingMode;
use sqlx::{query, query_as, sqlite::SqliteQueryAs, Connect, Executor, SqliteConnection}; use sqlx::{query, query_as, sqlite::SqliteQueryAs, Connect, Executor, SqliteConnection};
use url::Url;
use zeroize::Zeroizing; use zeroize::Zeroizing;
use super::{CryptoStore, CryptoStoreError, Result}; use super::{CryptoStore, CryptoStoreError, Result};
use crate::device::{Device, TrustState}; use crate::{
use crate::memory_stores::{DeviceStore, GroupSessionStore, SessionStore, UserDevices}; device::{Device, TrustState},
use crate::{Account, IdentityKeys, InboundGroupSession, Session}; memory_stores::{DeviceStore, GroupSessionStore, SessionStore, UserDevices},
use matrix_sdk_common::api::r0::keys::{AlgorithmAndDeviceId, KeyAlgorithm}; Account, IdentityKeys, InboundGroupSession, Session,
use matrix_sdk_common::events::Algorithm; };
use matrix_sdk_common::identifiers::{DeviceId, RoomId, UserId};
/// SQLite based implementation of a `CryptoStore`. /// SQLite based implementation of a `CryptoStore`.
pub struct SqliteStore { pub struct SqliteStore {
@ -887,10 +893,11 @@ impl std::fmt::Debug for SqliteStore {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::device::test::get_device; use crate::{device::test::get_device, olm::GroupSessionKey};
use crate::olm::GroupSessionKey; use matrix_sdk_common::{
use matrix_sdk_common::api::r0::keys::SignedKey; api::r0::keys::SignedKey,
use matrix_sdk_common::identifiers::{DeviceId, UserId}; identifiers::{DeviceId, UserId},
};
use olm_rs::outbound_group_session::OlmOutboundGroupSession; use olm_rs::outbound_group_session::OlmOutboundGroupSession;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use tempfile::tempdir; use tempfile::tempdir;

View File

@ -160,8 +160,7 @@ impl VerificationMachine {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use std::convert::TryFrom; use std::{convert::TryFrom, sync::Arc};
use std::sync::Arc;
use matrix_sdk_common::{ use matrix_sdk_common::{
events::AnyToDeviceEventContent, events::AnyToDeviceEventContent,
@ -170,8 +169,11 @@ mod test {
}; };
use super::{Sas, VerificationMachine}; use super::{Sas, VerificationMachine};
use crate::verification::test::{get_content_from_request, wrap_any_to_device_content}; use crate::{
use crate::{store::memorystore::MemoryStore, Account, CryptoStore, Device}; store::memorystore::MemoryStore,
verification::test::{get_content_from_request, wrap_any_to_device_content},
Account, CryptoStore, Device,
};
fn alice_id() -> UserId { fn alice_id() -> UserId {
UserId::try_from("@alice:example.org").unwrap() UserId::try_from("@alice:example.org").unwrap()

View File

@ -1,5 +1,4 @@
use std::collections::BTreeMap; use std::{collections::BTreeMap, convert::TryInto};
use std::convert::TryInto;
use olm_rs::sas::OlmSas; use olm_rs::sas::OlmSas;

View File

@ -491,12 +491,13 @@ impl InnerSas {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use std::convert::TryFrom; use std::{convert::TryFrom, sync::Arc};
use std::sync::Arc;
use matrix_sdk_common::events::{EventContent, ToDeviceEvent}; use matrix_sdk_common::{
use matrix_sdk_common::identifiers::{DeviceId, UserId}; events::{EventContent, ToDeviceEvent},
use matrix_sdk_common::locks::RwLock; identifiers::{DeviceId, UserId},
locks::RwLock,
};
use crate::{ use crate::{
store::memorystore::MemoryStore, store::memorystore::MemoryStore,

View File

@ -744,8 +744,10 @@ mod test {
use std::convert::TryFrom; use std::convert::TryFrom;
use crate::{Account, Device}; use crate::{Account, Device};
use matrix_sdk_common::events::{EventContent, ToDeviceEvent}; use matrix_sdk_common::{
use matrix_sdk_common::identifiers::{DeviceId, UserId}; events::{EventContent, ToDeviceEvent},
identifiers::{DeviceId, UserId},
};
use super::{Accepted, Created, SasState, Started}; use super::{Accepted, Created, SasState, Started};

View File

@ -1,15 +1,15 @@
use std::collections::HashMap; use std::{collections::HashMap, convert::TryFrom, panic};
use std::convert::TryFrom;
use std::panic;
use http::Response; use http::Response;
use matrix_sdk_common::api::r0::sync::sync_events::Response as SyncResponse; use matrix_sdk_common::{
use matrix_sdk_common::events::{ api::r0::sync::sync_events::Response as SyncResponse,
presence::PresenceEvent, AnyBasicEvent, AnySyncEphemeralRoomEvent, AnySyncRoomEvent, events::{
AnySyncStateEvent, presence::PresenceEvent, AnyBasicEvent, AnySyncEphemeralRoomEvent, AnySyncRoomEvent,
AnySyncStateEvent,
},
identifiers::RoomId,
}; };
use matrix_sdk_common::identifiers::RoomId;
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
pub use matrix_sdk_test_macros::async_test; pub use matrix_sdk_test_macros::async_test;