matrix_sdk_crypto_ffi/
users.rs

1use matrix_sdk_crypto::{types::CrossSigningKey, UserIdentity as SdkUserIdentity};
2
3use crate::CryptoStoreError;
4
5/// Enum representing cross signing identity of our own user or some other
6/// user.
7#[derive(uniffi::Enum)]
8pub enum UserIdentity {
9    /// Our own user identity.
10    Own {
11        /// The unique id of our own user.
12        user_id: String,
13        /// Does our own user identity trust our own device.
14        trusts_our_own_device: bool,
15        /// The public master key of our identity.
16        master_key: String,
17        /// The public user-signing key of our identity.
18        user_signing_key: String,
19        /// The public self-signing key of our identity.
20        self_signing_key: String,
21        /// True if this identity was verified at some point but is not anymore.
22        has_verification_violation: bool,
23    },
24    /// The user identity of other users.
25    Other {
26        /// The unique id of the user.
27        user_id: String,
28        /// The public master key of the identity.
29        master_key: String,
30        /// The public self-signing key of our identity.
31        self_signing_key: String,
32        /// True if this identity was verified at some point but is not anymore.
33        has_verification_violation: bool,
34    },
35}
36
37impl UserIdentity {
38    pub(crate) async fn from_rust(i: SdkUserIdentity) -> Result<Self, CryptoStoreError> {
39        Ok(match i {
40            SdkUserIdentity::Own(i) => {
41                let master: CrossSigningKey = i.master_key().as_ref().to_owned();
42                let user_signing: CrossSigningKey = i.user_signing_key().as_ref().to_owned();
43                let self_signing: CrossSigningKey = i.self_signing_key().as_ref().to_owned();
44
45                UserIdentity::Own {
46                    user_id: i.user_id().to_string(),
47                    trusts_our_own_device: i.trusts_our_own_device().await?,
48                    master_key: serde_json::to_string(&master)?,
49                    user_signing_key: serde_json::to_string(&user_signing)?,
50                    self_signing_key: serde_json::to_string(&self_signing)?,
51                    has_verification_violation: i.has_verification_violation(),
52                }
53            }
54            SdkUserIdentity::Other(i) => {
55                let master: CrossSigningKey = i.master_key().as_ref().to_owned();
56                let self_signing: CrossSigningKey = i.self_signing_key().as_ref().to_owned();
57
58                UserIdentity::Other {
59                    user_id: i.user_id().to_string(),
60                    master_key: serde_json::to_string(&master)?,
61                    self_signing_key: serde_json::to_string(&self_signing)?,
62                    has_verification_violation: i.has_verification_violation(),
63                }
64            }
65        })
66    }
67}