Replace remaining uses of boxed IDs with dedicated owned ones
This commit is contained in:
parent
76478de953
commit
efe48af207
@ -15,7 +15,7 @@ pub mod unban_user;
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
serde::Incoming, thirdparty::Medium, OwnedServerName, ServerSigningKeyId, UserId,
|
serde::Incoming, thirdparty::Medium, OwnedServerName, OwnedServerSigningKeyId, UserId,
|
||||||
};
|
};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ pub struct ThirdPartySigned<'a> {
|
|||||||
pub token: &'a str,
|
pub token: &'a str,
|
||||||
|
|
||||||
/// A signatures object containing a signature of the entire signed object.
|
/// A signatures object containing a signature of the entire signed object.
|
||||||
pub signatures: BTreeMap<OwnedServerName, BTreeMap<Box<ServerSigningKeyId>, String>>,
|
pub signatures: BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ThirdPartySigned<'a> {
|
impl<'a> ThirdPartySigned<'a> {
|
||||||
@ -44,7 +44,7 @@ impl<'a> ThirdPartySigned<'a> {
|
|||||||
sender: &'a UserId,
|
sender: &'a UserId,
|
||||||
mxid: &'a UserId,
|
mxid: &'a UserId,
|
||||||
token: &'a str,
|
token: &'a str,
|
||||||
signatures: BTreeMap<OwnedServerName, BTreeMap<Box<ServerSigningKeyId>, String>>,
|
signatures: BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, String>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { sender, mxid, token, signatures }
|
Self { sender, mxid, token, signatures }
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,10 @@
|
|||||||
//! [`OriginalSyncMessageLikeEvent`] struct but any [`OriginalMessageLikeEvent`] struct would work.
|
//! [`OriginalSyncMessageLikeEvent`] struct but any [`OriginalMessageLikeEvent`] struct would work.
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! use ruma_common::events::{macros::EventContent, OriginalSyncMessageLikeEvent};
|
//! use ruma_common::{
|
||||||
//! use ruma_common::EventId;
|
//! events::{macros::EventContent, OriginalSyncMessageLikeEvent},
|
||||||
|
//! OwnedEventId,
|
||||||
|
//! };
|
||||||
//! use serde::{Deserialize, Serialize};
|
//! use serde::{Deserialize, Serialize};
|
||||||
//!
|
//!
|
||||||
//! #[derive(Clone, Debug, Deserialize, Serialize)]
|
//! #[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
@ -51,7 +53,7 @@
|
|||||||
//! #[serde(rename = "m.annotation")]
|
//! #[serde(rename = "m.annotation")]
|
||||||
//! Annotation {
|
//! Annotation {
|
||||||
//! /// The event this reaction relates to.
|
//! /// The event this reaction relates to.
|
||||||
//! event_id: Box<EventId>,
|
//! event_id: OwnedEventId,
|
||||||
//! /// The displayable content of the reaction.
|
//! /// The displayable content of the reaction.
|
||||||
//! key: String,
|
//! key: String,
|
||||||
//! },
|
//! },
|
||||||
|
@ -10,7 +10,7 @@ use std::{
|
|||||||
use ruma_macros::EventContent;
|
use ruma_macros::EventContent;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{RoomId, UserId};
|
use crate::{OwnedRoomId, OwnedUserId};
|
||||||
|
|
||||||
/// The content of an `m.direct` event.
|
/// The content of an `m.direct` event.
|
||||||
///
|
///
|
||||||
@ -21,10 +21,10 @@ use crate::{RoomId, UserId};
|
|||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[allow(clippy::exhaustive_structs)]
|
#[allow(clippy::exhaustive_structs)]
|
||||||
#[ruma_event(type = "m.direct", kind = GlobalAccountData)]
|
#[ruma_event(type = "m.direct", kind = GlobalAccountData)]
|
||||||
pub struct DirectEventContent(pub BTreeMap<Box<UserId>, Vec<Box<RoomId>>>);
|
pub struct DirectEventContent(pub BTreeMap<OwnedUserId, Vec<OwnedRoomId>>);
|
||||||
|
|
||||||
impl Deref for DirectEventContent {
|
impl Deref for DirectEventContent {
|
||||||
type Target = BTreeMap<Box<UserId>, Vec<Box<RoomId>>>;
|
type Target = BTreeMap<OwnedUserId, Vec<OwnedRoomId>>;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.0
|
&self.0
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
use ruma_macros::EventContent;
|
use ruma_macros::EventContent;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::EventId;
|
use crate::OwnedEventId;
|
||||||
|
|
||||||
/// The content of an `m.room.pinned_events` event.
|
/// The content of an `m.room.pinned_events` event.
|
||||||
///
|
///
|
||||||
@ -15,12 +15,12 @@ use crate::EventId;
|
|||||||
#[ruma_event(type = "m.room.pinned_events", kind = State)]
|
#[ruma_event(type = "m.room.pinned_events", kind = State)]
|
||||||
pub struct RoomPinnedEventsEventContent {
|
pub struct RoomPinnedEventsEventContent {
|
||||||
/// An ordered list of event IDs to pin.
|
/// An ordered list of event IDs to pin.
|
||||||
pub pinned: Vec<Box<EventId>>,
|
pub pinned: Vec<OwnedEventId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RoomPinnedEventsEventContent {
|
impl RoomPinnedEventsEventContent {
|
||||||
/// Creates a new `RoomPinnedEventsEventContent` with the given events.
|
/// Creates a new `RoomPinnedEventsEventContent` with the given events.
|
||||||
pub fn new(pinned: Vec<Box<EventId>>) -> Self {
|
pub fn new(pinned: Vec<OwnedEventId>) -> Self {
|
||||||
Self { pinned }
|
Self { pinned }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,10 +45,10 @@ mod tests {
|
|||||||
|
|
||||||
let event = OriginalStateEvent {
|
let event = OriginalStateEvent {
|
||||||
content: content.clone(),
|
content: content.clone(),
|
||||||
event_id: EventId::new(server_name).into(),
|
event_id: EventId::new(server_name),
|
||||||
origin_server_ts: MilliSecondsSinceUnixEpoch(1_432_804_485_886_u64.try_into().unwrap()),
|
origin_server_ts: MilliSecondsSinceUnixEpoch(1_432_804_485_886_u64.try_into().unwrap()),
|
||||||
room_id: RoomId::new(server_name).into(),
|
room_id: RoomId::new(server_name),
|
||||||
sender: UserId::new(server_name).into(),
|
sender: UserId::new(server_name),
|
||||||
state_key: "".into(),
|
state_key: "".into(),
|
||||||
unsigned: StateUnsigned::default(),
|
unsigned: StateUnsigned::default(),
|
||||||
};
|
};
|
||||||
|
@ -21,9 +21,10 @@ impl ClientSecret {
|
|||||||
/// This will currently be a UUID without hyphens, but no guarantees are made about the
|
/// This will currently be a UUID without hyphens, but no guarantees are made about the
|
||||||
/// structure of client secrets generated from this function.
|
/// structure of client secrets generated from this function.
|
||||||
#[cfg(feature = "rand")]
|
#[cfg(feature = "rand")]
|
||||||
pub fn new() -> Box<Self> {
|
#[allow(clippy::new_ret_no_self)]
|
||||||
|
pub fn new() -> OwnedClientSecret {
|
||||||
let id = uuid::Uuid::new_v4();
|
let id = uuid::Uuid::new_v4();
|
||||||
Self::from_box(id.to_simple().to_string().into_boxed_str())
|
ClientSecret::from_borrowed(&id.to_simple().to_string()).to_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ use super::generate_localpart;
|
|||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use ruma_common::{device_id, DeviceId};
|
/// use ruma_common::{device_id, DeviceId, OwnedDeviceId};
|
||||||
///
|
///
|
||||||
/// # #[cfg(feature = "rand")] {
|
/// # #[cfg(feature = "rand")] {
|
||||||
/// let random_id = DeviceId::new();
|
/// let random_id = DeviceId::new();
|
||||||
@ -24,7 +24,7 @@ use super::generate_localpart;
|
|||||||
/// let ref_id: &DeviceId = "abcdefghi".into();
|
/// let ref_id: &DeviceId = "abcdefghi".into();
|
||||||
/// assert_eq!(ref_id.as_str(), "abcdefghi");
|
/// assert_eq!(ref_id.as_str(), "abcdefghi");
|
||||||
///
|
///
|
||||||
/// let owned_id: Box<DeviceId> = "ijklmnop".into();
|
/// let owned_id: OwnedDeviceId = "ijklmnop".into();
|
||||||
/// assert_eq!(owned_id.as_str(), "ijklmnop");
|
/// assert_eq!(owned_id.as_str(), "ijklmnop");
|
||||||
/// ```
|
/// ```
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
@ -34,14 +34,15 @@ pub struct DeviceId(str);
|
|||||||
impl DeviceId {
|
impl DeviceId {
|
||||||
/// Generates a random `DeviceId`, suitable for assignment to a new device.
|
/// Generates a random `DeviceId`, suitable for assignment to a new device.
|
||||||
#[cfg(feature = "rand")]
|
#[cfg(feature = "rand")]
|
||||||
pub fn new() -> Box<Self> {
|
#[allow(clippy::new_ret_no_self)]
|
||||||
Self::from_box(generate_localpart(8))
|
pub fn new() -> OwnedDeviceId {
|
||||||
|
Self::from_borrowed(&generate_localpart(8)).to_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(test, feature = "rand"))]
|
#[cfg(all(test, feature = "rand"))]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::DeviceId;
|
use super::{DeviceId, OwnedDeviceId};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generate_device_id() {
|
fn generate_device_id() {
|
||||||
@ -56,14 +57,14 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn create_boxed_device_id_from_str() {
|
fn create_boxed_device_id_from_str() {
|
||||||
let box_id: Box<DeviceId> = "12345678".into();
|
let box_id: OwnedDeviceId = "12345678".into();
|
||||||
assert_eq!(box_id.as_str(), "12345678");
|
assert_eq!(box_id.as_str(), "12345678");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn create_device_id_from_box() {
|
fn create_device_id_from_box() {
|
||||||
let box_str: Box<str> = "ijklmnop".into();
|
let box_str: Box<str> = "ijklmnop".into();
|
||||||
let device_id: Box<DeviceId> = box_str.into();
|
let device_id: OwnedDeviceId = box_str.into();
|
||||||
assert_eq!(device_id.as_str(), "ijklmnop");
|
assert_eq!(device_id.as_str(), "ijklmnop");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ pub struct DeviceKeyId(str);
|
|||||||
|
|
||||||
impl DeviceKeyId {
|
impl DeviceKeyId {
|
||||||
/// Create a `DeviceKeyId` from a `DeviceKeyAlgorithm` and a `DeviceId`.
|
/// Create a `DeviceKeyId` from a `DeviceKeyAlgorithm` and a `DeviceId`.
|
||||||
pub fn from_parts(algorithm: DeviceKeyAlgorithm, device_id: &DeviceId) -> Box<Self> {
|
pub fn from_parts(algorithm: DeviceKeyAlgorithm, device_id: &DeviceId) -> OwnedDeviceKeyId {
|
||||||
let algorithm: &str = algorithm.as_ref();
|
let algorithm: &str = algorithm.as_ref();
|
||||||
let device_id: &str = device_id.as_ref();
|
let device_id: &str = device_id.as_ref();
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ impl DeviceKeyId {
|
|||||||
res.push(':');
|
res.push(':');
|
||||||
res.push_str(device_id);
|
res.push_str(device_id);
|
||||||
|
|
||||||
Self::from_box(res.into())
|
Self::from_borrowed(&res).to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns key algorithm of the device key ID.
|
/// Returns key algorithm of the device key ID.
|
||||||
@ -43,7 +43,7 @@ impl DeviceKeyId {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use super::DeviceKeyId;
|
use super::{DeviceKeyId, OwnedDeviceKeyId};
|
||||||
use crate::identifiers::{crypto_algorithms::DeviceKeyAlgorithm, IdParseError};
|
use crate::identifiers::{crypto_algorithms::DeviceKeyAlgorithm, IdParseError};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -65,7 +65,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_device_key_id() {
|
fn deserialize_device_key_id() {
|
||||||
let deserialized: Box<DeviceKeyId> =
|
let deserialized: OwnedDeviceKeyId =
|
||||||
serde_json::from_value(serde_json::json!("ed25519:JLAFKJWSCS")).unwrap();
|
serde_json::from_value(serde_json::json!("ed25519:JLAFKJWSCS")).unwrap();
|
||||||
|
|
||||||
let expected = <&DeviceKeyId>::try_from("ed25519:JLAFKJWSCS").unwrap();
|
let expected = <&DeviceKeyId>::try_from("ed25519:JLAFKJWSCS").unwrap();
|
||||||
|
@ -48,8 +48,10 @@ impl EventId {
|
|||||||
/// This should only be used for events in the original format as used by Matrix room versions
|
/// This should only be used for events in the original format as used by Matrix room versions
|
||||||
/// 1 and 2.
|
/// 1 and 2.
|
||||||
#[cfg(feature = "rand")]
|
#[cfg(feature = "rand")]
|
||||||
pub fn new(server_name: &ServerName) -> Box<Self> {
|
#[allow(clippy::new_ret_no_self)]
|
||||||
Self::from_box(format!("${}:{}", super::generate_localpart(18), server_name).into())
|
pub fn new(server_name: &ServerName) -> OwnedEventId {
|
||||||
|
Self::from_borrowed(&format!("${}:{}", super::generate_localpart(18), server_name))
|
||||||
|
.to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the event's unique ID.
|
/// Returns the event's unique ID.
|
||||||
@ -78,7 +80,7 @@ impl EventId {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use super::EventId;
|
use super::{EventId, OwnedEventId};
|
||||||
use crate::IdParseError;
|
use crate::IdParseError;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -158,7 +160,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn deserialize_valid_original_event_id() {
|
fn deserialize_valid_original_event_id() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serde_json::from_str::<Box<EventId>>(r#""$39hvsi03hlne:example.com""#)
|
serde_json::from_str::<OwnedEventId>(r#""$39hvsi03hlne:example.com""#)
|
||||||
.expect("Failed to convert JSON to EventId"),
|
.expect("Failed to convert JSON to EventId"),
|
||||||
<&EventId>::try_from("$39hvsi03hlne:example.com").expect("Failed to create EventId.")
|
<&EventId>::try_from("$39hvsi03hlne:example.com").expect("Failed to create EventId.")
|
||||||
);
|
);
|
||||||
@ -167,7 +169,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn deserialize_valid_base64_event_id() {
|
fn deserialize_valid_base64_event_id() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serde_json::from_str::<Box<EventId>>(
|
serde_json::from_str::<OwnedEventId>(
|
||||||
r#""$acR1l0raoZnm60CBwAVgqbZqoO/mYU81xysh1u7XcJk""#
|
r#""$acR1l0raoZnm60CBwAVgqbZqoO/mYU81xysh1u7XcJk""#
|
||||||
)
|
)
|
||||||
.expect("Failed to convert JSON to EventId"),
|
.expect("Failed to convert JSON to EventId"),
|
||||||
@ -179,7 +181,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn deserialize_valid_url_safe_base64_event_id() {
|
fn deserialize_valid_url_safe_base64_event_id() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serde_json::from_str::<Box<EventId>>(
|
serde_json::from_str::<OwnedEventId>(
|
||||||
r#""$Rqnc-F-dvnEYJTyHq_iKxU2bZ1CI92-kuZq3a5lr5Zg""#
|
r#""$Rqnc-F-dvnEYJTyHq_iKxU2bZ1CI92-kuZq3a5lr5Zg""#
|
||||||
)
|
)
|
||||||
.expect("Failed to convert JSON to EventId"),
|
.expect("Failed to convert JSON to EventId"),
|
||||||
|
@ -17,7 +17,7 @@ pub struct KeyId<A, K: ?Sized>(PhantomData<(A, K)>, str);
|
|||||||
|
|
||||||
impl<A, K: ?Sized> KeyId<A, K> {
|
impl<A, K: ?Sized> KeyId<A, K> {
|
||||||
/// Creates a new `KeyId` from an algorithm and key name.
|
/// Creates a new `KeyId` from an algorithm and key name.
|
||||||
pub fn from_parts(algorithm: A, key_name: &K) -> Box<Self>
|
pub fn from_parts(algorithm: A, key_name: &K) -> OwnedKeyId<A, K>
|
||||||
where
|
where
|
||||||
A: AsRef<str>,
|
A: AsRef<str>,
|
||||||
K: AsRef<str>,
|
K: AsRef<str>,
|
||||||
@ -30,7 +30,7 @@ impl<A, K: ?Sized> KeyId<A, K> {
|
|||||||
res.push(':');
|
res.push(':');
|
||||||
res.push_str(key_name);
|
res.push_str(key_name);
|
||||||
|
|
||||||
Self::from_box(res.into())
|
Self::from_borrowed(&res).to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns key algorithm of the key ID.
|
/// Returns key algorithm of the key ID.
|
||||||
|
@ -9,7 +9,10 @@ use ruma_identifiers_validation::{
|
|||||||
};
|
};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use super::{EventId, OwnedServerName, RoomAliasId, RoomId, RoomOrAliasId, ServerName, UserId};
|
use super::{
|
||||||
|
EventId, OwnedEventId, OwnedRoomAliasId, OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName,
|
||||||
|
OwnedUserId, RoomAliasId, RoomId, RoomOrAliasId, ServerName, UserId,
|
||||||
|
};
|
||||||
use crate::PrivOwnedStr;
|
use crate::PrivOwnedStr;
|
||||||
|
|
||||||
const MATRIX_TO_BASE_URL: &str = "https://matrix.to/#/";
|
const MATRIX_TO_BASE_URL: &str = "https://matrix.to/#/";
|
||||||
@ -46,16 +49,16 @@ const RESERVED: &AsciiSet = &CONTROLS
|
|||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum MatrixId {
|
pub enum MatrixId {
|
||||||
/// A room ID.
|
/// A room ID.
|
||||||
Room(Box<RoomId>),
|
Room(OwnedRoomId),
|
||||||
|
|
||||||
/// A room alias.
|
/// A room alias.
|
||||||
RoomAlias(Box<RoomAliasId>),
|
RoomAlias(OwnedRoomAliasId),
|
||||||
|
|
||||||
/// A user ID.
|
/// A user ID.
|
||||||
User(Box<UserId>),
|
User(OwnedUserId),
|
||||||
|
|
||||||
/// An event ID.
|
/// An event ID.
|
||||||
Event(Box<RoomOrAliasId>, Box<EventId>),
|
Event(OwnedRoomOrAliasId, OwnedEventId),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MatrixId {
|
impl MatrixId {
|
||||||
|
@ -63,7 +63,7 @@ impl RoomAliasId {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use super::RoomAliasId;
|
use super::{OwnedRoomAliasId, RoomAliasId};
|
||||||
use crate::IdParseError;
|
use crate::IdParseError;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -97,7 +97,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn deserialize_valid_room_alias_id() {
|
fn deserialize_valid_room_alias_id() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serde_json::from_str::<Box<RoomAliasId>>(r##""#ruma:example.com""##)
|
serde_json::from_str::<OwnedRoomAliasId>(r##""#ruma:example.com""##)
|
||||||
.expect("Failed to convert JSON to RoomAliasId"),
|
.expect("Failed to convert JSON to RoomAliasId"),
|
||||||
<&RoomAliasId>::try_from("#ruma:example.com").expect("Failed to create RoomAliasId.")
|
<&RoomAliasId>::try_from("#ruma:example.com").expect("Failed to create RoomAliasId.")
|
||||||
);
|
);
|
||||||
|
@ -27,8 +27,10 @@ impl RoomId {
|
|||||||
///
|
///
|
||||||
/// Fails if the given homeserver cannot be parsed as a valid host.
|
/// Fails if the given homeserver cannot be parsed as a valid host.
|
||||||
#[cfg(feature = "rand")]
|
#[cfg(feature = "rand")]
|
||||||
pub fn new(server_name: &ServerName) -> Box<Self> {
|
#[allow(clippy::new_ret_no_self)]
|
||||||
Self::from_box(format!("!{}:{}", super::generate_localpart(18), server_name).into())
|
pub fn new(server_name: &ServerName) -> OwnedRoomId {
|
||||||
|
Self::from_borrowed(&format!("!{}:{}", super::generate_localpart(18), server_name))
|
||||||
|
.to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the rooms's unique ID.
|
/// Returns the rooms's unique ID.
|
||||||
@ -110,7 +112,7 @@ impl RoomId {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use super::RoomId;
|
use super::{OwnedRoomId, RoomId};
|
||||||
use crate::IdParseError;
|
use crate::IdParseError;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -157,7 +159,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn deserialize_valid_room_id() {
|
fn deserialize_valid_room_id() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serde_json::from_str::<Box<RoomId>>(r#""!29fhd83h92h0:example.com""#)
|
serde_json::from_str::<OwnedRoomId>(r#""!29fhd83h92h0:example.com""#)
|
||||||
.expect("Failed to convert JSON to RoomId"),
|
.expect("Failed to convert JSON to RoomId"),
|
||||||
<&RoomId>::try_from("!29fhd83h92h0:example.com").expect("Failed to create RoomId.")
|
<&RoomId>::try_from("!29fhd83h92h0:example.com").expect("Failed to create RoomId.")
|
||||||
);
|
);
|
||||||
|
@ -4,7 +4,7 @@ use std::{convert::TryFrom, hint::unreachable_unchecked};
|
|||||||
|
|
||||||
use ruma_macros::IdZst;
|
use ruma_macros::IdZst;
|
||||||
|
|
||||||
use super::{server_name::ServerName, RoomAliasId, RoomId};
|
use super::{server_name::ServerName, OwnedRoomAliasId, OwnedRoomId, RoomAliasId, RoomId};
|
||||||
|
|
||||||
/// A Matrix [room ID] or a Matrix [room alias ID].
|
/// A Matrix [room ID] or a Matrix [room alias ID].
|
||||||
///
|
///
|
||||||
@ -82,15 +82,17 @@ impl<'a> From<&'a RoomAliasId> for &'a RoomOrAliasId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Box<RoomId>> for Box<RoomOrAliasId> {
|
impl From<OwnedRoomId> for OwnedRoomOrAliasId {
|
||||||
fn from(room_id: Box<RoomId>) -> Self {
|
fn from(room_id: OwnedRoomId) -> Self {
|
||||||
RoomOrAliasId::from_box(room_id.into_owned())
|
// FIXME: Don't allocate
|
||||||
|
RoomOrAliasId::from_borrowed(room_id.as_str()).to_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Box<RoomAliasId>> for Box<RoomOrAliasId> {
|
impl From<OwnedRoomAliasId> for OwnedRoomOrAliasId {
|
||||||
fn from(room_alias_id: Box<RoomAliasId>) -> Self {
|
fn from(room_alias_id: OwnedRoomAliasId) -> Self {
|
||||||
RoomOrAliasId::from_box(room_alias_id.into_owned())
|
// FIXME: Don't allocate
|
||||||
|
RoomOrAliasId::from_borrowed(room_alias_id.as_str()).to_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,24 +118,26 @@ impl<'a> TryFrom<&'a RoomOrAliasId> for &'a RoomAliasId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<Box<RoomOrAliasId>> for Box<RoomId> {
|
impl TryFrom<OwnedRoomOrAliasId> for OwnedRoomId {
|
||||||
type Error = Box<RoomAliasId>;
|
type Error = OwnedRoomAliasId;
|
||||||
|
|
||||||
fn try_from(id: Box<RoomOrAliasId>) -> Result<Box<RoomId>, Box<RoomAliasId>> {
|
fn try_from(id: OwnedRoomOrAliasId) -> Result<OwnedRoomId, OwnedRoomAliasId> {
|
||||||
|
// FIXME: Don't allocate
|
||||||
match id.variant() {
|
match id.variant() {
|
||||||
Variant::RoomId => Ok(RoomId::from_box(id.into_owned())),
|
Variant::RoomId => Ok(RoomId::from_borrowed(id.as_str()).to_owned()),
|
||||||
Variant::RoomAliasId => Err(RoomAliasId::from_box(id.into_owned())),
|
Variant::RoomAliasId => Err(RoomAliasId::from_borrowed(id.as_str()).to_owned()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<Box<RoomOrAliasId>> for Box<RoomAliasId> {
|
impl TryFrom<OwnedRoomOrAliasId> for OwnedRoomAliasId {
|
||||||
type Error = Box<RoomId>;
|
type Error = OwnedRoomId;
|
||||||
|
|
||||||
fn try_from(id: Box<RoomOrAliasId>) -> Result<Box<RoomAliasId>, Box<RoomId>> {
|
fn try_from(id: OwnedRoomOrAliasId) -> Result<OwnedRoomAliasId, OwnedRoomId> {
|
||||||
|
// FIXME: Don't allocate
|
||||||
match id.variant() {
|
match id.variant() {
|
||||||
Variant::RoomAliasId => Ok(RoomAliasId::from_box(id.into_owned())),
|
Variant::RoomAliasId => Ok(RoomAliasId::from_borrowed(id.as_str()).to_owned()),
|
||||||
Variant::RoomId => Err(RoomId::from_box(id.into_owned())),
|
Variant::RoomId => Err(RoomId::from_borrowed(id.as_str()).to_owned()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,7 +146,7 @@ impl TryFrom<Box<RoomOrAliasId>> for Box<RoomAliasId> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use super::RoomOrAliasId;
|
use super::{OwnedRoomOrAliasId, RoomOrAliasId};
|
||||||
use crate::IdParseError;
|
use crate::IdParseError;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -200,7 +204,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn deserialize_valid_room_id_or_alias_id_with_a_room_alias_id() {
|
fn deserialize_valid_room_id_or_alias_id_with_a_room_alias_id() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serde_json::from_str::<Box<RoomOrAliasId>>(r##""#ruma:example.com""##)
|
serde_json::from_str::<OwnedRoomOrAliasId>(r##""#ruma:example.com""##)
|
||||||
.expect("Failed to convert JSON to RoomAliasId"),
|
.expect("Failed to convert JSON to RoomAliasId"),
|
||||||
<&RoomOrAliasId>::try_from("#ruma:example.com").expect("Failed to create RoomAliasId.")
|
<&RoomOrAliasId>::try_from("#ruma:example.com").expect("Failed to create RoomAliasId.")
|
||||||
);
|
);
|
||||||
@ -209,7 +213,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn deserialize_valid_room_id_or_alias_id_with_a_room_id() {
|
fn deserialize_valid_room_id_or_alias_id_with_a_room_id() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serde_json::from_str::<Box<RoomOrAliasId>>(r##""!29fhd83h92h0:example.com""##)
|
serde_json::from_str::<OwnedRoomOrAliasId>(r##""!29fhd83h92h0:example.com""##)
|
||||||
.expect("Failed to convert JSON to RoomId"),
|
.expect("Failed to convert JSON to RoomId"),
|
||||||
<&RoomOrAliasId>::try_from("!29fhd83h92h0:example.com")
|
<&RoomOrAliasId>::try_from("!29fhd83h92h0:example.com")
|
||||||
.expect("Failed to create RoomAliasId.")
|
.expect("Failed to create RoomAliasId.")
|
||||||
|
@ -2,15 +2,15 @@ use std::{borrow::Borrow, collections::BTreeMap};
|
|||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::{DeviceId, KeyName, ServerName, SigningKeyId, UserId};
|
use super::{OwnedDeviceId, OwnedKeyName, OwnedServerName, OwnedSigningKeyId, OwnedUserId};
|
||||||
|
|
||||||
/// Map of key identifier to signature values.
|
/// Map of key identifier to signature values.
|
||||||
pub type EntitySignatures<K> = BTreeMap<Box<SigningKeyId<K>>, String>;
|
pub type EntitySignatures<K> = BTreeMap<OwnedSigningKeyId<K>, String>;
|
||||||
|
|
||||||
/// Map of all signatures, grouped by entity
|
/// Map of all signatures, grouped by entity
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use ruma_common::{server_name, {KeyId, Signatures, SigningKeyAlgorithm}};
|
/// # use ruma_common::{server_name, KeyId, Signatures, SigningKeyAlgorithm};
|
||||||
/// let key_identifier = KeyId::from_parts(SigningKeyAlgorithm::Ed25519, "1");
|
/// let key_identifier = KeyId::from_parts(SigningKeyAlgorithm::Ed25519, "1");
|
||||||
/// let mut signatures = Signatures::new();
|
/// let mut signatures = Signatures::new();
|
||||||
/// let server_name = server_name!("example.org");
|
/// let server_name = server_name!("example.org");
|
||||||
@ -34,7 +34,7 @@ impl<E: Ord, K: ?Sized> Signatures<E, K> {
|
|||||||
pub fn insert(
|
pub fn insert(
|
||||||
&mut self,
|
&mut self,
|
||||||
entity: E,
|
entity: E,
|
||||||
key_identifier: Box<SigningKeyId<K>>,
|
key_identifier: OwnedSigningKeyId<K>,
|
||||||
value: String,
|
value: String,
|
||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
self.0.entry(entity).or_insert_with(Default::default).insert(key_identifier, value)
|
self.0.entry(entity).or_insert_with(Default::default).insert(key_identifier, value)
|
||||||
@ -51,7 +51,7 @@ impl<E: Ord, K: ?Sized> Signatures<E, K> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Map of server signatures for an event, grouped by server.
|
/// Map of server signatures for an event, grouped by server.
|
||||||
pub type ServerSignatures = Signatures<Box<ServerName>, Box<KeyName>>;
|
pub type ServerSignatures = Signatures<OwnedServerName, OwnedKeyName>;
|
||||||
|
|
||||||
/// Map of device signatures for an event, grouped by user.
|
/// Map of device signatures for an event, grouped by user.
|
||||||
pub type DeviceSignatures = Signatures<UserId, Box<DeviceId>>;
|
pub type DeviceSignatures = Signatures<OwnedUserId, OwnedDeviceId>;
|
||||||
|
@ -18,8 +18,9 @@ impl TransactionId {
|
|||||||
/// This will currently be a UUID without hyphens, but no guarantees are made about the
|
/// This will currently be a UUID without hyphens, but no guarantees are made about the
|
||||||
/// structure of transaction IDs generated from this function.
|
/// structure of transaction IDs generated from this function.
|
||||||
#[cfg(feature = "rand")]
|
#[cfg(feature = "rand")]
|
||||||
pub fn new() -> Box<Self> {
|
#[allow(clippy::new_ret_no_self)]
|
||||||
|
pub fn new() -> OwnedTransactionId {
|
||||||
let id = uuid::Uuid::new_v4();
|
let id = uuid::Uuid::new_v4();
|
||||||
Self::from_box(id.to_simple().to_string().into_boxed_str())
|
Self::from_borrowed(&id.to_simple().to_string()).to_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,14 @@ impl UserId {
|
|||||||
/// Attempts to generate a `UserId` for the given origin server with a localpart consisting of
|
/// Attempts to generate a `UserId` for the given origin server with a localpart consisting of
|
||||||
/// 12 random ASCII characters.
|
/// 12 random ASCII characters.
|
||||||
#[cfg(feature = "rand")]
|
#[cfg(feature = "rand")]
|
||||||
pub fn new(server_name: &ServerName) -> Box<Self> {
|
#[allow(clippy::new_ret_no_self)]
|
||||||
Self::from_box(
|
pub fn new(server_name: &ServerName) -> OwnedUserId {
|
||||||
format!("@{}:{}", super::generate_localpart(12).to_lowercase(), server_name).into(),
|
Self::from_borrowed(&format!(
|
||||||
)
|
"@{}:{}",
|
||||||
|
super::generate_localpart(12).to_lowercase(),
|
||||||
|
server_name
|
||||||
|
))
|
||||||
|
.to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempts to complete a user ID, by adding the colon + server name and `@` prefix, if not
|
/// Attempts to complete a user ID, by adding the colon + server name and `@` prefix, if not
|
||||||
@ -41,14 +45,14 @@ impl UserId {
|
|||||||
pub fn parse_with_server_name(
|
pub fn parse_with_server_name(
|
||||||
id: impl AsRef<str> + Into<Box<str>>,
|
id: impl AsRef<str> + Into<Box<str>>,
|
||||||
server_name: &ServerName,
|
server_name: &ServerName,
|
||||||
) -> Result<Box<Self>, IdParseError> {
|
) -> Result<OwnedUserId, IdParseError> {
|
||||||
let id_str = id.as_ref();
|
let id_str = id.as_ref();
|
||||||
|
|
||||||
if id_str.starts_with('@') {
|
if id_str.starts_with('@') {
|
||||||
Self::parse(id)
|
Self::parse(id).map(Into::into)
|
||||||
} else {
|
} else {
|
||||||
let _ = localpart_is_fully_conforming(id_str)?;
|
let _ = localpart_is_fully_conforming(id_str)?;
|
||||||
Ok(Self::from_box(format!("@{}:{}", id_str, server_name).into()))
|
Ok(Self::from_borrowed(&format!("@{}:{}", id_str, server_name)).to_owned())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +157,7 @@ use ruma_macros::IdZst;
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use super::UserId;
|
use super::{OwnedUserId, UserId};
|
||||||
use crate::{server_name, IdParseError};
|
use crate::{server_name, IdParseError};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -272,7 +276,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn deserialize_valid_user_id() {
|
fn deserialize_valid_user_id() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serde_json::from_str::<Box<UserId>>(r#""@carl:example.com""#)
|
serde_json::from_str::<OwnedUserId>(r#""@carl:example.com""#)
|
||||||
.expect("Failed to convert JSON to UserId"),
|
.expect("Failed to convert JSON to UserId"),
|
||||||
<&UserId>::try_from("@carl:example.com").expect("Failed to create UserId.")
|
<&UserId>::try_from("@carl:example.com").expect("Failed to create UserId.")
|
||||||
);
|
);
|
||||||
|
@ -12,15 +12,15 @@ use ruma_common::{
|
|||||||
AuthScheme, EndpointError, IncomingRequest, IncomingResponse, MatrixVersion, Metadata,
|
AuthScheme, EndpointError, IncomingRequest, IncomingResponse, MatrixVersion, Metadata,
|
||||||
OutgoingRequest, OutgoingResponse, SendAccessToken,
|
OutgoingRequest, OutgoingResponse, SendAccessToken,
|
||||||
},
|
},
|
||||||
RoomAliasId, RoomId,
|
OwnedRoomAliasId, OwnedRoomId,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// A request to create a new room alias.
|
/// A request to create a new room alias.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Request {
|
pub struct Request {
|
||||||
pub room_id: Box<RoomId>, // body
|
pub room_id: OwnedRoomId, // body
|
||||||
pub room_alias: Box<RoomAliasId>, // path
|
pub room_alias: OwnedRoomAliasId, // path
|
||||||
}
|
}
|
||||||
|
|
||||||
const METADATA: Metadata = Metadata {
|
const METADATA: Metadata = Metadata {
|
||||||
@ -104,7 +104,7 @@ impl IncomingRequest for Request {
|
|||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
struct RequestBody {
|
struct RequestBody {
|
||||||
room_id: Box<RoomId>,
|
room_id: OwnedRoomId,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The response to a request to create a new room alias.
|
/// The response to a request to create a new room alias.
|
||||||
|
@ -5,7 +5,7 @@ pub mod some_endpoint {
|
|||||||
api::ruma_api,
|
api::ruma_api,
|
||||||
events::{tag::TagEvent, AnyRoomEvent},
|
events::{tag::TagEvent, AnyRoomEvent},
|
||||||
serde::Raw,
|
serde::Raw,
|
||||||
UserId,
|
OwnedUserId,
|
||||||
};
|
};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
@ -33,7 +33,7 @@ pub mod some_endpoint {
|
|||||||
// This value will be inserted into the request's URL in place of the
|
// This value will be inserted into the request's URL in place of the
|
||||||
// ":user" path component.
|
// ":user" path component.
|
||||||
#[ruma_api(path)]
|
#[ruma_api(path)]
|
||||||
pub user: Box<UserId>,
|
pub user: OwnedUserId,
|
||||||
}
|
}
|
||||||
|
|
||||||
response: {
|
response: {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// consume the request/response.
|
// consume the request/response.
|
||||||
|
|
||||||
mod newtype_body {
|
mod newtype_body {
|
||||||
use ruma_common::{api::ruma_api, UserId};
|
use ruma_common::{api::ruma_api, OwnedUserId};
|
||||||
|
|
||||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||||
pub struct Foo;
|
pub struct Foo;
|
||||||
@ -25,7 +25,7 @@ mod newtype_body {
|
|||||||
pub bar: String,
|
pub bar: String,
|
||||||
|
|
||||||
#[ruma_api(query)]
|
#[ruma_api(query)]
|
||||||
pub baz: Box<UserId>,
|
pub baz: OwnedUserId,
|
||||||
|
|
||||||
#[ruma_api(header = CONTENT_TYPE)]
|
#[ruma_api(header = CONTENT_TYPE)]
|
||||||
pub world: String,
|
pub world: String,
|
||||||
@ -42,7 +42,7 @@ mod newtype_body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod raw_body {
|
mod raw_body {
|
||||||
use ruma_common::{api::ruma_api, UserId};
|
use ruma_common::{api::ruma_api, OwnedUserId};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -62,7 +62,7 @@ mod raw_body {
|
|||||||
pub bar: String,
|
pub bar: String,
|
||||||
|
|
||||||
#[ruma_api(query)]
|
#[ruma_api(query)]
|
||||||
pub baz: Box<UserId>,
|
pub baz: OwnedUserId,
|
||||||
|
|
||||||
#[ruma_api(header = CONTENT_TYPE)]
|
#[ruma_api(header = CONTENT_TYPE)]
|
||||||
pub world: String,
|
pub world: String,
|
||||||
@ -79,7 +79,7 @@ mod raw_body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod plain {
|
mod plain {
|
||||||
use ruma_common::{api::ruma_api, UserId};
|
use ruma_common::{api::ruma_api, OwnedUserId};
|
||||||
|
|
||||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||||
pub struct Foo;
|
pub struct Foo;
|
||||||
@ -101,7 +101,7 @@ mod plain {
|
|||||||
pub bar: String,
|
pub bar: String,
|
||||||
|
|
||||||
#[ruma_api(query)]
|
#[ruma_api(query)]
|
||||||
pub baz: Box<UserId>,
|
pub baz: OwnedUserId,
|
||||||
|
|
||||||
#[ruma_api(header = CONTENT_TYPE)]
|
#[ruma_api(header = CONTENT_TYPE)]
|
||||||
pub world: String,
|
pub world: String,
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use ruma_common::{serde::Base64, MilliSecondsSinceUnixEpoch, OwnedServerName, ServerSigningKeyId};
|
use ruma_common::{
|
||||||
|
serde::Base64, MilliSecondsSinceUnixEpoch, OwnedServerName, OwnedServerSigningKeyId,
|
||||||
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub mod discover_homeserver;
|
pub mod discover_homeserver;
|
||||||
@ -55,15 +57,15 @@ pub struct ServerSigningKeys {
|
|||||||
pub server_name: OwnedServerName,
|
pub server_name: OwnedServerName,
|
||||||
|
|
||||||
/// Public keys of the homeserver for verifying digital signatures.
|
/// Public keys of the homeserver for verifying digital signatures.
|
||||||
pub verify_keys: BTreeMap<Box<ServerSigningKeyId>, VerifyKey>,
|
pub verify_keys: BTreeMap<OwnedServerSigningKeyId, VerifyKey>,
|
||||||
|
|
||||||
/// Public keys that the homeserver used to use and when it stopped using them.
|
/// Public keys that the homeserver used to use and when it stopped using them.
|
||||||
pub old_verify_keys: BTreeMap<Box<ServerSigningKeyId>, OldVerifyKey>,
|
pub old_verify_keys: BTreeMap<OwnedServerSigningKeyId, OldVerifyKey>,
|
||||||
|
|
||||||
/// Digital signatures of this object signed using the verify_keys.
|
/// Digital signatures of this object signed using the verify_keys.
|
||||||
///
|
///
|
||||||
/// Map of server name to keys by key ID.
|
/// Map of server name to keys by key ID.
|
||||||
pub signatures: BTreeMap<OwnedServerName, BTreeMap<Box<ServerSigningKeyId>, String>>,
|
pub signatures: BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, String>>,
|
||||||
|
|
||||||
/// Timestamp when the keys should be refreshed.
|
/// Timestamp when the keys should be refreshed.
|
||||||
///
|
///
|
||||||
|
@ -11,7 +11,8 @@ pub mod v2 {
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
api::ruma_api, serde::Raw, MilliSecondsSinceUnixEpoch, OwnedServerName, ServerSigningKeyId,
|
api::ruma_api, serde::Raw, MilliSecondsSinceUnixEpoch, OwnedServerName,
|
||||||
|
OwnedServerSigningKeyId,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ pub mod v2 {
|
|||||||
/// notary server must return an empty server_keys array in the response.
|
/// notary server must return an empty server_keys array in the response.
|
||||||
///
|
///
|
||||||
/// The notary server may return multiple keys regardless of the Key IDs given.
|
/// The notary server may return multiple keys regardless of the Key IDs given.
|
||||||
pub server_keys: BTreeMap<OwnedServerName, BTreeMap<Box<ServerSigningKeyId>, QueryCriteria>>,
|
pub server_keys: BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, QueryCriteria>>,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ pub mod v2 {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
server_keys: BTreeMap<
|
server_keys: BTreeMap<
|
||||||
OwnedServerName,
|
OwnedServerName,
|
||||||
BTreeMap<Box<ServerSigningKeyId>, QueryCriteria>,
|
BTreeMap<OwnedServerSigningKeyId, QueryCriteria>,
|
||||||
>,
|
>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { server_keys }
|
Self { server_keys }
|
||||||
|
@ -13,7 +13,7 @@ pub mod v1 {
|
|||||||
api::ruma_api,
|
api::ruma_api,
|
||||||
encryption::OneTimeKey,
|
encryption::OneTimeKey,
|
||||||
serde::{Base64, Raw},
|
serde::{Base64, Raw},
|
||||||
DeviceKeyAlgorithm, DeviceKeyId, OwnedDeviceId, OwnedUserId,
|
DeviceKeyAlgorithm, OwnedDeviceId, OwnedDeviceKeyId, OwnedUserId,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ pub mod v1 {
|
|||||||
|
|
||||||
/// One time keys for use in pre-key messages
|
/// One time keys for use in pre-key messages
|
||||||
pub type OneTimeKeys =
|
pub type OneTimeKeys =
|
||||||
BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceId, BTreeMap<Box<DeviceKeyId>, Raw<OneTimeKey>>>>;
|
BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceId, BTreeMap<OwnedDeviceKeyId, Raw<OneTimeKey>>>>;
|
||||||
|
|
||||||
/// A key and its signature
|
/// A key and its signature
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
@ -68,14 +68,14 @@ pub mod v1 {
|
|||||||
pub key: Base64,
|
pub key: Base64,
|
||||||
|
|
||||||
/// Signature of the key object.
|
/// Signature of the key object.
|
||||||
pub signatures: BTreeMap<OwnedUserId, BTreeMap<Box<DeviceKeyId>, String>>,
|
pub signatures: BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceKeyId, String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KeyObject {
|
impl KeyObject {
|
||||||
/// Creates a new `KeyObject` with the given key and signatures.
|
/// Creates a new `KeyObject` with the given key and signatures.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
key: Base64,
|
key: Base64,
|
||||||
signatures: BTreeMap<OwnedUserId, BTreeMap<Box<DeviceKeyId>, String>>,
|
signatures: BTreeMap<OwnedUserId, BTreeMap<OwnedDeviceKeyId, String>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { key, signatures }
|
Self { key, signatures }
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ pub mod v1 {
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
api::ruma_api, thirdparty::Medium, OwnedRoomId, OwnedServerName, OwnedUserId,
|
api::ruma_api, thirdparty::Medium, OwnedRoomId, OwnedServerName, OwnedServerSigningKeyId,
|
||||||
ServerSigningKeyId, UserId,
|
OwnedUserId, UserId,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ pub mod v1 {
|
|||||||
pub sender: OwnedUserId,
|
pub sender: OwnedUserId,
|
||||||
|
|
||||||
/// Signature from the identity server using a long-term private key.
|
/// Signature from the identity server using a long-term private key.
|
||||||
pub signed: BTreeMap<OwnedServerName, BTreeMap<Box<ServerSigningKeyId>, String>>,
|
pub signed: BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ThirdPartyInvite {
|
impl ThirdPartyInvite {
|
||||||
@ -98,7 +98,7 @@ pub mod v1 {
|
|||||||
mxid: OwnedUserId,
|
mxid: OwnedUserId,
|
||||||
room_id: OwnedRoomId,
|
room_id: OwnedRoomId,
|
||||||
sender: OwnedUserId,
|
sender: OwnedUserId,
|
||||||
signed: BTreeMap<OwnedServerName, BTreeMap<Box<ServerSigningKeyId>, String>>,
|
signed: BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, String>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { medium: Medium::Email, address, mxid, room_id, sender, signed }
|
Self { medium: Medium::Email, address, mxid, room_id, sender, signed }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user