rust: Clean up our deps

This commit is contained in:
Damir Jelić 2021-02-16 15:13:31 +01:00
parent 930e6f4e9b
commit 01149c8d45
2 changed files with 34 additions and 28 deletions

View File

@ -10,30 +10,28 @@ name = "matrix_crypto"
[dependencies] [dependencies]
matrix-sdk-common = { git = "https://github.com/matrix-org/matrix-rust-sdk/"} matrix-sdk-common = { git = "https://github.com/matrix-org/matrix-rust-sdk/"}
futures = { version = "0.3.12", default_features = false, features = ["executor"] }
tokio = { version = "1.2.0", default_features = false, features = ["rt-multi-thread", "time"] }
serde_json = "1.0.62" serde_json = "1.0.62"
thiserror = "1.0.23"
http = "0.2.3" http = "0.2.3"
thiserror = "1.0.23"
tracing = "0.1.23" tracing = "0.1.23"
tracing-subscriber = "0.2.15" tracing-subscriber = "0.2.15"
once_cell = "1.5.2"
[dependencies.matrix-sdk-crypto] [dependencies.matrix-sdk-crypto]
git = "https://github.com/matrix-org/matrix-rust-sdk/" git = "https://github.com/matrix-org/matrix-rust-sdk/"
features = ["sled_cryptostore"] features = ["sled_cryptostore"]
[dependencies.tokio]
version = "1.2.0"
default_features = false
features = ["rt-multi-thread"]
[dependencies.uniffi] [dependencies.uniffi]
version = "0.7.0" version = "0.7.0"
git = "https://github.com/mozilla/uniffi-rs" git = "https://github.com/mozilla/uniffi-rs"
branch = "tagged-unions" branch = "tagged-unions"
[dependencies.ruma]
version = "0.0.2"
git = "https://github.com/ruma/ruma"
rev = "d6aa37c848b7f682a98c25b346899e284ffc6df7"
features = ["client-api", "compat", "unstable-pre-spec", "unstable-exhaustive-types"]
[build-dependencies] [build-dependencies]
uniffi_build = "0.7.0" uniffi_build = "0.7.0"

View File

