Skip to content

Commit 2d8dcbe

Browse files
committed
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]: matrix-org/matrix-spec-proposals#2732
1 parent 70b3d31 commit 2d8dcbe

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

crates/ruma-client-api/src/r0/keys/upload_keys.rs

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ ruma_api! {
2929
/// One-time public keys for "pre-key" messages.
3030
#[serde(skip_serializing_if = "Option::is_none")]
3131
pub one_time_keys: Option<BTreeMap<Box<DeviceKeyId>, Raw<OneTimeKey>>>,
32+
33+
/// Fallback public keys for "pre-key" messages.
34+
#[cfg(feature = "unstable-pre-spec")]
35+
#[serde(skip_serializing_if = "Option::is_none", rename = "org.matrix.msc2732.fallback_keys")]
36+
pub fallback_keys: Option<BTreeMap<Box<DeviceKeyId>, Raw<OneTimeKey>>>,
3237
}
3338

3439
response: {

crates/ruma-client-api/src/r0/sync/sync_events.rs

+11
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ ruma_api! {
9393
/// currently held on the server for a device.
9494
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
9595
pub device_one_time_keys_count: BTreeMap<DeviceKeyAlgorithm, UInt>,
96+
97+
/// For each key algorithm, the number of unclaimed one-time keys
98+
/// currently held on the server for a device.
99+
///
100+
/// The presence of this field indicates that the server supports
101+
/// fallback keys.
102+
#[cfg(feature = "unstable-pre-spec")]
103+
#[serde(rename = "org.matrix.msc2732.device_unused_fallback_key_types")]
104+
pub device_unused_fallback_key_types: Option<Vec<DeviceKeyAlgorithm>>,
96105
}
97106

98107
error: crate::Error
@@ -116,6 +125,8 @@ impl Response {
116125
to_device: Default::default(),
117126
device_lists: Default::default(),
118127
device_one_time_keys_count: BTreeMap::new(),
128+
#[cfg(feature = "unstable-pre-spec")]
129+
device_unused_fallback_key_types: None,
119130
}
120131
}
121132
}

crates/ruma-common/src/encryption.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,28 @@ pub struct SignedKey {
8383

8484
/// Signatures for the key object.
8585
pub signatures: SignedKeySignatures,
86+
87+
/// Is this key considered to be a fallback key, defaults to false.
88+
#[cfg(feature = "unstable-pre-spec")]
89+
#[serde(default, skip_serializing_if = "ruma_serde::is_default")]
90+
pub fallback: bool,
8691
}
8792

8893
impl SignedKey {
8994
/// Creates a new `SignedKey` with the given key and signatures.
9095
pub fn new(key: String, signatures: SignedKeySignatures) -> Self {
91-
Self { key, signatures }
96+
Self {
97+
key,
98+
signatures,
99+
#[cfg(feature = "unstable-pre-spec")]
100+
fallback: false,
101+
}
102+
}
103+
104+
/// Creates a new fallback `SignedKey` with the given key and signatures.
105+
#[cfg(feature = "unstable-pre-spec")]
106+
pub fn new_fallback(key: String, signatures: SignedKeySignatures) -> Self {
107+
Self { key, signatures, fallback: true }
92108
}
93109
}
94110

0 commit comments

Comments
 (0)