2021-04-07 16:04:22 +03:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
use matrix_sdk_crypto::Device as InnerDevice;
|
|
|
|
|
2021-04-14 13:15:47 +03:00
|
|
|
/// An E2EE capable Matrix device.
|
2021-04-07 16:04:22 +03:00
|
|
|
pub struct Device {
|
2021-04-14 13:15:47 +03:00
|
|
|
/// The device owner.
|
2021-04-07 16:04:22 +03:00
|
|
|
pub user_id: String,
|
2021-04-14 13:15:47 +03:00
|
|
|
/// The unique ID of the device.
|
2021-04-07 16:04:22 +03:00
|
|
|
pub device_id: String,
|
2021-04-14 13:15:47 +03:00
|
|
|
/// The published public identity keys of the devices
|
|
|
|
///
|
|
|
|
/// A map from the key type (e.g. curve25519) to the base64 encoded key.
|
2021-04-07 16:04:22 +03:00
|
|
|
pub keys: HashMap<String, String>,
|
2021-04-14 13:15:47 +03:00
|
|
|
/// The supported algorithms of the device.
|
2021-04-09 14:53:55 +03:00
|
|
|
pub algorithms: Vec<String>,
|
2021-04-14 13:15:47 +03:00
|
|
|
/// The human readable name of the device.
|
2021-04-09 14:53:55 +03:00
|
|
|
pub display_name: Option<String>,
|
2021-04-14 13:15:47 +03:00
|
|
|
/// A flag indicating if the device has been blocked, blocked devices don't
|
|
|
|
/// receive any room keys from us.
|
2021-04-09 14:53:55 +03:00
|
|
|
pub is_blocked: bool,
|
2021-06-24 14:57:13 +03:00
|
|
|
/// Is the device locally trusted
|
|
|
|
pub locally_trusted: bool,
|
|
|
|
/// Is our cross signing identity trusted and does the identity trust the
|
|
|
|
/// device.
|
|
|
|
pub cross_signing_trusted: bool,
|
2021-04-07 16:04:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<InnerDevice> for Device {
|
|
|
|
fn from(d: InnerDevice) -> Self {
|
|
|
|
Device {
|
|
|
|
user_id: d.user_id().to_string(),
|
|
|
|
device_id: d.device_id().to_string(),
|
|
|
|
keys: d
|
|
|
|
.keys()
|
|
|
|
.iter()
|
|
|
|
.map(|(k, v)| (k.to_string(), v.to_string()))
|
|
|
|
.collect(),
|
2021-04-09 14:53:55 +03:00
|
|
|
algorithms: d.algorithms().iter().map(|a| a.to_string()).collect(),
|
|
|
|
display_name: d.display_name().clone(),
|
|
|
|
is_blocked: d.is_blacklisted(),
|
2021-06-24 14:57:13 +03:00
|
|
|
locally_trusted: d.is_locally_trusted(),
|
|
|
|
cross_signing_trusted: d.is_cross_signing_trusted(),
|
2021-04-07 16:04:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|