diff --git a/matrix_sdk_crypto/src/identities/mod.rs b/matrix_sdk_crypto/src/identities/mod.rs index 853447dc..c1941b50 100644 --- a/matrix_sdk_crypto/src/identities/mod.rs +++ b/matrix_sdk_crypto/src/identities/mod.rs @@ -41,7 +41,7 @@ //! Both identity sets need to reqularly fetched from the server using the //! `/keys/query` API call. pub(crate) mod device; -mod user; +pub(crate) mod user; pub use device::{Device, LocalTrust, ReadOnlyDevice, UserDevices}; pub use user::{ diff --git a/matrix_sdk_crypto/src/identities/user.rs b/matrix_sdk_crypto/src/identities/user.rs index 1444e7ac..d3a78979 100644 --- a/matrix_sdk_crypto/src/identities/user.rs +++ b/matrix_sdk_crypto/src/identities/user.rs @@ -13,6 +13,7 @@ // limitations under the License. use std::{ + collections::{btree_map::Iter, BTreeMap}, convert::TryFrom, sync::{ atomic::{AtomicBool, Ordering}, @@ -24,7 +25,7 @@ use serde::{Deserialize, Serialize}; use serde_json::to_value; use matrix_sdk_common::{ - api::r0::keys::CrossSigningKey, + api::r0::keys::{CrossSigningKey, KeyUsage}, identifiers::{DeviceKeyId, UserId}, }; @@ -117,6 +118,21 @@ impl MasterPubkey { &self.0.user_id } + /// Get the keys map of containing the master keys. + pub fn keys(&self) -> &BTreeMap { + &self.0.keys + } + + /// Get the list of `KeyUsage` that is set for this key. + pub fn usage(&self) -> &[KeyUsage] { + &self.0.usage + } + + /// Get the signatures map of this cross signing key. + pub fn signatures(&self) -> &BTreeMap> { + &self.0.signatures + } + /// Get the master key with the given key id. /// /// # Arguments @@ -167,12 +183,26 @@ impl MasterPubkey { } } +impl<'a> IntoIterator for &'a MasterPubkey { + type Item = (&'a String, &'a String); + type IntoIter = Iter<'a, String, String>; + + fn into_iter(self) -> Self::IntoIter { + self.keys().iter() + } +} + impl UserSigningPubkey { /// Get the user id of the user signing key's owner. pub fn user_id(&self) -> &UserId { &self.0.user_id } + /// Get the keys map of containing the user signing keys. + pub fn keys(&self) -> &BTreeMap { + &self.0.keys + } + /// Check if the given master key is signed by this user signing key. /// /// # Arguments @@ -202,12 +232,26 @@ impl UserSigningPubkey { } } +impl<'a> IntoIterator for &'a UserSigningPubkey { + type Item = (&'a String, &'a String); + type IntoIter = Iter<'a, String, String>; + + fn into_iter(self) -> Self::IntoIter { + self.keys().iter() + } +} + impl SelfSigningPubkey { /// Get the user id of the self signing key's owner. pub fn user_id(&self) -> &UserId { &self.0.user_id } + /// Get the keys map of containing the self signing keys. + pub fn keys(&self) -> &BTreeMap { + &self.0.keys + } + /// Check if the given device is signed by this self signing key. /// /// # Arguments @@ -236,6 +280,15 @@ impl SelfSigningPubkey { } } +impl<'a> IntoIterator for &'a SelfSigningPubkey { + type Item = (&'a String, &'a String); + type IntoIter = Iter<'a, String, String>; + + fn into_iter(self) -> Self::IntoIter { + self.keys().iter() + } +} + /// Enum over the different user identity types we can have. #[derive(Debug, Clone)] pub enum UserIdentities { @@ -245,6 +298,12 @@ pub enum UserIdentities { Other(UserIdentity), } +impl From for UserIdentities { + fn from(identity: OwnUserIdentity) -> Self { + UserIdentities::Own(identity) + } +} + impl UserIdentities { /// The unique user id of this identity. pub fn user_id(&self) -> &UserId { @@ -504,7 +563,7 @@ impl OwnUserIdentity { } #[cfg(test)] -mod test { +pub(crate) mod test { use serde_json::json; use std::{convert::TryFrom, sync::Arc};