Skip to main content

matrix_sdk_crypto_ffi/
users.rs

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