matrix_sdk_crypto_ffi/
users.rsuse matrix_sdk_crypto::{types::CrossSigningKey, UserIdentity as SdkUserIdentity};
use crate::CryptoStoreError;
#[derive(uniffi::Enum)]
pub enum UserIdentity {
Own {
user_id: String,
trusts_our_own_device: bool,
master_key: String,
user_signing_key: String,
self_signing_key: String,
has_verification_violation: bool,
},
Other {
user_id: String,
master_key: String,
self_signing_key: String,
has_verification_violation: bool,
},
}
impl UserIdentity {
pub(crate) async fn from_rust(i: SdkUserIdentity) -> Result<Self, CryptoStoreError> {
Ok(match i {
SdkUserIdentity::Own(i) => {
let master: CrossSigningKey = i.master_key().as_ref().to_owned();
let user_signing: CrossSigningKey = i.user_signing_key().as_ref().to_owned();
let self_signing: CrossSigningKey = i.self_signing_key().as_ref().to_owned();
UserIdentity::Own {
user_id: i.user_id().to_string(),
trusts_our_own_device: i.trusts_our_own_device().await?,
master_key: serde_json::to_string(&master)?,
user_signing_key: serde_json::to_string(&user_signing)?,
self_signing_key: serde_json::to_string(&self_signing)?,
has_verification_violation: i.has_verification_violation(),
}
}
SdkUserIdentity::Other(i) => {
let master: CrossSigningKey = i.master_key().as_ref().to_owned();
let self_signing: CrossSigningKey = i.self_signing_key().as_ref().to_owned();
UserIdentity::Other {
user_id: i.user_id().to_string(),
master_key: serde_json::to_string(&master)?,
self_signing_key: serde_json::to_string(&self_signing)?,
has_verification_violation: i.has_verification_violation(),
}
}
})
}
}