matrix_sdk_crypto_ffi/
device.rs

1use std::collections::HashMap;
2
3use matrix_sdk_crypto::Device as InnerDevice;
4
5/// An E2EE capable Matrix device.
6#[derive(uniffi::Record)]
7pub struct Device {
8    /// The device owner.
9    pub user_id: String,
10    /// The unique ID of the device.
11    pub device_id: String,
12    /// The published public identity keys of the devices
13    ///
14    /// A map from the key type (e.g. curve25519) to the base64 encoded key.
15    pub keys: HashMap<String, String>,
16    /// The supported algorithms of the device.
17    pub algorithms: Vec<String>,
18    /// The human readable name of the device.
19    pub display_name: Option<String>,
20    /// A flag indicating if the device has been blocked, blocked devices don't
21    /// receive any room keys from us.
22    pub is_blocked: bool,
23    /// Is the device locally trusted
24    pub locally_trusted: bool,
25    /// Is our cross signing identity trusted and does the identity trust the
26    /// device.
27    pub cross_signing_trusted: bool,
28    /// The first time this device was seen in local timestamp, milliseconds
29    /// since epoch.
30    pub first_time_seen_ts: u64,
31    /// Whether or not the device is a dehydrated device.
32    pub dehydrated: bool,
33}
34
35impl From<InnerDevice> for Device {
36    fn from(d: InnerDevice) -> Self {
37        Device {
38            user_id: d.user_id().to_string(),
39            device_id: d.device_id().to_string(),
40            keys: d.keys().iter().map(|(k, v)| (k.to_string(), v.to_base64())).collect(),
41            algorithms: d.algorithms().iter().map(|a| a.to_string()).collect(),
42            display_name: d.display_name().map(|d| d.to_owned()),
43            is_blocked: d.is_blacklisted(),
44            locally_trusted: d.is_locally_trusted(),
45            cross_signing_trusted: d.is_cross_signing_trusted(),
46            first_time_seen_ts: d.first_time_seen_ts().0.into(),
47            dehydrated: d.is_dehydrated(),
48        }
49    }
50}