mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-17 20:40:07 +03:00
rust: Add the string that failed to be parsed as an user id to the error
If there's an invalid user id that gets passed to the Rust side we're going to throw an error, this error doesn't tell us what is invalid nor what the string contained. Add the string that is being parsed to the error so that the log line becomes actionable.
This commit is contained in:
parent
ee017b7302
commit
a194213978
4 changed files with 25 additions and 15 deletions
|
@ -46,6 +46,8 @@ pub enum CryptoStoreError {
|
||||||
OlmError(#[from] OlmError),
|
OlmError(#[from] OlmError),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Serialization(#[from] serde_json::Error),
|
Serialization(#[from] serde_json::Error),
|
||||||
|
#[error("The given string is not a valid user ID: source {0}, error {1}")]
|
||||||
|
InvalidUserId(String, RumaIdentifierError),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Identifier(#[from] RumaIdentifierError),
|
Identifier(#[from] RumaIdentifierError),
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ mod responses;
|
||||||
mod users;
|
mod users;
|
||||||
mod verification;
|
mod verification;
|
||||||
|
|
||||||
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
pub use backup_recovery_key::{
|
pub use backup_recovery_key::{
|
||||||
BackupRecoveryKey, DecodeError, MegolmV1BackupKey, PassphraseInfo, PkDecryptionError,
|
BackupRecoveryKey, DecodeError, MegolmV1BackupKey, PassphraseInfo, PkDecryptionError,
|
||||||
};
|
};
|
||||||
|
@ -153,4 +155,9 @@ impl From<matrix_sdk_crypto::CrossSigningStatus> for CrossSigningStatus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse_user_id(user_id: &str) -> Result<Box<ruma::UserId>, CryptoStoreError> {
|
||||||
|
Box::<ruma::UserId>::try_from(user_id)
|
||||||
|
.map_err(|e| CryptoStoreError::InvalidUserId(user_id.to_owned(), e))
|
||||||
|
}
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/olm.uniffi.rs"));
|
include!(concat!(env!("OUT_DIR"), "/olm.uniffi.rs"));
|
||||||
|
|
|
@ -48,7 +48,7 @@ use crate::{
|
||||||
CrossSigningStatus, DecodeError, DecryptedEvent, Device, DeviceLists, KeyImportError,
|
CrossSigningStatus, DecodeError, DecryptedEvent, Device, DeviceLists, KeyImportError,
|
||||||
KeysImportResult, MegolmV1BackupKey, ProgressListener, QrCode, Request, RequestType,
|
KeysImportResult, MegolmV1BackupKey, ProgressListener, QrCode, Request, RequestType,
|
||||||
RequestVerificationResult, RoomKeyCounts, ScanResult, SignatureUploadRequest, StartSasResult,
|
RequestVerificationResult, RoomKeyCounts, ScanResult, SignatureUploadRequest, StartSasResult,
|
||||||
UserIdentity, Verification, VerificationRequest,
|
UserIdentity, Verification, VerificationRequest, parse_user_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A high level state machine that handles E2EE for Matrix.
|
/// A high level state machine that handles E2EE for Matrix.
|
||||||
|
@ -78,7 +78,7 @@ impl OlmMachine {
|
||||||
///
|
///
|
||||||
/// * `path` - The path where the state of the machine should be persisted.
|
/// * `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> {
|
pub fn new(user_id: &str, device_id: &str, path: &str) -> Result<Self, CryptoStoreError> {
|
||||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
let user_id = parse_user_id(user_id)?;
|
||||||
let device_id = device_id.into();
|
let device_id = device_id.into();
|
||||||
let runtime = Runtime::new().expect("Couldn't create a tokio runtime");
|
let runtime = Runtime::new().expect("Couldn't create a tokio runtime");
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ impl OlmMachine {
|
||||||
|
|
||||||
/// Get a cross signing user identity for the given user ID.
|
/// Get a cross signing user identity for the given user ID.
|
||||||
pub fn get_identity(&self, user_id: &str) -> Result<Option<UserIdentity>, CryptoStoreError> {
|
pub fn get_identity(&self, user_id: &str) -> Result<Option<UserIdentity>, CryptoStoreError> {
|
||||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
let user_id = parse_user_id(user_id)?;
|
||||||
|
|
||||||
Ok(
|
Ok(
|
||||||
if let Some(identity) = self.runtime.block_on(self.inner.get_identity(&user_id))? {
|
if let Some(identity) = self.runtime.block_on(self.inner.get_identity(&user_id))? {
|
||||||
|
@ -120,7 +120,7 @@ impl OlmMachine {
|
||||||
|
|
||||||
/// Check if a user identity is considered to be verified by us.
|
/// Check if a user identity is considered to be verified by us.
|
||||||
pub fn is_identity_verified(&self, user_id: &str) -> Result<bool, CryptoStoreError> {
|
pub fn is_identity_verified(&self, user_id: &str) -> Result<bool, CryptoStoreError> {
|
||||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
let user_id = parse_user_id(user_id)?;
|
||||||
|
|
||||||
Ok(
|
Ok(
|
||||||
if let Some(identity) = self.runtime.block_on(self.inner.get_identity(&user_id))? {
|
if let Some(identity) = self.runtime.block_on(self.inner.get_identity(&user_id))? {
|
||||||
|
@ -173,7 +173,7 @@ impl OlmMachine {
|
||||||
user_id: &str,
|
user_id: &str,
|
||||||
device_id: &str,
|
device_id: &str,
|
||||||
) -> Result<Option<Device>, CryptoStoreError> {
|
) -> Result<Option<Device>, CryptoStoreError> {
|
||||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
let user_id = parse_user_id(user_id)?;
|
||||||
|
|
||||||
Ok(self
|
Ok(self
|
||||||
.runtime
|
.runtime
|
||||||
|
@ -220,7 +220,7 @@ impl OlmMachine {
|
||||||
user_id: &str,
|
user_id: &str,
|
||||||
device_id: &str,
|
device_id: &str,
|
||||||
) -> Result<(), CryptoStoreError> {
|
) -> Result<(), CryptoStoreError> {
|
||||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
let user_id = parse_user_id(user_id)?;
|
||||||
|
|
||||||
let device = self
|
let device = self
|
||||||
.runtime
|
.runtime
|
||||||
|
@ -240,7 +240,7 @@ impl OlmMachine {
|
||||||
///
|
///
|
||||||
/// * `user_id` - The id of the device owner.
|
/// * `user_id` - The id of the device owner.
|
||||||
pub fn get_user_devices(&self, user_id: &str) -> Result<Vec<Device>, CryptoStoreError> {
|
pub fn get_user_devices(&self, user_id: &str) -> Result<Vec<Device>, CryptoStoreError> {
|
||||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
let user_id = parse_user_id(user_id)?;
|
||||||
|
|
||||||
Ok(self
|
Ok(self
|
||||||
.runtime
|
.runtime
|
||||||
|
@ -400,7 +400,7 @@ impl OlmMachine {
|
||||||
/// A user can be marked for tracking using the
|
/// A user can be marked for tracking using the
|
||||||
/// [`OlmMachine::update_tracked_users()`] method.
|
/// [`OlmMachine::update_tracked_users()`] method.
|
||||||
pub fn is_user_tracked(&self, user_id: &str) -> Result<bool, CryptoStoreError> {
|
pub fn is_user_tracked(&self, user_id: &str) -> Result<bool, CryptoStoreError> {
|
||||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
let user_id = parse_user_id(user_id)?;
|
||||||
Ok(self.inner.tracked_users().contains(&user_id))
|
Ok(self.inner.tracked_users().contains(&user_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -802,7 +802,7 @@ impl OlmMachine {
|
||||||
user_id: &str,
|
user_id: &str,
|
||||||
methods: Vec<String>,
|
methods: Vec<String>,
|
||||||
) -> Result<Option<String>, CryptoStoreError> {
|
) -> Result<Option<String>, CryptoStoreError> {
|
||||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
let user_id = parse_user_id(user_id)?;
|
||||||
|
|
||||||
let identity = self.runtime.block_on(self.inner.get_identity(&user_id))?;
|
let identity = self.runtime.block_on(self.inner.get_identity(&user_id))?;
|
||||||
|
|
||||||
|
@ -845,7 +845,7 @@ impl OlmMachine {
|
||||||
event_id: &str,
|
event_id: &str,
|
||||||
methods: Vec<String>,
|
methods: Vec<String>,
|
||||||
) -> Result<Option<VerificationRequest>, CryptoStoreError> {
|
) -> Result<Option<VerificationRequest>, CryptoStoreError> {
|
||||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
let user_id = parse_user_id(user_id)?;
|
||||||
let event_id = Box::<EventId>::try_from(event_id)?;
|
let event_id = Box::<EventId>::try_from(event_id)?;
|
||||||
let room_id = Box::<RoomId>::try_from(room_id)?;
|
let room_id = Box::<RoomId>::try_from(room_id)?;
|
||||||
|
|
||||||
|
@ -883,7 +883,7 @@ impl OlmMachine {
|
||||||
device_id: &str,
|
device_id: &str,
|
||||||
methods: Vec<String>,
|
methods: Vec<String>,
|
||||||
) -> Result<Option<RequestVerificationResult>, CryptoStoreError> {
|
) -> Result<Option<RequestVerificationResult>, CryptoStoreError> {
|
||||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
let user_id = parse_user_id(user_id)?;
|
||||||
|
|
||||||
let methods = methods.into_iter().map(VerificationMethod::from).collect();
|
let methods = methods.into_iter().map(VerificationMethod::from).collect();
|
||||||
|
|
||||||
|
@ -1010,7 +1010,7 @@ impl OlmMachine {
|
||||||
user_id: &str,
|
user_id: &str,
|
||||||
flow_id: &str,
|
flow_id: &str,
|
||||||
) -> Result<Option<ConfirmVerificationResult>, CryptoStoreError> {
|
) -> Result<Option<ConfirmVerificationResult>, CryptoStoreError> {
|
||||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
let user_id = parse_user_id(user_id)?;
|
||||||
|
|
||||||
Ok(
|
Ok(
|
||||||
if let Some(verification) = self.inner.get_verification(&user_id, flow_id) {
|
if let Some(verification) = self.inner.get_verification(&user_id, flow_id) {
|
||||||
|
@ -1053,7 +1053,7 @@ impl OlmMachine {
|
||||||
user_id: &str,
|
user_id: &str,
|
||||||
flow_id: &str,
|
flow_id: &str,
|
||||||
) -> Result<Option<QrCode>, CryptoStoreError> {
|
) -> Result<Option<QrCode>, CryptoStoreError> {
|
||||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
let user_id = parse_user_id(user_id)?;
|
||||||
|
|
||||||
if let Some(verification) = self.inner.get_verification_request(&user_id, flow_id) {
|
if let Some(verification) = self.inner.get_verification_request(&user_id, flow_id) {
|
||||||
Ok(self
|
Ok(self
|
||||||
|
@ -1146,7 +1146,7 @@ impl OlmMachine {
|
||||||
user_id: &str,
|
user_id: &str,
|
||||||
flow_id: &str,
|
flow_id: &str,
|
||||||
) -> Result<Option<StartSasResult>, CryptoStoreError> {
|
) -> Result<Option<StartSasResult>, CryptoStoreError> {
|
||||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
let user_id = parse_user_id(user_id)?;
|
||||||
|
|
||||||
Ok(
|
Ok(
|
||||||
if let Some(verification) = self.inner.get_verification_request(&user_id, flow_id) {
|
if let Some(verification) = self.inner.get_verification_request(&user_id, flow_id) {
|
||||||
|
@ -1181,7 +1181,7 @@ impl OlmMachine {
|
||||||
user_id: &str,
|
user_id: &str,
|
||||||
device_id: &str,
|
device_id: &str,
|
||||||
) -> Result<Option<StartSasResult>, CryptoStoreError> {
|
) -> Result<Option<StartSasResult>, CryptoStoreError> {
|
||||||
let user_id = Box::<UserId>::try_from(user_id)?;
|
let user_id = parse_user_id(user_id)?;
|
||||||
|
|
||||||
Ok(
|
Ok(
|
||||||
if let Some(device) = self
|
if let Some(device) = self
|
||||||
|
|
|
@ -44,6 +44,7 @@ enum CryptoStoreError {
|
||||||
"OlmError",
|
"OlmError",
|
||||||
"Serialization",
|
"Serialization",
|
||||||
"Identifier",
|
"Identifier",
|
||||||
|
"InvalidUserId",
|
||||||
};
|
};
|
||||||
|
|
||||||
[Error]
|
[Error]
|
||||||
|
|
Loading…
Add table
Reference in a new issue