diff --git a/crates/ruma-client-api/src/keys/upload_signatures.rs b/crates/ruma-client-api/src/keys/upload_signatures.rs index 9dfa4e3b..cdf1032a 100644 --- a/crates/ruma-client-api/src/keys/upload_signatures.rs +++ b/crates/ruma-client-api/src/keys/upload_signatures.rs @@ -16,6 +16,8 @@ pub mod v3 { use crate::PrivOwnedStr; + pub use super::iter::SignedKeysIter; + ruma_api! { metadata: { description: "Publishes cross-signing signatures for the user.", @@ -81,6 +83,11 @@ pub mod v3 { ) { self.0.insert(cross_signing_key_id, cross_signing_keys.into_json()); } + + /// Returns an iterator over the keys. + pub fn iter(&self) -> SignedKeysIter<'_> { + SignedKeysIter(self.0.iter()) + } } /// A failure to process a signed key. @@ -105,3 +112,5 @@ pub mod v3 { _Custom(PrivOwnedStr), } } + +mod iter; diff --git a/crates/ruma-client-api/src/keys/upload_signatures/iter.rs b/crates/ruma-client-api/src/keys/upload_signatures/iter.rs new file mode 100644 index 00000000..95dba071 --- /dev/null +++ b/crates/ruma-client-api/src/keys/upload_signatures/iter.rs @@ -0,0 +1,26 @@ +use std::collections::btree_map; + +use serde_json::value::RawValue as RawJsonValue; + +use super::v3::SignedKeys; + +impl<'a> IntoIterator for &'a SignedKeys { + type Item = (&'a str, &'a RawJsonValue); + type IntoIter = SignedKeysIter<'a>; + + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} + +/// An iterator over signed key IDs and their associated data. +#[derive(Debug)] +pub struct SignedKeysIter<'a>(pub(super) btree_map::Iter<'a, Box, Box>); + +impl<'a> Iterator for SignedKeysIter<'a> { + type Item = (&'a str, &'a RawJsonValue); + + fn next(&mut self) -> Option { + self.0.next().map(|(id, val)| (&**id, &**val)) + } +}