client-api: Add support for fallback keys
This implements support for MSC2732[1], fallback keys. Only support to upload and get notifications about fallback keys via `/sync` is implemented. [1]: https://github.com/matrix-org/matrix-doc/pull/2732
This commit is contained in:
		
							parent
							
								
									af0a8f009c
								
							
						
					
					
						commit
						caa3c05db3
					
				| @ -29,6 +29,11 @@ ruma_api! { | |||||||
|         /// 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")] | ||||||
|         pub one_time_keys: Option<BTreeMap<Box<DeviceKeyId>, Raw<OneTimeKey>>>, |         pub one_time_keys: Option<BTreeMap<Box<DeviceKeyId>, Raw<OneTimeKey>>>, | ||||||
|  | 
 | ||||||
|  |         /// Fallback public keys for "pre-key" messages.
 | ||||||
|  |         #[cfg(feature = "unstable-pre-spec")] | ||||||
|  |         #[serde(skip_serializing_if = "Option::is_none", rename = "org.matrix.msc2732.fallback_keys")] | ||||||
|  |         pub fallback_keys: Option<BTreeMap<Box<DeviceKeyId>, Raw<OneTimeKey>>>, | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     response: { |     response: { | ||||||
|  | |||||||
| @ -93,6 +93,15 @@ ruma_api! { | |||||||
|         /// currently held on the server for a device.
 |         /// currently held on the server for a device.
 | ||||||
|         #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] |         #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] | ||||||
|         pub device_one_time_keys_count: BTreeMap<DeviceKeyAlgorithm, UInt>, |         pub device_one_time_keys_count: BTreeMap<DeviceKeyAlgorithm, UInt>, | ||||||
|  | 
 | ||||||
|  |         /// For each key algorithm, the number of unclaimed one-time keys
 | ||||||
|  |         /// currently held on the server for a device.
 | ||||||
|  |         ///
 | ||||||
|  |         /// The presence of this field indicates that the server supports
 | ||||||
|  |         /// fallback keys.
 | ||||||
|  |         #[cfg(feature = "unstable-pre-spec")] | ||||||
|  |         #[serde(rename = "org.matrix.msc2732.device_unused_fallback_key_types")] | ||||||
|  |         pub device_unused_fallback_key_types: Option<Vec<DeviceKeyAlgorithm>>, | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     error: crate::Error |     error: crate::Error | ||||||
| @ -116,6 +125,8 @@ impl Response { | |||||||
|             to_device: Default::default(), |             to_device: Default::default(), | ||||||
|             device_lists: Default::default(), |             device_lists: Default::default(), | ||||||
|             device_one_time_keys_count: BTreeMap::new(), |             device_one_time_keys_count: BTreeMap::new(), | ||||||
|  |             #[cfg(feature = "unstable-pre-spec")] | ||||||
|  |             device_unused_fallback_key_types: None, | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -83,12 +83,28 @@ pub struct SignedKey { | |||||||
| 
 | 
 | ||||||
|     /// Signatures for the key object.
 |     /// Signatures for the key object.
 | ||||||
|     pub signatures: SignedKeySignatures, |     pub signatures: SignedKeySignatures, | ||||||
|  | 
 | ||||||
|  |     /// Is this key considered to be a fallback key, defaults to false.
 | ||||||
|  |     #[cfg(feature = "unstable-pre-spec")] | ||||||
|  |     #[serde(default, skip_serializing_if = "ruma_serde::is_default")] | ||||||
|  |     pub fallback: bool, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl SignedKey { | impl SignedKey { | ||||||
|     /// Creates a new `SignedKey` with the given key and signatures.
 |     /// Creates a new `SignedKey` with the given key and signatures.
 | ||||||
|     pub fn new(key: String, signatures: SignedKeySignatures) -> Self { |     pub fn new(key: String, signatures: SignedKeySignatures) -> Self { | ||||||
|         Self { key, signatures } |         Self { | ||||||
|  |             key, | ||||||
|  |             signatures, | ||||||
|  |             #[cfg(feature = "unstable-pre-spec")] | ||||||
|  |             fallback: false, | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /// Creates a new fallback `SignedKey` with the given key and signatures.
 | ||||||
|  |     #[cfg(feature = "unstable-pre-spec")] | ||||||
|  |     pub fn new_fallback(key: String, signatures: SignedKeySignatures) -> Self { | ||||||
|  |         Self { key, signatures, fallback: true } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user