mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-29 12:28:36 +03:00
rust: Bump the rust-sdk version
This commit is contained in:
parent
2167564812
commit
71cc38fa78
3 changed files with 56 additions and 48 deletions
|
@ -29,11 +29,11 @@ features = ["lax_deserialize"]
|
|||
|
||||
[dependencies.matrix-sdk-common]
|
||||
git = "https://github.com/matrix-org/matrix-rust-sdk/"
|
||||
rev = "a628e84b63f6b761af383655e00f544ef6a09082"
|
||||
rev = "8494f105837af824f4637c05e9e01b0854d7109b"
|
||||
|
||||
[dependencies.matrix-sdk-crypto]
|
||||
git = "https://github.com/matrix-org/matrix-rust-sdk/"
|
||||
rev = "a628e84b63f6b761af383655e00f544ef6a09082"
|
||||
rev = "8494f105837af824f4637c05e9e01b0854d7109b"
|
||||
features = ["sled_cryptostore", "qrcode", "backups_v1"]
|
||||
|
||||
[dependencies.tokio]
|
||||
|
@ -43,7 +43,7 @@ features = ["rt-multi-thread"]
|
|||
|
||||
[dependencies.ruma]
|
||||
git = "https://github.com/ruma/ruma"
|
||||
rev = "ac6ecc3e5"
|
||||
rev = "6c4892664"
|
||||
features = ["client-api-c"]
|
||||
|
||||
[build-dependencies]
|
||||
|
|
|
@ -2,6 +2,7 @@ use std::{
|
|||
collections::{BTreeMap, HashMap},
|
||||
convert::{TryFrom, TryInto},
|
||||
io::Cursor,
|
||||
ops::Deref,
|
||||
};
|
||||
|
||||
use base64::{decode_config, encode, STANDARD_NO_PAD};
|
||||
|
@ -77,7 +78,7 @@ impl OlmMachine {
|
|||
///
|
||||
/// * `path` - The path where the state of the machine should be persisted.
|
||||
pub fn new(user_id: &str, device_id: &str, path: &str) -> Result<Self, CryptoStoreError> {
|
||||
let user_id = UserId::try_from(user_id)?;
|
||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
||||
let device_id = device_id.into();
|
||||
let runtime = Runtime::new().expect("Couldn't create a tokio runtime");
|
||||
|
||||
|
@ -106,7 +107,7 @@ impl OlmMachine {
|
|||
|
||||
/// Get a cross signing user identity for the given user ID.
|
||||
pub fn get_identity(&self, user_id: &str) -> Result<Option<UserIdentity>, CryptoStoreError> {
|
||||
let user_id = UserId::try_from(user_id)?;
|
||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
||||
|
||||
Ok(
|
||||
if let Some(identity) = self.runtime.block_on(self.inner.get_identity(&user_id))? {
|
||||
|
@ -119,7 +120,7 @@ impl OlmMachine {
|
|||
|
||||
/// Check if a user identity is considered to be verified by us.
|
||||
pub fn is_identity_verified(&self, user_id: &str) -> Result<bool, CryptoStoreError> {
|
||||
let user_id = UserId::try_from(user_id)?;
|
||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
||||
|
||||
Ok(
|
||||
if let Some(identity) = self.runtime.block_on(self.inner.get_identity(&user_id))? {
|
||||
|
@ -145,7 +146,7 @@ impl OlmMachine {
|
|||
/// Returns a request that needs to be sent out for the user identity to be
|
||||
/// marked as verified.
|
||||
pub fn verify_identity(&self, user_id: &str) -> Result<SignatureUploadRequest, SignatureError> {
|
||||
let user_id = UserId::try_from(user_id)?;
|
||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
||||
|
||||
let user_identity = self.runtime.block_on(self.inner.get_identity(&user_id))?;
|
||||
|
||||
|
@ -172,7 +173,7 @@ impl OlmMachine {
|
|||
user_id: &str,
|
||||
device_id: &str,
|
||||
) -> Result<Option<Device>, CryptoStoreError> {
|
||||
let user_id = UserId::try_from(user_id)?;
|
||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
||||
|
||||
Ok(self
|
||||
.runtime
|
||||
|
@ -198,7 +199,7 @@ impl OlmMachine {
|
|||
user_id: &str,
|
||||
device_id: &str,
|
||||
) -> Result<SignatureUploadRequest, SignatureError> {
|
||||
let user_id = UserId::try_from(user_id)?;
|
||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
||||
let device = self
|
||||
.runtime
|
||||
.block_on(self.inner.get_device(&user_id, device_id.into()))?;
|
||||
|
@ -219,7 +220,7 @@ impl OlmMachine {
|
|||
user_id: &str,
|
||||
device_id: &str,
|
||||
) -> Result<(), CryptoStoreError> {
|
||||
let user_id = UserId::try_from(user_id)?;
|
||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
||||
|
||||
let device = self
|
||||
.runtime
|
||||
|
@ -239,7 +240,7 @@ impl OlmMachine {
|
|||
///
|
||||
/// * `user_id` - The id of the device owner.
|
||||
pub fn get_user_devices(&self, user_id: &str) -> Result<Vec<Device>, CryptoStoreError> {
|
||||
let user_id = UserId::try_from(user_id)?;
|
||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
||||
|
||||
Ok(self
|
||||
.runtime
|
||||
|
@ -378,13 +379,15 @@ impl OlmMachine {
|
|||
///
|
||||
/// `users` - The users that should be queued up for a key query.
|
||||
pub fn update_tracked_users(&self, users: Vec<String>) {
|
||||
let users: Vec<UserId> = users
|
||||
let users: Vec<Box<UserId>> = users
|
||||
.into_iter()
|
||||
.filter_map(|u| UserId::try_from(u).ok())
|
||||
.filter_map(|u| Box::<UserId>::try_from(u).ok())
|
||||
.collect();
|
||||
|
||||
self.runtime
|
||||
.block_on(self.inner.update_tracked_users(users.iter()));
|
||||
self.runtime.block_on(
|
||||
self.inner
|
||||
.update_tracked_users(users.iter().map(Deref::deref)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Check if the given user is considered to be tracked.
|
||||
|
@ -392,7 +395,7 @@ impl OlmMachine {
|
|||
/// A user can be marked for tracking using the
|
||||
/// [`OlmMachine::update_tracked_users()`] method.
|
||||
pub fn is_user_tracked(&self, user_id: &str) -> Result<bool, CryptoStoreError> {
|
||||
let user_id = UserId::try_from(user_id)?;
|
||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
||||
Ok(self.inner.tracked_users().contains(&user_id))
|
||||
}
|
||||
|
||||
|
@ -414,14 +417,17 @@ impl OlmMachine {
|
|||
&self,
|
||||
users: Vec<String>,
|
||||
) -> Result<Option<Request>, CryptoStoreError> {
|
||||
let users: Vec<UserId> = users
|
||||
let users: Vec<Box<UserId>> = users
|
||||
.into_iter()
|
||||
.filter_map(|u| UserId::try_from(u).ok())
|
||||
.filter_map(|u| Box::<UserId>::try_from(u).ok())
|
||||
.collect();
|
||||
|
||||
Ok(self
|
||||
.runtime
|
||||
.block_on(self.inner.get_missing_sessions(users.iter()))?
|
||||
.block_on(
|
||||
self.inner
|
||||
.get_missing_sessions(users.iter().map(Deref::deref)),
|
||||
)?
|
||||
.map(|r| r.into()))
|
||||
}
|
||||
|
||||
|
@ -447,15 +453,15 @@ impl OlmMachine {
|
|||
room_id: &str,
|
||||
users: Vec<String>,
|
||||
) -> Result<Vec<Request>, CryptoStoreError> {
|
||||
let users: Vec<UserId> = users
|
||||
let users: Vec<Box<UserId>> = users
|
||||
.into_iter()
|
||||
.filter_map(|u| UserId::try_from(u).ok())
|
||||
.filter_map(|u| Box::<UserId>::try_from(u).ok())
|
||||
.collect();
|
||||
|
||||
let room_id = RoomId::try_from(room_id)?;
|
||||
let room_id = Box::<RoomId>::try_from(room_id)?;
|
||||
let requests = self.runtime.block_on(self.inner.share_group_session(
|
||||
&room_id,
|
||||
users.iter(),
|
||||
users.iter().map(Deref::deref),
|
||||
EncryptionSettings::default(),
|
||||
))?;
|
||||
|
||||
|
@ -501,7 +507,7 @@ impl OlmMachine {
|
|||
event_type: &str,
|
||||
content: &str,
|
||||
) -> Result<String, CryptoStoreError> {
|
||||
let room_id = RoomId::try_from(room_id)?;
|
||||
let room_id = Box::<RoomId>::try_from(room_id)?;
|
||||
let content: Box<RawValue> = serde_json::from_str(content)?;
|
||||
|
||||
let content = AnyMessageEventContent::from_parts(event_type, &content)?;
|
||||
|
@ -537,7 +543,7 @@ impl OlmMachine {
|
|||
}
|
||||
|
||||
let event: SyncMessageEvent<RoomEncryptedEventContent> = serde_json::from_str(event)?;
|
||||
let room_id = RoomId::try_from(room_id)?;
|
||||
let room_id = Box::<RoomId>::try_from(room_id)?;
|
||||
|
||||
let decrypted = self
|
||||
.runtime
|
||||
|
@ -580,7 +586,7 @@ impl OlmMachine {
|
|||
room_id: &str,
|
||||
) -> Result<KeyRequestPair, DecryptionError> {
|
||||
let event: SyncMessageEvent<RoomEncryptedEventContent> = serde_json::from_str(event)?;
|
||||
let room_id = RoomId::try_from(room_id)?;
|
||||
let room_id = Box::<RoomId>::try_from(room_id)?;
|
||||
|
||||
let (cancel, request) = self
|
||||
.runtime
|
||||
|
@ -698,7 +704,7 @@ impl OlmMachine {
|
|||
/// Discard the currently active room key for the given room if there is
|
||||
/// one.
|
||||
pub fn discard_room_key(&self, room_id: &str) -> Result<(), CryptoStoreError> {
|
||||
let room_id = RoomId::try_from(room_id)?;
|
||||
let room_id = Box::<RoomId>::try_from(room_id)?;
|
||||
|
||||
self.runtime
|
||||
.block_on(self.inner.invalidate_group_session(&room_id))?;
|
||||
|
@ -713,7 +719,7 @@ impl OlmMachine {
|
|||
/// * `user_id` - The ID of the user for which we would like to fetch the
|
||||
/// verification requests.
|
||||
pub fn get_verification_requests(&self, user_id: &str) -> Vec<VerificationRequest> {
|
||||
let user_id = if let Ok(user_id) = UserId::try_from(user_id) {
|
||||
let user_id = if let Ok(user_id) = Box::<UserId>::try_from(user_id) {
|
||||
user_id
|
||||
} else {
|
||||
return vec![];
|
||||
|
@ -740,7 +746,7 @@ impl OlmMachine {
|
|||
user_id: &str,
|
||||
flow_id: &str,
|
||||
) -> Option<VerificationRequest> {
|
||||
let user_id = UserId::try_from(user_id).ok()?;
|
||||
let user_id = Box::<UserId>::try_from(user_id).ok()?;
|
||||
|
||||
self.inner
|
||||
.get_verification_request(&user_id, flow_id)
|
||||
|
@ -767,7 +773,7 @@ impl OlmMachine {
|
|||
flow_id: &str,
|
||||
methods: Vec<String>,
|
||||
) -> Option<OutgoingVerificationRequest> {
|
||||
let user_id = UserId::try_from(user_id).ok()?;
|
||||
let user_id = Box::<UserId>::try_from(user_id).ok()?;
|
||||
let methods = methods.into_iter().map(VerificationMethod::from).collect();
|
||||
|
||||
if let Some(verification) = self.inner.get_verification_request(&user_id, flow_id) {
|
||||
|
@ -791,7 +797,7 @@ impl OlmMachine {
|
|||
user_id: &str,
|
||||
methods: Vec<String>,
|
||||
) -> Result<Option<String>, CryptoStoreError> {
|
||||
let user_id = UserId::try_from(user_id)?;
|
||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
||||
|
||||
let identity = self.runtime.block_on(self.inner.get_identity(&user_id))?;
|
||||
|
||||
|
@ -834,9 +840,9 @@ impl OlmMachine {
|
|||
event_id: &str,
|
||||
methods: Vec<String>,
|
||||
) -> Result<Option<VerificationRequest>, CryptoStoreError> {
|
||||
let user_id = UserId::try_from(user_id)?;
|
||||
let event_id = EventId::try_from(event_id)?;
|
||||
let room_id = RoomId::try_from(room_id)?;
|
||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
||||
let event_id = Box::<EventId>::try_from(event_id)?;
|
||||
let room_id = Box::<RoomId>::try_from(room_id)?;
|
||||
|
||||
let identity = self.runtime.block_on(self.inner.get_identity(&user_id))?;
|
||||
|
||||
|
@ -872,7 +878,7 @@ impl OlmMachine {
|
|||
device_id: &str,
|
||||
methods: Vec<String>,
|
||||
) -> Result<Option<RequestVerificationResult>, CryptoStoreError> {
|
||||
let user_id = UserId::try_from(user_id)?;
|
||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
||||
|
||||
let methods = methods.into_iter().map(VerificationMethod::from).collect();
|
||||
|
||||
|
@ -933,7 +939,8 @@ impl OlmMachine {
|
|||
///
|
||||
/// * `flow_id` - The ID that uniquely identifies the verification flow.
|
||||
pub fn get_verification(&self, user_id: &str, flow_id: &str) -> Option<Verification> {
|
||||
let user_id = UserId::try_from(user_id).ok()?;
|
||||
let user_id = Box::<UserId>::try_from(user_id).ok()?;
|
||||
|
||||
self.inner
|
||||
.get_verification(&user_id, flow_id)
|
||||
.map(|v| match v {
|
||||
|
@ -963,7 +970,7 @@ impl OlmMachine {
|
|||
flow_id: &str,
|
||||
cancel_code: &str,
|
||||
) -> Option<OutgoingVerificationRequest> {
|
||||
let user_id = UserId::try_from(user_id).ok()?;
|
||||
let user_id = Box::<UserId>::try_from(user_id).ok()?;
|
||||
|
||||
if let Some(request) = self.inner.get_verification_request(&user_id, flow_id) {
|
||||
request.cancel().map(|r| r.into())
|
||||
|
@ -998,7 +1005,7 @@ impl OlmMachine {
|
|||
user_id: &str,
|
||||
flow_id: &str,
|
||||
) -> Result<Option<ConfirmVerificationResult>, CryptoStoreError> {
|
||||
let user_id = UserId::try_from(user_id)?;
|
||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
||||
|
||||
Ok(
|
||||
if let Some(verification) = self.inner.get_verification(&user_id, flow_id) {
|
||||
|
@ -1041,7 +1048,7 @@ impl OlmMachine {
|
|||
user_id: &str,
|
||||
flow_id: &str,
|
||||
) -> Result<Option<QrCode>, CryptoStoreError> {
|
||||
let user_id = UserId::try_from(user_id)?;
|
||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
||||
|
||||
if let Some(verification) = self.inner.get_verification_request(&user_id, flow_id) {
|
||||
Ok(self
|
||||
|
@ -1072,7 +1079,7 @@ impl OlmMachine {
|
|||
///
|
||||
/// [start_qr_verification()]: #method.start_qr_verification
|
||||
pub fn generate_qr_code(&self, user_id: &str, flow_id: &str) -> Option<String> {
|
||||
let user_id = UserId::try_from(user_id).ok()?;
|
||||
let user_id = Box::<UserId>::try_from(user_id).ok()?;
|
||||
self.inner
|
||||
.get_verification(&user_id, flow_id)
|
||||
.and_then(|v| v.qr_v1().and_then(|qr| qr.to_bytes().map(encode).ok()))
|
||||
|
@ -1095,7 +1102,7 @@ impl OlmMachine {
|
|||
/// * `data` - The data that was extracted from the scanned QR code as an
|
||||
/// base64 encoded string, without padding.
|
||||
pub fn scan_qr_code(&self, user_id: &str, flow_id: &str, data: &str) -> Option<ScanResult> {
|
||||
let user_id = UserId::try_from(user_id).ok()?;
|
||||
let user_id = Box::<UserId>::try_from(user_id).ok()?;
|
||||
let data = decode_config(data, STANDARD_NO_PAD).ok()?;
|
||||
let data = QrVerificationData::from_bytes(data).ok()?;
|
||||
|
||||
|
@ -1134,7 +1141,7 @@ impl OlmMachine {
|
|||
user_id: &str,
|
||||
flow_id: &str,
|
||||
) -> Result<Option<StartSasResult>, CryptoStoreError> {
|
||||
let user_id = UserId::try_from(user_id)?;
|
||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
||||
|
||||
Ok(
|
||||
if let Some(verification) = self.inner.get_verification_request(&user_id, flow_id) {
|
||||
|
@ -1169,7 +1176,7 @@ impl OlmMachine {
|
|||
user_id: &str,
|
||||
device_id: &str,
|
||||
) -> Result<Option<StartSasResult>, CryptoStoreError> {
|
||||
let user_id = UserId::try_from(user_id)?;
|
||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
||||
|
||||
Ok(
|
||||
if let Some(device) = self
|
||||
|
@ -1201,7 +1208,8 @@ impl OlmMachine {
|
|||
user_id: &str,
|
||||
flow_id: &str,
|
||||
) -> Option<OutgoingVerificationRequest> {
|
||||
let user_id = UserId::try_from(user_id).ok()?;
|
||||
let user_id = Box::<UserId>::try_from(user_id).ok()?;
|
||||
|
||||
self.inner
|
||||
.get_verification(&user_id, flow_id)
|
||||
.and_then(|s| s.sas_v1())
|
||||
|
@ -1222,7 +1230,7 @@ impl OlmMachine {
|
|||
///
|
||||
/// * `flow_id` - The ID that uniquely identifies the verification flow.
|
||||
pub fn get_emoji_index(&self, user_id: &str, flow_id: &str) -> Option<Vec<i32>> {
|
||||
let user_id = UserId::try_from(user_id).ok()?;
|
||||
let user_id = Box::<UserId>::try_from(user_id).ok()?;
|
||||
|
||||
self.inner
|
||||
.get_verification(&user_id, flow_id)
|
||||
|
@ -1247,7 +1255,7 @@ impl OlmMachine {
|
|||
///
|
||||
/// * `flow_id` - The ID that uniquely identifies the verification flow.
|
||||
pub fn get_decimals(&self, user_id: &str, flow_id: &str) -> Option<Vec<i32>> {
|
||||
let user_id = UserId::try_from(user_id).ok()?;
|
||||
let user_id = Box::<UserId>::try_from(user_id).ok()?;
|
||||
|
||||
self.inner
|
||||
.get_verification(&user_id, flow_id)
|
||||
|
|
|
@ -283,12 +283,12 @@ impl From<DeviceLists> for RumaDeviceLists {
|
|||
changed: d
|
||||
.changed
|
||||
.into_iter()
|
||||
.filter_map(|u| UserId::try_from(u).ok())
|
||||
.filter_map(|u| Box::<UserId>::try_from(u).ok())
|
||||
.collect(),
|
||||
left: d
|
||||
.left
|
||||
.into_iter()
|
||||
.filter_map(|u| UserId::try_from(u).ok())
|
||||
.filter_map(|u| Box::<UserId>::try_from(u).ok())
|
||||
.collect(),
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue