crypto: Identities add some methods to get the keys/signatures of the keys.
parent
f57447527d
commit
faaf3f7a29
|
@ -41,7 +41,7 @@
|
||||||
//! Both identity sets need to reqularly fetched from the server using the
|
//! Both identity sets need to reqularly fetched from the server using the
|
||||||
//! `/keys/query` API call.
|
//! `/keys/query` API call.
|
||||||
pub(crate) mod device;
|
pub(crate) mod device;
|
||||||
mod user;
|
pub(crate) mod user;
|
||||||
|
|
||||||
pub use device::{Device, LocalTrust, ReadOnlyDevice, UserDevices};
|
pub use device::{Device, LocalTrust, ReadOnlyDevice, UserDevices};
|
||||||
pub use user::{
|
pub use user::{
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
collections::{btree_map::Iter, BTreeMap},
|
||||||
convert::TryFrom,
|
convert::TryFrom,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicBool, Ordering},
|
atomic::{AtomicBool, Ordering},
|
||||||
|
@ -24,7 +25,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use serde_json::to_value;
|
use serde_json::to_value;
|
||||||
|
|
||||||
use matrix_sdk_common::{
|
use matrix_sdk_common::{
|
||||||
api::r0::keys::CrossSigningKey,
|
api::r0::keys::{CrossSigningKey, KeyUsage},
|
||||||
identifiers::{DeviceKeyId, UserId},
|
identifiers::{DeviceKeyId, UserId},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -117,6 +118,21 @@ impl MasterPubkey {
|
||||||
&self.0.user_id
|
&self.0.user_id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the keys map of containing the master keys.
|
||||||
|
pub fn keys(&self) -> &BTreeMap<String, String> {
|
||||||
|
&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<UserId, BTreeMap<String, String>> {
|
||||||
|
&self.0.signatures
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the master key with the given key id.
|
/// Get the master key with the given key id.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # 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 {
|
impl UserSigningPubkey {
|
||||||
/// Get the user id of the user signing key's owner.
|
/// Get the user id of the user signing key's owner.
|
||||||
pub fn user_id(&self) -> &UserId {
|
pub fn user_id(&self) -> &UserId {
|
||||||
&self.0.user_id
|
&self.0.user_id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the keys map of containing the user signing keys.
|
||||||
|
pub fn keys(&self) -> &BTreeMap<String, String> {
|
||||||
|
&self.0.keys
|
||||||
|
}
|
||||||
|
|
||||||
/// Check if the given master key is signed by this user signing key.
|
/// Check if the given master key is signed by this user signing key.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # 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 {
|
impl SelfSigningPubkey {
|
||||||
/// Get the user id of the self signing key's owner.
|
/// Get the user id of the self signing key's owner.
|
||||||
pub fn user_id(&self) -> &UserId {
|
pub fn user_id(&self) -> &UserId {
|
||||||
&self.0.user_id
|
&self.0.user_id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the keys map of containing the self signing keys.
|
||||||
|
pub fn keys(&self) -> &BTreeMap<String, String> {
|
||||||
|
&self.0.keys
|
||||||
|
}
|
||||||
|
|
||||||
/// Check if the given device is signed by this self signing key.
|
/// Check if the given device is signed by this self signing key.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # 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.
|
/// Enum over the different user identity types we can have.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum UserIdentities {
|
pub enum UserIdentities {
|
||||||
|
@ -245,6 +298,12 @@ pub enum UserIdentities {
|
||||||
Other(UserIdentity),
|
Other(UserIdentity),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<OwnUserIdentity> for UserIdentities {
|
||||||
|
fn from(identity: OwnUserIdentity) -> Self {
|
||||||
|
UserIdentities::Own(identity)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl UserIdentities {
|
impl UserIdentities {
|
||||||
/// The unique user id of this identity.
|
/// The unique user id of this identity.
|
||||||
pub fn user_id(&self) -> &UserId {
|
pub fn user_id(&self) -> &UserId {
|
||||||
|
@ -504,7 +563,7 @@ impl OwnUserIdentity {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
pub(crate) mod test {
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::{convert::TryFrom, sync::Arc};
|
use std::{convert::TryFrom, sync::Arc};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue