1#![allow(unused_qualifications)]
6
7#[doc(inline)]
8pub use ruma_identifiers_validation::{
9 error::{
10 Error as IdParseError, MatrixIdError, MatrixToError, MatrixUriError, MxcUriError,
11 VoipVersionIdError,
12 },
13 KeyName,
14};
15use serde::de::{self, Deserializer, Unexpected};
16
17#[doc(inline)]
18pub use self::{
19 base64_public_key::{Base64PublicKey, OwnedBase64PublicKey},
20 base64_public_key_or_device_id::{Base64PublicKeyOrDeviceId, OwnedBase64PublicKeyOrDeviceId},
21 client_secret::{ClientSecret, OwnedClientSecret},
22 crypto_algorithms::{
23 DeviceKeyAlgorithm, EventEncryptionAlgorithm, KeyDerivationAlgorithm, OneTimeKeyAlgorithm,
24 SigningKeyAlgorithm,
25 },
26 device_id::{DeviceId, OwnedDeviceId},
27 event_id::{EventId, OwnedEventId},
28 key_id::{
29 AnyKeyName, CrossSigningKeyId, CrossSigningOrDeviceSigningKeyId, DeviceKeyId,
30 DeviceSigningKeyId, KeyAlgorithm, KeyId, OneTimeKeyId, OwnedCrossSigningKeyId,
31 OwnedCrossSigningOrDeviceSigningKeyId, OwnedDeviceKeyId, OwnedDeviceSigningKeyId,
32 OwnedKeyId, OwnedOneTimeKeyId, OwnedServerSigningKeyId, OwnedSigningKeyId,
33 ServerSigningKeyId, SigningKeyId,
34 },
35 matrix_uri::{MatrixToUri, MatrixUri},
36 mxc_uri::{MxcUri, OwnedMxcUri},
37 one_time_key_name::{OneTimeKeyName, OwnedOneTimeKeyName},
38 room_alias_id::{OwnedRoomAliasId, RoomAliasId},
39 room_id::{OwnedRoomId, RoomId},
40 room_or_alias_id::{OwnedRoomOrAliasId, RoomOrAliasId},
41 room_version_id::RoomVersionId,
42 server_name::{OwnedServerName, ServerName},
43 server_signing_key_version::{OwnedServerSigningKeyVersion, ServerSigningKeyVersion},
44 session_id::{OwnedSessionId, SessionId},
45 signatures::{
46 CrossSigningOrDeviceSignatures, DeviceSignatures, EntitySignatures, ServerSignatures,
47 Signatures,
48 },
49 transaction_id::{OwnedTransactionId, TransactionId},
50 user_id::{OwnedUserId, UserId},
51 voip_id::{OwnedVoipId, VoipId},
52 voip_version_id::VoipVersionId,
53};
54
55pub mod matrix_uri;
56pub mod user_id;
57
58mod base64_public_key;
59mod base64_public_key_or_device_id;
60mod client_secret;
61mod crypto_algorithms;
62mod device_id;
63mod event_id;
64mod key_id;
65mod mxc_uri;
66mod one_time_key_name;
67mod room_alias_id;
68mod room_id;
69mod room_or_alias_id;
70mod room_version_id;
71mod server_name;
72mod server_signing_key_version;
73mod session_id;
74mod signatures;
75mod transaction_id;
76mod voip_id;
77mod voip_version_id;
78
79#[cfg(feature = "rand")]
81fn generate_localpart(length: usize) -> Box<str> {
82 use rand::Rng as _;
83 rand::thread_rng()
84 .sample_iter(&rand::distributions::Alphanumeric)
85 .map(char::from)
86 .take(length)
87 .collect::<String>()
88 .into_boxed_str()
89}
90
91fn deserialize_id<'de, D, T>(deserializer: D, expected_str: &str) -> Result<T, D::Error>
95where
96 D: Deserializer<'de>,
97 T: for<'a> TryFrom<&'a str>,
98{
99 crate::serde::deserialize_cow_str(deserializer).and_then(|v| {
100 T::try_from(&v).map_err(|_| de::Error::invalid_value(Unexpected::Str(&v), &expected_str))
101 })
102}
103
104#[macro_export]
106macro_rules! device_id {
107 ($s:expr) => {
108 <&$crate::DeviceId as ::std::convert::From<_>>::from($s)
109 };
110}
111
112#[macro_export]
114macro_rules! owned_device_id {
115 ($s:expr) => {
116 <$crate::OwnedDeviceId as ::std::convert::From<_>>::from($s)
117 };
118}
119
120#[doc(hidden)]
121pub mod __private_macros {
122 pub use ruma_macros::{
123 base64_public_key, event_id, mxc_uri, room_alias_id, room_id, room_version_id, server_name,
124 server_signing_key_version, user_id,
125 };
126}
127
128#[macro_export]
130macro_rules! event_id {
131 ($s:literal) => {
132 $crate::__private_macros::event_id!($crate, $s)
133 };
134}
135
136#[macro_export]
138macro_rules! owned_event_id {
139 ($s:literal) => {
140 $crate::event_id!($s).to_owned()
141 };
142}
143
144#[macro_export]
146macro_rules! room_alias_id {
147 ($s:literal) => {
148 $crate::__private_macros::room_alias_id!($crate, $s)
149 };
150}
151
152#[macro_export]
154macro_rules! owned_room_alias_id {
155 ($s:literal) => {
156 $crate::room_alias_id!($s).to_owned()
157 };
158}
159
160#[macro_export]
162macro_rules! room_id {
163 ($s:literal) => {
164 $crate::__private_macros::room_id!($crate, $s)
165 };
166}
167
168#[macro_export]
170macro_rules! owned_room_id {
171 ($s:literal) => {
172 $crate::room_id!($s).to_owned()
173 };
174}
175
176#[macro_export]
178macro_rules! room_version_id {
179 ($s:literal) => {
180 $crate::__private_macros::room_version_id!($crate, $s)
181 };
182}
183
184#[macro_export]
186macro_rules! server_signing_key_version {
187 ($s:literal) => {
188 $crate::__private_macros::server_signing_key_version!($crate, $s)
189 };
190}
191
192#[macro_export]
194macro_rules! owned_server_signing_key_version {
195 ($s:literal) => {
196 $crate::server_signing_key_version!($s).to_owned()
197 };
198}
199
200#[macro_export]
202macro_rules! server_name {
203 ($s:literal) => {
204 $crate::__private_macros::server_name!($crate, $s)
205 };
206}
207
208#[macro_export]
210macro_rules! owned_server_name {
211 ($s:literal) => {
212 $crate::server_name!($s).to_owned()
213 };
214}
215
216#[macro_export]
218macro_rules! session_id {
219 ($s:literal) => {{
220 const SESSION_ID: &$crate::SessionId = match $crate::SessionId::_priv_const_new($s) {
221 Ok(id) => id,
222 Err(e) => panic!("{}", e),
223 };
224
225 SESSION_ID
226 }};
227}
228
229#[macro_export]
231macro_rules! owned_session_id {
232 ($s:literal) => {
233 $crate::session_id!($s).to_owned()
234 };
235}
236
237#[macro_export]
239macro_rules! mxc_uri {
240 ($s:literal) => {
241 $crate::__private_macros::mxc_uri!($crate, $s)
242 };
243}
244
245#[macro_export]
247macro_rules! owned_mxc_uri {
248 ($s:literal) => {
249 $crate::mxc_uri!($s).to_owned()
250 };
251}
252
253#[macro_export]
255macro_rules! user_id {
256 ($s:literal) => {
257 $crate::__private_macros::user_id!($crate, $s)
258 };
259}
260
261#[macro_export]
263macro_rules! owned_user_id {
264 ($s:literal) => {
265 $crate::user_id!($s).to_owned()
266 };
267}
268
269#[macro_export]
271macro_rules! base64_public_key {
272 ($s:literal) => {
273 $crate::__private_macros::base64_public_key!($crate, $s)
274 };
275}
276
277#[macro_export]
279macro_rules! owned_base64_public_key {
280 ($s:literal) => {
281 $crate::base64_public_key!($s).to_owned()
282 };
283}