fix formatting

This commit is contained in:
Benjamin Kampmann
2021-11-30 18:45:00 +01:00
parent 9a0cf2b507
commit 97d675f216
24 changed files with 213 additions and 215 deletions

View File

@@ -28,16 +28,12 @@
#[cfg(all(feature = "sled_state_store", feature = "indexeddb_state_store"))]
compile_error!("sled_state_store and indexeddb_state_store are mutually exclusive and cannot be enabled together");
#[cfg(all(feature = "indexeddb_state_store", not(target_arch = "wasm32")))]
compile_error!("indexeddb_state_store only works for wasm32 target");
#[cfg(all(feature = "sled_cryptostore", feature = "indexeddb_state_store"))]
compile_error!("sled_cryptostore and indexeddb_state_store are mutually exclusive and cannot be enabled together");
pub use matrix_sdk_common::*;
pub use crate::{

View File

@@ -1,14 +1,11 @@
use ruma::MilliSecondsSinceUnixEpoch;
use instant::SystemTime;
use ruma::MilliSecondsSinceUnixEpoch;
/// Platform agnostic helper function to create MilliSecondsSinceUnixEpoch
pub fn milli_seconds_since_unix_epoch() -> MilliSecondsSinceUnixEpoch {
let duration = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.expect("now is always higher");
let millis = duration.
as_millis()
.try_into()
.expect("can't convert miliseconds since UNIXEPOCH");
let duration =
SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).expect("now is always higher");
let millis =
duration.as_millis().try_into().expect("can't convert miliseconds since UNIXEPOCH");
MilliSecondsSinceUnixEpoch(millis)
}
}

View File

