Remove borrowing from types in ruma_common::encryption
Until a better solution can be found for types that appear both in request & response types and would otherwise require incoming types to appear as fields of outgoing types.
This commit is contained in:
		
							parent
							
								
									eab5368edd
								
							
						
					
					
						commit
						4a9b1aeb3c
					
				| @ -3,7 +3,7 @@ | |||||||
| use std::{collections::BTreeMap, time::Duration}; | use std::{collections::BTreeMap, time::Duration}; | ||||||
| 
 | 
 | ||||||
| use ruma_api::ruma_api; | use ruma_api::ruma_api; | ||||||
| use ruma_common::encryption::IncomingDeviceKeys; | use ruma_common::encryption::DeviceKeys; | ||||||
| use ruma_identifiers::{DeviceIdBox, UserId}; | use ruma_identifiers::{DeviceIdBox, UserId}; | ||||||
| use serde_json::Value as JsonValue; | use serde_json::Value as JsonValue; | ||||||
| 
 | 
 | ||||||
| @ -54,7 +54,7 @@ ruma_api! { | |||||||
| 
 | 
 | ||||||
|         /// Information on the queried devices.
 |         /// Information on the queried devices.
 | ||||||
|         #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] |         #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] | ||||||
|         pub device_keys: BTreeMap<UserId, BTreeMap<DeviceIdBox, IncomingDeviceKeys>>, |         pub device_keys: BTreeMap<UserId, BTreeMap<DeviceIdBox, DeviceKeys>>, | ||||||
| 
 | 
 | ||||||
|         /// Information on the master cross-signing keys of the queried users.
 |         /// Information on the master cross-signing keys of the queried users.
 | ||||||
|         #[cfg(feature = "unstable-pre-spec")] |         #[cfg(feature = "unstable-pre-spec")] | ||||||
|  | |||||||
| @ -4,7 +4,7 @@ use std::collections::BTreeMap; | |||||||
| 
 | 
 | ||||||
| use js_int::UInt; | use js_int::UInt; | ||||||
| use ruma_api::ruma_api; | use ruma_api::ruma_api; | ||||||
| use ruma_common::encryption::{DeviceKeys, IncomingDeviceKeys}; | use ruma_common::encryption::DeviceKeys; | ||||||
| use ruma_identifiers::{DeviceKeyAlgorithm, DeviceKeyId}; | use ruma_identifiers::{DeviceKeyAlgorithm, DeviceKeyId}; | ||||||
| 
 | 
 | ||||||
| use super::OneTimeKey; | use super::OneTimeKey; | ||||||
| @ -23,7 +23,7 @@ ruma_api! { | |||||||
|     request: { |     request: { | ||||||
|         /// Identity keys for the device. May be absent if no new identity keys are required.
 |         /// Identity keys for the device. May be absent if no new identity keys are required.
 | ||||||
|         #[serde(skip_serializing_if = "Option::is_none")] |         #[serde(skip_serializing_if = "Option::is_none")] | ||||||
|         pub device_keys: Option<DeviceKeys<'a>>, |         pub device_keys: Option<DeviceKeys>, | ||||||
| 
 | 
 | ||||||
|         /// One-time public keys for "pre-key" messages.
 |         /// One-time public keys for "pre-key" messages.
 | ||||||
|         #[serde(skip_serializing_if = "Option::is_none")] |         #[serde(skip_serializing_if = "Option::is_none")] | ||||||
| @ -39,7 +39,7 @@ ruma_api! { | |||||||
|     error: crate::Error |     error: crate::Error | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Request<'_> { | impl Request { | ||||||
|     /// Creates an empty `Request`.
 |     /// Creates an empty `Request`.
 | ||||||
|     pub fn new() -> Self { |     pub fn new() -> Self { | ||||||
|         Default::default() |         Default::default() | ||||||
|  | |||||||
| @ -4,24 +4,21 @@ | |||||||
| 
 | 
 | ||||||
| use std::collections::BTreeMap; | use std::collections::BTreeMap; | ||||||
| 
 | 
 | ||||||
| use ruma_api::Outgoing; | use ruma_identifiers::{DeviceIdBox, DeviceKeyId, EventEncryptionAlgorithm, UserId}; | ||||||
| use ruma_identifiers::{DeviceId, DeviceKeyId, EventEncryptionAlgorithm, UserId}; | use serde::{Deserialize, Serialize}; | ||||||
| use ruma_serde::CanBeEmpty; |  | ||||||
| use serde::Serialize; |  | ||||||
| 
 | 
 | ||||||
| /// Identity keys for a device.
 | /// Identity keys for a device.
 | ||||||
| #[derive(Clone, Debug, Outgoing, Serialize)] | #[derive(Clone, Debug, Deserialize, Serialize)] | ||||||
| #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||||
| #[incoming_derive(Clone, Serialize)] | pub struct DeviceKeys { | ||||||
| pub struct DeviceKeys<'a> { |  | ||||||
|     /// The ID of the user the device belongs to. Must match the user ID used when logging in.
 |     /// The ID of the user the device belongs to. Must match the user ID used when logging in.
 | ||||||
|     pub user_id: &'a UserId, |     pub user_id: UserId, | ||||||
| 
 | 
 | ||||||
|     /// The ID of the device these keys belong to. Must match the device ID used when logging in.
 |     /// The ID of the device these keys belong to. Must match the device ID used when logging in.
 | ||||||
|     pub device_id: &'a DeviceId, |     pub device_id: DeviceIdBox, | ||||||
| 
 | 
 | ||||||
|     /// The encryption algorithms supported by this device.
 |     /// The encryption algorithms supported by this device.
 | ||||||
|     pub algorithms: &'a [EventEncryptionAlgorithm], |     pub algorithms: Vec<EventEncryptionAlgorithm>, | ||||||
| 
 | 
 | ||||||
|     /// Public identity keys.
 |     /// Public identity keys.
 | ||||||
|     pub keys: BTreeMap<DeviceKeyId, String>, |     pub keys: BTreeMap<DeviceKeyId, String>, | ||||||
| @ -31,17 +28,17 @@ pub struct DeviceKeys<'a> { | |||||||
| 
 | 
 | ||||||
|     /// Additional data added to the device key information by intermediate servers, and
 |     /// Additional data added to the device key information by intermediate servers, and
 | ||||||
|     /// not covered by the signatures.
 |     /// not covered by the signatures.
 | ||||||
|     #[serde(skip_serializing_if = "ruma_serde::is_empty")] |     #[serde(skip_serializing_if = "UnsignedDeviceInfo::is_empty")] | ||||||
|     pub unsigned: UnsignedDeviceInfo<'a>, |     pub unsigned: UnsignedDeviceInfo, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl<'a> DeviceKeys<'a> { | impl DeviceKeys { | ||||||
|     /// Creates a new `DeviceKeys` from the given user id, device id, algorithms, keys and
 |     /// Creates a new `DeviceKeys` from the given user id, device id, algorithms, keys and
 | ||||||
|     /// signatures.
 |     /// signatures.
 | ||||||
|     pub fn new( |     pub fn new( | ||||||
|         user_id: &'a UserId, |         user_id: UserId, | ||||||
|         device_id: &'a DeviceId, |         device_id: DeviceIdBox, | ||||||
|         algorithms: &'a [EventEncryptionAlgorithm], |         algorithms: Vec<EventEncryptionAlgorithm>, | ||||||
|         keys: BTreeMap<DeviceKeyId, String>, |         keys: BTreeMap<DeviceKeyId, String>, | ||||||
|         signatures: BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>, |         signatures: BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>, | ||||||
|     ) -> Self { |     ) -> Self { | ||||||
| @ -50,16 +47,15 @@ impl<'a> DeviceKeys<'a> { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// Additional data added to device key information by intermediate servers.
 | /// Additional data added to device key information by intermediate servers.
 | ||||||
| #[derive(Clone, Debug, Default, Outgoing, Serialize)] | #[derive(Clone, Debug, Default, Deserialize, Serialize)] | ||||||
| #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] | ||||||
| #[incoming_derive(Clone, Serialize)] | pub struct UnsignedDeviceInfo { | ||||||
| pub struct UnsignedDeviceInfo<'a> { |  | ||||||
|     /// The display name which the user set on the device.
 |     /// The display name which the user set on the device.
 | ||||||
|     #[serde(skip_serializing_if = "Option::is_none")] |     #[serde(skip_serializing_if = "Option::is_none")] | ||||||
|     pub device_display_name: Option<&'a str>, |     pub device_display_name: Option<String>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl UnsignedDeviceInfo<'_> { | impl UnsignedDeviceInfo { | ||||||
|     /// Creates an empty `UnsignedDeviceInfo`.
 |     /// Creates an empty `UnsignedDeviceInfo`.
 | ||||||
|     pub fn new() -> Self { |     pub fn new() -> Self { | ||||||
|         Default::default() |         Default::default() | ||||||
| @ -70,22 +66,3 @@ impl UnsignedDeviceInfo<'_> { | |||||||
|         self.device_display_name.is_none() |         self.device_display_name.is_none() | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 |  | ||||||
| impl IncomingUnsignedDeviceInfo { |  | ||||||
|     /// Checks whether all fields are empty / `None`.
 |  | ||||||
|     pub fn is_empty(&self) -> bool { |  | ||||||
|         self.device_display_name.is_none() |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| impl CanBeEmpty for UnsignedDeviceInfo<'_> { |  | ||||||
|     fn is_empty(&self) -> bool { |  | ||||||
|         self.is_empty() |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| impl CanBeEmpty for IncomingUnsignedDeviceInfo { |  | ||||||
|     fn is_empty(&self) -> bool { |  | ||||||
|         self.is_empty() |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  | |||||||
| @ -2,7 +2,7 @@ | |||||||
| 
 | 
 | ||||||
| use js_int::UInt; | use js_int::UInt; | ||||||
| use ruma_api::ruma_api; | use ruma_api::ruma_api; | ||||||
| use ruma_common::encryption::IncomingDeviceKeys; | use ruma_common::encryption::DeviceKeys; | ||||||
| use ruma_identifiers::{DeviceIdBox, UserId}; | use ruma_identifiers::{DeviceIdBox, UserId}; | ||||||
| use serde::{Deserialize, Serialize}; | use serde::{Deserialize, Serialize}; | ||||||
| 
 | 
 | ||||||
| @ -60,7 +60,7 @@ pub struct UserDevice { | |||||||
|     pub device_id: DeviceIdBox, |     pub device_id: DeviceIdBox, | ||||||
| 
 | 
 | ||||||
|     /// Identity keys for the device.
 |     /// Identity keys for the device.
 | ||||||
|     pub keys: IncomingDeviceKeys, |     pub keys: DeviceKeys, | ||||||
| 
 | 
 | ||||||
|     /// Optional display name for the device
 |     /// Optional display name for the device
 | ||||||
|     #[serde(skip_serializing_if = "Option::is_none")] |     #[serde(skip_serializing_if = "Option::is_none")] | ||||||
| @ -69,7 +69,7 @@ pub struct UserDevice { | |||||||
| 
 | 
 | ||||||
| impl UserDevice { | impl UserDevice { | ||||||
|     /// Creates a new `UserDevice` with the given device id and keys.
 |     /// Creates a new `UserDevice` with the given device id and keys.
 | ||||||
|     pub fn new(device_id: DeviceIdBox, keys: IncomingDeviceKeys) -> Self { |     pub fn new(device_id: DeviceIdBox, keys: DeviceKeys) -> Self { | ||||||
|         Self { device_id, keys, device_display_name: None } |         Self { device_id, keys, device_display_name: None } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -3,7 +3,7 @@ | |||||||
| use std::collections::BTreeMap; | use std::collections::BTreeMap; | ||||||
| 
 | 
 | ||||||
| use ruma_api::ruma_api; | use ruma_api::ruma_api; | ||||||
| use ruma_common::encryption::IncomingDeviceKeys; | use ruma_common::encryption::DeviceKeys; | ||||||
| use ruma_identifiers::{DeviceIdBox, UserId}; | use ruma_identifiers::{DeviceIdBox, UserId}; | ||||||
| 
 | 
 | ||||||
| ruma_api! { | ruma_api! { | ||||||
| @ -24,7 +24,7 @@ ruma_api! { | |||||||
| 
 | 
 | ||||||
|     response: { |     response: { | ||||||
|         /// Keys from the queried devices.
 |         /// Keys from the queried devices.
 | ||||||
|         pub device_keys: BTreeMap<UserId, BTreeMap<DeviceIdBox, IncomingDeviceKeys>>, |         pub device_keys: BTreeMap<UserId, BTreeMap<DeviceIdBox, DeviceKeys>>, | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -37,7 +37,7 @@ impl Request { | |||||||
| 
 | 
 | ||||||
| impl Response { | impl Response { | ||||||
|     /// Creates a new `Response` with the given device keys.
 |     /// Creates a new `Response` with the given device keys.
 | ||||||
|     pub fn new(device_keys: BTreeMap<UserId, BTreeMap<DeviceIdBox, IncomingDeviceKeys>>) -> Self { |     pub fn new(device_keys: BTreeMap<UserId, BTreeMap<DeviceIdBox, DeviceKeys>>) -> Self { | ||||||
|         Self { device_keys } |         Self { device_keys } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user