@ -1,13 +1,11 @@
use std::{ use std::{
collections::{BTreeMap, HashMap}, collections::{BTreeMap, HashMap},
convert::TryFrom, convert::TryFrom,
time::Duration,
}; };
use futures::executor::block_on;
use http::Response; use http::Response;
use serde_json::json; use serde_json::json;
use tokio::{runtime::Runtime, time::sleep}; use tokio::runtime::Runtime;
use matrix_sdk_common::{ use matrix_sdk_common::{
api::r0::{ api::r0::{
@ -17,6 +15,7 @@ use matrix_sdk_common::{
}, },
sync::sync_events::{DeviceLists as RumaDeviceLists, ToDevice}, sync::sync_events::{DeviceLists as RumaDeviceLists, ToDevice},
}, },
assign,
identifiers::{DeviceKeyAlgorithm, UserId}, identifiers::{DeviceKeyAlgorithm, UserId},
uuid::Uuid, uuid::Uuid,
UInt, UInt,
@ -40,7 +39,7 @@ pub struct DeviceLists {
impl Into<RumaDeviceLists> for DeviceLists { impl Into<RumaDeviceLists> for DeviceLists {
fn into(self) -> RumaDeviceLists { fn into(self) -> RumaDeviceLists {
RumaDeviceLists { assign!(RumaDeviceLists::new(), {
changed: self changed: self
.changed .changed
.into_iter() .into_iter()
@ -51,7 +50,7 @@ impl Into<RumaDeviceLists> for DeviceLists {
.into_iter() .into_iter()
.filter_map(|u| UserId::try_from(u).ok()) .filter_map(|u| UserId::try_from(u).ok())
.collect(), .collect(),
} })
} }
} }
@ -188,12 +187,13 @@ impl OlmMachine {
pub fn new(user_id: &str, device_id: &str, path: &str) -> Result<Self, MachineCreationError> { pub fn new(user_id: &str, device_id: &str, path: &str) -> Result<Self, MachineCreationError> {
let user_id = UserId::try_from(user_id)?; let user_id = UserId::try_from(user_id)?;
let device_id = device_id.into(); let device_id = device_id.into();
let runtime = Runtime::new().unwrap();
Ok(OlmMachine { Ok(OlmMachine {
inner: block_on(InnerMachine::new_with_default_store( inner: runtime.block_on(InnerMachine::new_with_default_store(
&user_id, device_id, path, None, &user_id, device_id, path, None,
))?, ))?,
runtime: Runtime::new().unwrap(), runtime,
}) })
} }
@ -208,7 +208,8 @@ impl OlmMachine {
pub fn get_device(&self, user_id: &str, device_id: &str) -> Option<Device> { pub fn get_device(&self, user_id: &str, device_id: &str) -> Option<Device> {
let user_id = UserId::try_from(user_id).unwrap(); let user_id = UserId::try_from(user_id).unwrap();
block_on(self.inner.get_device(&user_id, device_id.into())) self.runtime
.block_on(self.inner.get_device(&user_id, device_id.into()))
.unwrap() .unwrap()
.map(|d| Device { .map(|d| Device {
user_id: d.user_id().to_string(), user_id: d.user_id().to_string(),
@ -223,7 +224,8 @@ impl OlmMachine {
pub fn get_user_devices(&self, user_id: &str) -> Vec<Device> { pub fn get_user_devices(&self, user_id: &str) -> Vec<Device> {
let user_id = UserId::try_from(user_id).unwrap(); let user_id = UserId::try_from(user_id).unwrap();
block_on(self.inner.get_user_devices(&user_id)) self.runtime
.block_on(self.inner.get_user_devices(&user_id))
.unwrap() .unwrap()
.devices() .devices()
.map(|d| Device { .map(|d| Device {
@ -263,7 +265,8 @@ impl OlmMachine {
} }
.expect("Can't convert json string to response"); .expect("Can't convert json string to response");
block_on(self.inner.mark_request_as_sent(&id, &response))?; self.runtime
.block_on(self.inner.mark_request_as_sent(&id, &response))?;
Ok(()) Ok(())
} }
@ -271,9 +274,12 @@ impl OlmMachine {
pub fn start_verification(&self, device: &Device) -> Result<Sas, CryptoStoreError> { pub fn start_verification(&self, device: &Device) -> Result<Sas, CryptoStoreError> {
let user_id = UserId::try_from(device.user_id.clone()).unwrap(); let user_id = UserId::try_from(device.user_id.clone()).unwrap();
let device_id = device.device_id.as_str().into(); let device_id = device.device_id.as_str().into();
let device = block_on(self.inner.get_device(&user_id, device_id))?.unwrap(); let device = self
.runtime
.block_on(self.inner.get_device(&user_id, device_id))?
.unwrap();
let (sas, request) = block_on(device.start_verification())?; let (sas, request) = self.runtime.block_on(device.start_verification())?;
Ok(Sas { Ok(Sas {
other_user_id: sas.other_user_id().to_string(), other_user_id: sas.other_user_id().to_string(),
@ -284,7 +290,8 @@ impl OlmMachine {
} }
pub fn outgoing_requests(&self) -> Vec<Request> { pub fn outgoing_requests(&self) -> Vec<Request> {
block_on(self.inner.outgoing_requests()) self.runtime
.block_on(self.inner.outgoing_requests())
.into_iter() .into_iter()
.map(|r| r.into()) .map(|r| r.into())
.collect() .collect()
@ -303,10 +310,11 @@ impl OlmMachine {
.map(|(k, v)| (DeviceKeyAlgorithm::from(k), v.into())) .map(|(k, v)| (DeviceKeyAlgorithm::from(k), v.into()))
.collect(); .collect();
block_on( self.runtime
self.inner .block_on(
.receive_sync_changes(&events, &device_changes, &key_counts), self.inner
) .receive_sync_changes(&events, &device_changes, &key_counts),
.unwrap(); )
.unwrap();
} }
} }