@@ -938,8 +938,6 @@ mod test {
use dashmap::DashMap;
use matches::assert_matches;
use matrix_sdk_common::locks::Mutex;
use matrix_sdk_test::async_test;
use ruma::{
device_id,

View File

@@ -88,8 +88,13 @@ pub enum SecretInfo {
impl SecretInfo {
pub(crate) fn as_key(&self) -> String {
match &self {
SecretInfo::KeyRequest(ref info) => format!("keyRequest:{:}:{:}:{:}:{:}",
info.room_id.as_str(), info.sender_key, info.session_id, &info.algorithm),
SecretInfo::KeyRequest(ref info) => format!(
"keyRequest:{:}:{:}:{:}:{:}",
info.room_id.as_str(),
info.sender_key,
info.session_id,
&info.algorithm
),
SecretInfo::SecretRequest(ref sname) => format!("secretName:{:}", sname),
}
}

View File

@@ -938,7 +938,6 @@ impl ReadOnlyOwnUserIdentity {
#[cfg(test)]
pub(crate) mod test {
use std::{convert::TryFrom, sync::Arc};
use matrix_sdk_common::locks::Mutex;

View File

@@ -25,11 +25,9 @@
unused_qualifications
)]
#[cfg(all(feature = "indexeddb_cryptostore", not(target_arch = "wasm32")))]
compile_error!("indexeddb_cryptostore only works for wasm32 target");
#[cfg(feature = "backups_v1")]
#[cfg_attr(feature = "docs", doc(cfg(backups_v1)))]
pub mod backups;

View File

@@ -1548,11 +1548,11 @@ impl OlmMachine {
#[cfg(test)]
pub(crate) mod test {
use matrix_sdk_test::async_test;
use std::{collections::BTreeMap, convert::TryInto, iter, sync::Arc};
use http::Response;
use matrix_sdk_test::test_json;
use matrix_sdk_common::util::milli_seconds_since_unix_epoch;
use matrix_sdk_test::{async_test, test_json};
use ruma::{
api::{
client::r0::keys::{claim_keys, get_keys, upload_keys},
@@ -1580,7 +1580,6 @@ pub(crate) mod test {
verification::test::{outgoing_request_to_event, request_to_event},
EncryptionSettings, ReadOnlyDevice, ToDeviceRequest,
};
use matrix_sdk_common::util::milli_seconds_since_unix_epoch;
/// These keys need to be periodically uploaded to the server.
type OneTimeKeys = BTreeMap<Box<DeviceKeyId>, OneTimeKey>;

View File

@@ -1157,7 +1157,6 @@ impl PartialEq for ReadOnlyAccount {
mod test {
use std::{collections::BTreeSet, ops::Deref};
use matrix_sdk_test::async_test;
use ruma::{device_id, identifiers::DeviceId, user_id, DeviceKeyId, UserId};

View File

@@ -162,13 +162,10 @@ impl From<ToDeviceForwardedRoomKeyEventContent> for ExportedRoomKey {
#[cfg(target_os = "linux")]
#[cfg(test)]
mod test {
use matrix_sdk_test::async_test;
use std::{
sync::Arc,
time::Duration,
};
use std::{sync::Arc, time::Duration};
use matrix_sdk_common::instant::Instant;
use matrix_sdk_test::async_test;
use ruma::{device_id, events::room::message::RoomMessageEventContent, room_id, user_id};
use super::EncryptionSettings;

View File

@@ -60,10 +60,10 @@ where
#[cfg(test)]
pub(crate) mod test {
use matrix_sdk_test::async_test;
use std::{collections::BTreeMap, convert::TryInto};
use matches::assert_matches;
use matrix_sdk_test::async_test;
use olm_rs::session::OlmMessage;
use ruma::{
device_id,
@@ -250,7 +250,8 @@ pub(crate) mod test {
room_id,
outbound.session_key().await,
None,
).unwrap();
)
.unwrap();
assert_eq!(0, inbound.first_known_index());

View File

@@ -580,7 +580,7 @@ mod test {
use std::ops::Deref;
use matrix_sdk_common::uuid::Uuid;
use matrix_sdk_test::response_from_file;
use matrix_sdk_test::{async_test, response_from_file};
use ruma::{
api::{
client::r0::keys::{claim_keys, get_keys},
@@ -590,9 +590,6 @@ mod test {
};
use serde_json::Value;
use matrix_sdk_test::async_test;
use crate::{EncryptionSettings, OlmMachine};
fn alice_id() -> &'static UserId {

View File

@@ -337,7 +337,6 @@ mod test {
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, device_id, user_id,

View File

@@ -187,6 +187,7 @@ impl DeviceStore {
#[cfg(test)]
mod test {
use matrix_sdk_test::async_test;
use ruma::room_id;
use crate::{
@@ -195,9 +196,6 @@ mod test {
store::caches::{DeviceStore, GroupSessionStore, SessionStore},
};
use matrix_sdk_test::async_test;
#[async_test]
async fn test_session_store() {
let (_, session) = get_account_and_session().await;

View File

@@ -16,12 +16,12 @@
use std::{
collections::{HashMap, HashSet},
sync::{Arc, RwLock},
convert::{TryFrom, TryInto},
sync::{Arc, RwLock},
};
use wasm_bindgen::JsValue;
use dashmap::DashSet;
use indexed_db_futures::{prelude::*, web_sys::IdbKeyRange};
use matrix_sdk_common::{async_trait, locks::Mutex, uuid};
use olm_rs::{account::IdentityKeys, PicklingMode};
use ruma::{
@@ -30,17 +30,17 @@ use ruma::{
};
use tracing::trace;
use uuid::Uuid;
use wasm_bindgen::JsValue;
use super::{
caches::SessionStore, BackupKeys, Changes, CryptoStore, CryptoStoreError, InboundGroupSession,
PickleKey, EncryptedPickleKey, ReadOnlyAccount, Result, RoomKeyCounts, Session,
caches::SessionStore, BackupKeys, Changes, CryptoStore, CryptoStoreError, EncryptedPickleKey,
InboundGroupSession, PickleKey, ReadOnlyAccount, Result, RoomKeyCounts, Session,
};
use crate::{
gossiping::{GossipRequest, SecretInfo},
identities::{ReadOnlyDevice, ReadOnlyUserIdentities},
olm::{OutboundGroupSession, PickledInboundGroupSession, PrivateCrossSigningIdentity},
};
use indexed_db_futures::{prelude::*, web_sys::IdbKeyRange};
/// This needs to be 32 bytes long since AES-GCM requires it, otherwise we will
/// panic once we try to pickle a Signing object.
@@ -75,9 +75,9 @@ mod KEYS {
pub const SECRET_REQUESTS_BY_INFO: &'static str = "secret_requests_by_info";
// KEYS
pub const PICKLE_KEY: &'static str = "pickle_key";
pub const ACCOUNT: &'static str = "account";
pub const PRIVATE_IDENTITY: &'static str = "private_identity";
pub const PICKLE_KEY: &'static str = "pickle_key";
pub const ACCOUNT: &'static str = "account";
pub const PRIVATE_IDENTITY: &'static str = "private_identity";
}
/// An in-memory only store that will forget all the E2EE key once it's dropped.
@@ -90,7 +90,6 @@ pub struct IndexeddbStore {
session_cache: SessionStore,
tracked_users_cache: Arc<DashSet<Box<UserId>>>,
users_for_key_query_cache: Arc<DashSet<Box<UserId>>>,
}
impl std::fmt::Debug for IndexeddbStore {
@@ -104,24 +103,21 @@ fn make_range(key: String) -> Result<IdbKeyRange, CryptoStoreError> {
&JsValue::from_str(&format!("{}:", key)),
&JsValue::from_str(&format!("{};", key)),
)
.map_err(|e| {
CryptoStoreError::IndexedDatabase {
code: 0,
name: "IdbKeyRangeMakeError".to_owned(),
message: e.as_string().unwrap_or(format!("Creating key range for {:} failed", key)),
}
.map_err(|e| CryptoStoreError::IndexedDatabase {
code: 0,
name: "IdbKeyRangeMakeError".to_owned(),
message: e.as_string().unwrap_or(format!("Creating key range for {:} failed", key)),
})
}
impl IndexeddbStore {
async fn open_helper(prefix: String, pickle_key: Option<PickleKey>) -> Result<Self> {
let name = format!("{:0}::matrix-sdk-crypto", prefix);
let pickle_key = pickle_key.unwrap_or_else(||
let pickle_key = pickle_key.unwrap_or_else(|| {
PickleKey::try_from(DEFAULT_PICKLE.as_bytes().to_vec())
.expect("Default Pickle always works. qed")
);
});
// Open my_db v1
let mut db_req: OpenDbRequest = IdbDatabase::open_f64(&name, 1.0)?;
@@ -193,11 +189,14 @@ impl IndexeddbStore {
let pickle_key = match store_key {
Some(key) => PickleKey::from_encrypted(passphrase, key)
.map_err(|_| CryptoStoreError::UnpicklingError)?,
.map_err(|_| CryptoStoreError::UnpicklingError)?,
None => {
let key = PickleKey::new();
let encrypted = key.encrypt(passphrase);
ob.put_key_val(&JsValue::from_str(KEYS::PICKLE_KEY), &JsValue::from_serde(&encrypted)?)?;
ob.put_key_val(
&JsValue::from_str(KEYS::PICKLE_KEY),
&JsValue::from_serde(&encrypted)?,
)?;
tx.await.into_result()?;
key
}
@@ -214,7 +213,6 @@ impl IndexeddbStore {
self.account_info.read().unwrap().clone()
}
fn get_pickle_mode(&self) -> PicklingMode {
self.pickle_key.pickle_mode()
}
@@ -227,11 +225,17 @@ impl IndexeddbStore {
let mut stores: Vec<&'static str> = [
(changes.account.is_some() || changes.private_identity.is_some(), KEYS::CORE),
(!changes.sessions.is_empty(), KEYS::SESSION),
(!changes.devices.new.is_empty() || !changes.devices.changed.is_empty() || !changes.devices.deleted.is_empty(),
KEYS::DEVICES),
(!changes.identities.new.is_empty() || !changes.identities.changed.is_empty(),
KEYS::IDENTITIES),
(!changes.inbound_group_sessions.is_empty(), KEYS::INBOUND_GROUP_SESSIONS),
(
!changes.devices.new.is_empty()
|| !changes.devices.changed.is_empty()
|| !changes.devices.deleted.is_empty(),
KEYS::DEVICES,
),
(
!changes.identities.new.is_empty() || !changes.identities.changed.is_empty(),
KEYS::IDENTITIES,
),
(!changes.inbound_group_sessions.is_empty(), KEYS::INBOUND_GROUP_SESSIONS),
(!changes.outbound_group_sessions.is_empty(), KEYS::OUTBOUND_GROUP_SESSIONS),
(!changes.message_hashes.is_empty(), KEYS::OLM_HASHES),
]
@@ -273,11 +277,12 @@ impl IndexeddbStore {
}
if let Some(i) = &private_identity_pickle {
tx.object_store(KEYS::CORE)?
.put_key_val(&JsValue::from_str(KEYS::PRIVATE_IDENTITY), &JsValue::from_serde(i)?)?;
tx.object_store(KEYS::CORE)?.put_key_val(
&JsValue::from_str(KEYS::PRIVATE_IDENTITY),
&JsValue::from_serde(i)?,
)?;
}
if !changes.sessions.is_empty() {
let sessions = tx.object_store(KEYS::SESSION)?;
@@ -312,7 +317,10 @@ impl IndexeddbStore {
for session in changes.outbound_group_sessions {
let room_id = session.room_id();
let pickle = session.pickle(self.get_pickle_mode()).await;
sessions.put_key_val(&JsValue::from_str(room_id.as_str()), &JsValue::from_serde(&pickle)?)?;
sessions.put_key_val(
&JsValue::from_str(room_id.as_str()),
&JsValue::from_serde(&pickle)?,
)?;
}
}
@@ -355,7 +363,7 @@ impl IndexeddbStore {
for hash in &olm_hashes {
hashes.put_key_val(
&JsValue::from_str(&format!("{}:{}", hash.sender_key, hash.hash)),
&JsValue::TRUE
&JsValue::TRUE,
)?;
}
}
@@ -366,23 +374,17 @@ impl IndexeddbStore {
let outgoing_secret_requests = tx.object_store(KEYS::OUTGOING_SECRET_REQUESTS)?;
for key_request in &key_requests {
let key_request_id = JsValue::from_str(&key_request.request_id.to_string());
secret_requests_by_info.put_key_val(
&JsValue::from_str(&key_request.info.as_key()),
&key_request_id,
)?;
secret_requests_by_info
.put_key_val(&JsValue::from_str(&key_request.info.as_key()), &key_request_id)?;
if key_request.sent_out {
unsent_secret_requests.delete(&key_request_id)?;
outgoing_secret_requests.put_key_val(
&key_request_id,
&JsValue::from_serde(&key_request)?,
)?;
outgoing_secret_requests
.put_key_val(&key_request_id, &JsValue::from_serde(&key_request)?)?;
} else {
outgoing_secret_requests.delete(&key_request_id)?;
unsent_secret_requests.put_key_val(
&key_request_id,
&JsValue::from_serde(&key_request)?,
)?;
unsent_secret_requests
.put_key_val(&key_request_id, &JsValue::from_serde(&key_request)?)?;
}
}
}
@@ -397,23 +399,20 @@ impl IndexeddbStore {
Ok(())
}
async fn load_tracked_users(&self) -> Result<()> {
let tx = self
.inner
.transaction_on_one_with_mode(KEYS::TRACKED_USERS, IdbTransactionMode::Readonly)?;
let os = tx.object_store(KEYS::TRACKED_USERS)?;
let user_ids = os
.get_all_keys()?
.await?;
let user_ids = os.get_all_keys()?.await?;
for user_id in user_ids.iter() {
let dirty : bool = match os.get(&user_id)?.await?.map(|v| v.into_serde()) {
let dirty: bool = match os.get(&user_id)?.await?.map(|v| v.into_serde()) {
Some(Ok(false)) => false,
_ => true
_ => true,
};
let user = match user_id.as_string().map(|u| Box::<UserId>::try_from(u)) {
Some(Ok(user)) => user,
_ => continue
_ => continue,
};
self.tracked_users_cache.insert(user.clone());
@@ -432,18 +431,23 @@ impl IndexeddbStore {
let account_info = self.get_account_info().ok_or(CryptoStoreError::AccountUnset)?;
if let Some(value) = self
.inner
.transaction_on_one_with_mode(KEYS::OUTBOUND_GROUP_SESSIONS, IdbTransactionMode::Readonly)?
.transaction_on_one_with_mode(
KEYS::OUTBOUND_GROUP_SESSIONS,
IdbTransactionMode::Readonly,
)?
.object_store(KEYS::OUTBOUND_GROUP_SESSIONS)?
.get(&JsValue::from_str(room_id.as_str()))?
.await?
{
Ok(Some(OutboundGroupSession::from_pickle(
account_info.device_id,
account_info.identity_keys,
value.into_serde()?,
self.get_pickle_mode(),
)
.map_err(CryptoStoreError::OlmGroupSession)?))
Ok(Some(
OutboundGroupSession::from_pickle(
account_info.device_id,
account_info.identity_keys,
value.into_serde()?,
self.get_pickle_mode(),
)
.map_err(CryptoStoreError::OlmGroupSession)?,
))
} else {
Ok(None)
}
@@ -451,18 +455,18 @@ impl IndexeddbStore {
async fn get_outgoing_key_request_helper(&self, key: &str) -> Result<Option<GossipRequest>> {
let jskey = JsValue::from_str(key);
let dbs = [KEYS::OUTGOING_SECRET_REQUESTS, KEYS::UNSENT_SECRET_REQUESTS];
let tx = self
.inner
.transaction_on_multi_with_mode(&dbs, IdbTransactionMode::Readonly)?;
let tx = self.inner.transaction_on_multi_with_mode(&dbs, IdbTransactionMode::Readonly)?;
let request = tx.object_store(KEYS::OUTGOING_SECRET_REQUESTS)?
.get(&jskey)?
.await?
.map(|i| i.into_serde())
.transpose()?;
let request = tx
.object_store(KEYS::OUTGOING_SECRET_REQUESTS)?
.get(&jskey)?
.await?
.map(|i| i.into_serde())
.transpose()?;
Ok(match request {
None => tx.object_store(KEYS::UNSENT_SECRET_REQUESTS)?
None => tx
.object_store(KEYS::UNSENT_SECRET_REQUESTS)?
.get(&jskey)?
.await?
.map(|i| i.into_serde())
@@ -482,10 +486,10 @@ impl CryptoStore for IndexeddbStore {
.get(&JsValue::from_str(KEYS::ACCOUNT))?
.await?
{
self.load_tracked_users().await?;
let account = ReadOnlyAccount::from_pickle(pickle.into_serde()?, self.get_pickle_mode())?;
let account =
ReadOnlyAccount::from_pickle(pickle.into_serde()?, self.get_pickle_mode())?;
let account_info = AccountInfo {
user_id: account.user_id.clone(),
@@ -524,9 +528,12 @@ impl CryptoStore for IndexeddbStore {
.await?
{
Ok(Some(
PrivateCrossSigningIdentity::from_pickle(pickle.into_serde()?, self.get_pickle_key())
.await
.map_err(|_| CryptoStoreError::UnpicklingError)?,
PrivateCrossSigningIdentity::from_pickle(
pickle.into_serde()?,
self.get_pickle_key(),
)
.await
.map_err(|_| CryptoStoreError::UnpicklingError)?,
))
} else {
Ok(None)
@@ -551,13 +558,14 @@ impl CryptoStore for IndexeddbStore {
.iter()
.filter_map(|f| match f.into_serde() {
Ok(p) => Session::from_pickle(
account_info.user_id.clone(),
account_info.device_id.clone(),
account_info.identity_keys.clone(),
p,
self.get_pickle_mode(),
).ok(),
_ => None
account_info.user_id.clone(),
account_info.device_id.clone(),
account_info.identity_keys.clone(),
p,
self.get_pickle_mode(),
)
.ok(),
_ => None,
})
.collect::<Vec<Session>>();
@@ -576,14 +584,18 @@ impl CryptoStore for IndexeddbStore {
let key = format!("{}:{}:{}", room_id.as_str(), sender_key, session_id);
if let Some(pickle) = self
.inner
.transaction_on_one_with_mode(KEYS::INBOUND_GROUP_SESSIONS, IdbTransactionMode::Readonly)?
.transaction_on_one_with_mode(
KEYS::INBOUND_GROUP_SESSIONS,
IdbTransactionMode::Readonly,
)?
.object_store(KEYS::INBOUND_GROUP_SESSIONS)?
.get(&JsValue::from_str(&key))?
.await?
{
Ok(Some(
InboundGroupSession::from_pickle(pickle.into_serde()?, self.get_pickle_mode())?
))
Ok(Some(InboundGroupSession::from_pickle(
pickle.into_serde()?,
self.get_pickle_mode(),
)?))
} else {
Ok(None)
}
@@ -592,15 +604,17 @@ impl CryptoStore for IndexeddbStore {
async fn get_inbound_group_sessions(&self) -> Result<Vec<InboundGroupSession>> {
Ok(self
.inner
.transaction_on_one_with_mode(KEYS::INBOUND_GROUP_SESSIONS, IdbTransactionMode::Readonly)?
.transaction_on_one_with_mode(
KEYS::INBOUND_GROUP_SESSIONS,
IdbTransactionMode::Readonly,
)?
.object_store(KEYS::INBOUND_GROUP_SESSIONS)?
.get_all()?
.await?
.iter()
.filter_map(|i| i.into_serde().ok())
.filter_map(|p| InboundGroupSession::from_pickle(p, self.get_pickle_mode()).ok())
.collect()
)
.collect())
}
async fn get_outbound_group_sessions(
@@ -687,7 +701,10 @@ impl CryptoStore for IndexeddbStore {
os.put_key_val(
&JsValue::from_str(user.as_str()),
&match dirty { true => JsValue::TRUE, false => JsValue::FALSE }
&match dirty {
true => JsValue::TRUE,
false => JsValue::FALSE,
},
)?;
tx.await.into_result()?;
@@ -701,14 +718,13 @@ impl CryptoStore for IndexeddbStore {
) -> Result<Option<ReadOnlyDevice>> {
let key = format!("{}:{}", user_id.as_str(), device_id.as_str());
Ok(self
.inner
.transaction_on_one_with_mode(KEYS::DEVICES, IdbTransactionMode::Readonly)?
.object_store(KEYS::DEVICES)?
.get(&JsValue::from_str(&key))?
.await?
.map(|i| i.into_serde())
.transpose()?
)
.inner
.transaction_on_one_with_mode(KEYS::DEVICES, IdbTransactionMode::Readonly)?
.object_store(KEYS::DEVICES)?
.get(&JsValue::from_str(&key))?
.await?
.map(|i| i.into_serde())
.transpose()?)
}
async fn get_user_devices(
@@ -731,15 +747,14 @@ impl CryptoStore for IndexeddbStore {
}
async fn get_user_identity(&self, user_id: &UserId) -> Result<Option<ReadOnlyUserIdentities>> {
Ok(self
Ok(self
.inner
.transaction_on_one_with_mode(KEYS::IDENTITIES, IdbTransactionMode::Readonly)?
.object_store(KEYS::IDENTITIES)?
.get(&JsValue::from_str(user_id.as_str()))?
.await?
.map(|i| i.into_serde())
.transpose()?
)
.transpose()?)
}
async fn is_message_known(&self, hash: &crate::olm::OlmMessageHash) -> Result<bool> {
@@ -749,8 +764,7 @@ impl CryptoStore for IndexeddbStore {
.object_store(KEYS::OLM_HASHES)?
.get(&JsValue::from_str(&format!("{}:{}", hash.sender_key, hash.hash)))?
.await?
.is_some()
)
.is_some())
}
async fn get_outgoing_secret_requests(
@@ -765,13 +779,16 @@ impl CryptoStore for IndexeddbStore {
key_info: &SecretInfo,
) -> Result<Option<GossipRequest>> {
let id = self
.inner
.transaction_on_one_with_mode(KEYS::SECRET_REQUESTS_BY_INFO, IdbTransactionMode::Readonly)?
.object_store(KEYS::SECRET_REQUESTS_BY_INFO)?
.get(&JsValue::from_str(&key_info.as_key()))?
.await?
.map(|i| i.as_string())
.flatten();
.inner
.transaction_on_one_with_mode(
KEYS::SECRET_REQUESTS_BY_INFO,
IdbTransactionMode::Readonly,
)?
.object_store(KEYS::SECRET_REQUESTS_BY_INFO)?
.get(&JsValue::from_str(&key_info.as_key()))?
.await?
.map(|i| i.as_string())
.flatten();
if let Some(id) = id {
self.get_outgoing_key_request_helper(&id).await
} else {
@@ -781,32 +798,38 @@ impl CryptoStore for IndexeddbStore {
async fn get_unsent_secret_requests(&self) -> Result<Vec<GossipRequest>> {
Ok(self
.inner
.transaction_on_one_with_mode(KEYS::UNSENT_SECRET_REQUESTS, IdbTransactionMode::Readonly)?
.object_store(KEYS::UNSENT_SECRET_REQUESTS)?
.get_all()?
.await?
.iter()
.filter_map(|i| i.into_serde().ok())
.collect()
)
.inner
.transaction_on_one_with_mode(
KEYS::UNSENT_SECRET_REQUESTS,
IdbTransactionMode::Readonly,
)?
.object_store(KEYS::UNSENT_SECRET_REQUESTS)?
.get_all()?
.await?
.iter()
.filter_map(|i| i.into_serde().ok())
.collect())
}
async fn delete_outgoing_secret_requests(&self, request_id: Uuid) -> Result<()> {
let jskey = JsValue::from_str(&request_id.to_string());
let dbs = [KEYS::OUTGOING_SECRET_REQUESTS, KEYS::UNSENT_SECRET_REQUESTS, KEYS::SECRET_REQUESTS_BY_INFO];
let tx = self
.inner
.transaction_on_multi_with_mode(&dbs, IdbTransactionMode::Readwrite)?;
let dbs = [
KEYS::OUTGOING_SECRET_REQUESTS,
KEYS::UNSENT_SECRET_REQUESTS,
KEYS::SECRET_REQUESTS_BY_INFO,
];
let tx = self.inner.transaction_on_multi_with_mode(&dbs, IdbTransactionMode::Readwrite)?;
let request : Option<GossipRequest> = tx.object_store(KEYS::OUTGOING_SECRET_REQUESTS)?
.get(&jskey)?
.await?
.map(|i| i.into_serde())
.transpose()?;
let request: Option<GossipRequest> = tx
.object_store(KEYS::OUTGOING_SECRET_REQUESTS)?
.get(&jskey)?
.await?
.map(|i| i.into_serde())
.transpose()?;
let request = match request {
None => tx.object_store(KEYS::UNSENT_SECRET_REQUESTS)?
let request = match request {
None => tx
.object_store(KEYS::UNSENT_SECRET_REQUESTS)?
.get(&jskey)?
.await?
.map(|i| i.into_serde())
@@ -842,7 +865,6 @@ mod test {
.await
.expect("Can't create store without passphrase"),
}
}
cryptostore_integration_tests! { integration }
}
}

View File

@@ -600,4 +600,4 @@ macro_rules! cryptostore_integration_tests {
}
)*
}
}
}

View File

@@ -308,10 +308,8 @@ impl CryptoStore for MemoryStore {
#[cfg(test)]
mod test {
use ruma::room_id;
use matrix_sdk_test::async_test;
use ruma::room_id;
use crate::{
identities::device::test::get_device,

View File

@@ -43,10 +43,10 @@ mod pickle_key;
#[cfg(test)]
#[macro_use]
pub mod integration_tests;
#[cfg(feature = "sled_cryptostore")]
pub(crate) mod sled;
#[cfg(feature = "indexeddb_cryptostore")]
pub(crate) mod indexeddb;
#[cfg(feature = "sled_cryptostore")]
pub(crate) mod sled;
use std::{
collections::{HashMap, HashSet},
@@ -57,6 +57,8 @@ use std::{
};
use base64::DecodeError;
#[cfg(feature = "indexeddb_cryptostore")]
use indexed_db_futures::web_sys::DomException;
use matrix_sdk_common::{async_trait, locks::Mutex, uuid::Uuid, AsyncTraitDeps};
pub use memorystore::MemoryStore;
use olm_rs::errors::{OlmAccountError, OlmGroupSessionError, OlmSessionError};
@@ -70,13 +72,10 @@ use thiserror::Error;
use tracing::{info, warn};
use zeroize::Zeroize;
#[cfg(feature = "sled_cryptostore")]
pub use self::sled::SledStore;
#[cfg(feature = "indexeddb_cryptostore")]
pub use self::indexeddb::IndexeddbStore;
#[cfg(feature = "indexeddb_cryptostore")]
use indexed_db_futures::web_sys::DomException;
#[cfg(feature = "sled_cryptostore")]
pub use self::sled::SledStore;
use crate::{
error::SessionUnpicklingError,
identities::{
@@ -589,11 +588,14 @@ pub enum CryptoStoreError {
Serialization(#[from] SerdeError),
}
#[cfg(feature = "indexeddb_cryptostore")]
impl From<DomException> for CryptoStoreError {
fn from(frm: DomException) -> CryptoStoreError {
CryptoStoreError::IndexedDatabase { name: frm.name(), message: frm.message(), code: frm.code() }
CryptoStoreError::IndexedDatabase {
name: frm.name(),
message: frm.message(),
code: frm.code(),
}
}
}

View File

@@ -1009,12 +1009,12 @@ impl CryptoStore for SledStore {
}
}
#[cfg(test)]
mod test {
use super::SledStore;
use tempfile::{tempdir, TempDir};
use lazy_static::lazy_static;
use tempfile::{tempdir, TempDir};
use super::SledStore;
lazy_static! {
/// This is an example for using doc comment attributes
static ref TMP_DIR: TempDir = tempdir().unwrap();

View File

@@ -18,7 +18,7 @@ use std::{
};
use dashmap::DashMap;
use matrix_sdk_common::{locks::Mutex, uuid::Uuid};
use matrix_sdk_common::{locks::Mutex, util::milli_seconds_since_unix_epoch, uuid::Uuid};
use ruma::{
events::{
key::verification::VerificationMethod, AnyToDeviceEvent, AnyToDeviceEventContent,
@@ -28,7 +28,6 @@ use ruma::{
DeviceId, EventId, MilliSecondsSinceUnixEpoch, RoomId, UserId,
};
use tracing::{info, trace, warn};
use matrix_sdk_common::util::milli_seconds_since_unix_epoch;
use super::{
cache::VerificationCache,
@@ -506,11 +505,8 @@ impl VerificationMachine {
#[cfg(test)]
mod test {
use std::{
convert::TryFrom,
sync::Arc,
time::Duration,
};
use std::{convert::TryFrom, sync::Arc, time::Duration};
use matrix_sdk_common::{instant::Instant, locks::Mutex};
use matrix_sdk_test::async_test;
use ruma::{device_id, user_id, DeviceId, UserId};

View File

@@ -19,7 +19,7 @@ use std::{
#[cfg(feature = "qrcode")]
use matrix_qrcode::QrVerificationData;
use matrix_sdk_common::{instant::Instant, uuid::Uuid, util::milli_seconds_since_unix_epoch};
use matrix_sdk_common::{instant::Instant, util::milli_seconds_since_unix_epoch, uuid::Uuid};
#[cfg(feature = "qrcode")]
use ruma::DeviceKeyAlgorithm;
use ruma::{
@@ -1267,7 +1267,6 @@ struct Done {}
#[cfg(test)]
mod test {
use std::convert::{TryFrom, TryInto};
use matrix_sdk_test::async_test;

View File

@@ -13,9 +13,9 @@
// limitations under the License.
use std::sync::Arc;
#[cfg(test)]
use matrix_sdk_common::instant::Instant;
use ruma::{
events::key::verification::{cancel::CancelCode, ShortAuthenticationString},
EventId, RoomId, UserId,

View File

@@ -17,10 +17,10 @@ mod inner_sas;
mod sas_state;
use std::sync::{Arc, Mutex};
#[cfg(test)]
use matrix_sdk_common::instant::Instant;
use inner_sas::InnerSas;
#[cfg(test)]
use matrix_sdk_common::instant::Instant;
use matrix_sdk_common::uuid::Uuid;
use ruma::{
api::client::r0::keys::upload_signatures::Request as SignatureUploadRequest,
@@ -556,8 +556,9 @@ impl AcceptSettings {
#[cfg(test)]
mod test {
use std::{convert::TryFrom, sync::Arc};
use ruma::{device_id, user_id, DeviceId, UserId};
use matrix_sdk_test::async_test;
use ruma::{device_id, user_id, DeviceId, UserId};
use super::Sas;
use crate::{

View File

@@ -16,11 +16,10 @@ use std::{
convert::{TryFrom, TryInto},
matches,
sync::{Arc, Mutex},
time::{Duration},
time::Duration,
};
use matrix_sdk_common::instant::Instant;
use matrix_sdk_common::uuid::Uuid;
use matrix_sdk_common::{instant::Instant, uuid::Uuid};
use olm_rs::sas::OlmSas;
use ruma::{
events::{
@@ -1137,8 +1136,8 @@ impl SasState<Cancelled> {
#[cfg(test)]
mod test {
use std::convert::TryFrom;
use matrix_sdk_test::async_test;
use matrix_sdk_test::async_test;
use ruma::{
device_id,
events::key::verification::{

View File

@@ -1,13 +1,11 @@
use proc_macro::TokenStream;
use quote::ToTokens;
use syn::parse_macro_input;
use quote::{quote, format_ident};
use syn;
use quote::{format_ident, quote, ToTokens};
use syn::{self, parse_macro_input};
/// Attribute to use `wasm_bindgen_test` for wasm32 targets and `tokio::test`
/// for everything else with async-support and custom result-tyupes
#[proc_macro_attribute]
pub fn async_test(_attr: TokenStream, item: TokenStream) -> TokenStream {
pub fn async_test(_attr: TokenStream, item: TokenStream) -> TokenStream {
let fun = parse_macro_input!(item as syn::ItemFn);
// on the regular return-case, we can just use cfg_attr and quit early
if fun.sig.output == syn::ReturnType::Default {
@@ -17,9 +15,9 @@ pub fn async_test(_attr: TokenStream, item: TokenStream) -> TokenStream {
"#;
let mut out: TokenStream = attrs.parse().expect("Static works");
let inner : TokenStream = fun.into_token_stream().into();
let inner: TokenStream = fun.into_token_stream().into();
out.extend(inner);
return out
return out;
}
// on the more complicated case, where we have some `->`-Result-Arrow
@@ -37,25 +35,25 @@ pub fn async_test(_attr: TokenStream, item: TokenStream) -> TokenStream {
let mut outer = fun.clone();
let fn_name = fun.sig.ident.clone();
let fn_call : TokenStream = if fun.sig.asyncness.is_some() {
quote!{
let fn_call: TokenStream = if fun.sig.asyncness.is_some() {
quote! {
{
assert!(#fn_name().await.is_ok());
}
}
} else {
quote!{
quote! {
{
assert!(#fn_name().is_ok());
}
}
}.into();
}
.into();
outer.sig.output = syn::ReturnType::Default;
outer.sig.ident = format_ident!("{}_outer", fun.sig.ident);
outer.block = Box::new(parse_macro_input!(fn_call as syn::Block));
let inner : TokenStream = fun.into_token_stream().into();
let inner: TokenStream = fun.into_token_stream().into();
out.extend(inner);
let attrs = r#"
@@ -63,7 +61,7 @@ pub fn async_test(_attr: TokenStream, item: TokenStream) -> TokenStream {
#[wasm_bindgen_test::wasm_bindgen_test]
"#;
let outer_attrs: TokenStream = attrs.parse().expect("Static works.");
let of : TokenStream = outer.into_token_stream().into();
let of: TokenStream = outer.into_token_stream().into();
out.extend(outer_attrs);
out.extend(of);