7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1 | #![allow(missing_docs)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3 | use std::collections::HashMap; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 4 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 5 | use http::Response; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 6 | use matrix_sdk_crypto::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 7 | CrossSigningBootstrapRequests, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 8 | types::requests::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 9 | AnyIncomingResponse, KeysBackupRequest, OutgoingRequest, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 10 | OutgoingVerificationRequest as SdkVerificationRequest, RoomMessageRequest, ToDeviceRequest, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 11 | UploadSigningKeysRequest as RustUploadSigningKeysRequest, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 12 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 13 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 14 | use ruma::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 15 | OwnedTransactionId, UserId, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 16 | api::client::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 17 | backup::add_backup_keys::v3::Response as KeysBackupResponse, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 18 | keys::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 19 | claim_keys::v3::{Request as KeysClaimRequest, Response as KeysClaimResponse}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 20 | get_keys::v3::Response as KeysQueryResponse, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 21 | upload_keys::v3::Response as KeysUploadResponse, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 22 | upload_signatures::v3::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 23 | Request as RustSignatureUploadRequest, Response as SignatureUploadResponse, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 24 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 25 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 26 | message::send_message_event::v3::Response as RoomMessageResponse, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 27 | sync::sync_events::DeviceLists as RumaDeviceLists, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 28 | to_device::send_event_to_device::v3::Response as ToDeviceResponse, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 29 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 30 | assign, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 31 | events::MessageLikeEventContent, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 32 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 33 | use serde_json::json; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 34 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 35 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 36 | pub struct SignatureUploadRequest { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 37 | pub body: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 38 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 39 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 40 | impl From<RustSignatureUploadRequest> for SignatureUploadRequest { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 41 | fn from(r: RustSignatureUploadRequest) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 42 | Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 43 | body: serde_json::to_string(&r.signed_keys) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 44 | .expect("Can't serialize signature upload request"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 45 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 46 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 47 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 48 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 49 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 50 | pub struct UploadSigningKeysRequest { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 51 | pub master_key: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 52 | pub self_signing_key: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 53 | pub user_signing_key: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 54 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 55 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 56 | impl From<RustUploadSigningKeysRequest> for UploadSigningKeysRequest { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 57 | fn from(r: RustUploadSigningKeysRequest) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 58 | Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 59 | master_key: serde_json::to_string( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 60 | &r.master_key.expect("Request didn't contain a master key"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 61 | ) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 62 | .expect("Can't serialize cross signing master key"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 63 | self_signing_key: serde_json::to_string( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 64 | &r.self_signing_key.expect("Request didn't contain a self-signing key"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 65 | ) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 66 | .expect("Can't serialize cross signing self-signing key"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 67 | user_signing_key: serde_json::to_string( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 68 | &r.user_signing_key.expect("Request didn't contain a user-signing key"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 69 | ) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 70 | .expect("Can't serialize cross signing user-signing key"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 71 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 72 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 73 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 74 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 75 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 76 | pub struct BootstrapCrossSigningResult { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 77 | /// Optional request to upload some device keys alongside. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 78 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 79 | /// Must be sent first if present, and marked with `mark_request_as_sent`. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 80 | pub upload_keys_request: Option<Request>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 81 | /// Request to upload the signing keys. Must be sent second. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 82 | pub upload_signing_keys_request: UploadSigningKeysRequest, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 83 | /// Request to upload the keys signatures, including for the signing keys |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 84 | /// and optionally for the device keys. Must be sent last. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 85 | pub upload_signature_request: SignatureUploadRequest, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 86 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 87 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 88 | impl From<CrossSigningBootstrapRequests> for BootstrapCrossSigningResult { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 89 | fn from(requests: CrossSigningBootstrapRequests) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 90 | Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 91 | upload_signing_keys_request: requests.upload_signing_keys_req.into(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 92 | upload_keys_request: requests.upload_keys_req.map(Request::from), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 93 | upload_signature_request: requests.upload_signatures_req.into(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 94 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 95 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 96 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 97 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 98 | #[derive(uniffi::Enum)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 99 | pub enum OutgoingVerificationRequest { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 100 | ToDevice { request_id: String, event_type: String, body: String }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 101 | InRoom { request_id: String, room_id: String, event_type: String, content: String }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 102 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 103 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 104 | impl From<SdkVerificationRequest> for OutgoingVerificationRequest { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 105 | fn from(r: SdkVerificationRequest) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 106 | match r { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 107 | SdkVerificationRequest::ToDevice(r) => r.into(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 108 | SdkVerificationRequest::InRoom(r) => Self::InRoom { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 109 | request_id: r.txn_id.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 110 | room_id: r.room_id.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 111 | content: serde_json::to_string(&r.content) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 112 | .expect("Can't serialize message content"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 113 | event_type: r.content.event_type().to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 114 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 115 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 116 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 117 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 118 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 119 | impl From<ToDeviceRequest> for OutgoingVerificationRequest { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 120 | fn from(r: ToDeviceRequest) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 121 | Self::ToDevice { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 122 | request_id: r.txn_id.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 123 | event_type: r.event_type.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 124 | body: serde_json::to_string(&r.messages).expect("Can't serialize to-device body"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 125 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 126 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 127 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 128 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 129 | #[derive(Debug, uniffi::Enum)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 130 | pub enum Request { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 131 | ToDevice { request_id: String, event_type: String, body: String }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 132 | KeysUpload { request_id: String, body: String }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 133 | KeysQuery { request_id: String, users: Vec<String> }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 134 | KeysClaim { request_id: String, one_time_keys: HashMap<String, HashMap<String, String>> }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 135 | KeysBackup { request_id: String, version: String, rooms: String }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 136 | RoomMessage { request_id: String, room_id: String, event_type: String, content: String }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 137 | SignatureUpload { request_id: String, body: String }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 138 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 139 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 140 | impl From<OutgoingRequest> for Request { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 141 | fn from(r: OutgoingRequest) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 142 | use matrix_sdk_crypto::types::requests::AnyOutgoingRequest::*; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 143 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 144 | match r.request() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 145 | KeysUpload(u) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 146 | let body = json!({ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 147 | "device_keys": u.device_keys, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 148 | "one_time_keys": u.one_time_keys, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 149 | "fallback_keys": u.fallback_keys, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 150 | }); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 151 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 152 | Request::KeysUpload { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 153 | request_id: r.request_id().to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 154 | body: serde_json::to_string(&body) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 155 | .expect("Can't serialize `/keys/upload` request"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 156 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 157 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 158 | KeysQuery(k) => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 159 | let users: Vec<String> = k.device_keys.keys().map(|u| u.to_string()).collect(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 160 | Request::KeysQuery { request_id: r.request_id().to_string(), users } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 161 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 162 | ToDeviceRequest(t) => Request::from(t), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 163 | SignatureUpload(t) => Request::SignatureUpload { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 164 | request_id: r.request_id().to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 165 | body: serde_json::to_string(&t.signed_keys) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 166 | .expect("Can't serialize signature upload request"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 167 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 168 | RoomMessage(r) => Request::from(r), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 169 | KeysClaim(c) => (r.request_id().to_owned(), c.clone()).into(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 170 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 171 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 172 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 173 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 174 | impl From<ToDeviceRequest> for Request { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 175 | fn from(r: ToDeviceRequest) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 176 | Request::ToDevice { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 177 | request_id: r.txn_id.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 178 | event_type: r.event_type.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 179 | body: serde_json::to_string(&r.messages).expect("Can't serialize to-device body"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 180 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 181 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 182 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 183 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 184 | impl From<(OwnedTransactionId, KeysClaimRequest)> for Request { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 185 | fn from(request_tuple: (OwnedTransactionId, KeysClaimRequest)) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 186 | let (request_id, request) = request_tuple; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 187 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 188 | Request::KeysClaim { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 189 | request_id: request_id.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 190 | one_time_keys: request |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 191 | .one_time_keys |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 192 | .into_iter() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 193 | .map(|(u, d)| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 194 | ( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 195 | u.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 196 | d.into_iter().map(|(k, v)| (k.to_string(), v.to_string())).collect(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 197 | ) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 198 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 199 | .collect(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 200 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 201 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 202 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 203 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 204 | impl From<(OwnedTransactionId, KeysBackupRequest)> for Request { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 205 | fn from(request_tuple: (OwnedTransactionId, KeysBackupRequest)) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 206 | let (request_id, request) = request_tuple; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 207 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 208 | Request::KeysBackup { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 209 | request_id: request_id.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 210 | version: request.version.to_owned(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 211 | rooms: serde_json::to_string(&request.rooms) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 212 | .expect("Can't serialize keys backup request"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 213 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 214 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 215 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 216 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 217 | impl From<&ToDeviceRequest> for Request { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 218 | fn from(r: &ToDeviceRequest) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 219 | Request::ToDevice { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 220 | request_id: r.txn_id.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 221 | event_type: r.event_type.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 222 | body: serde_json::to_string(&r.messages).expect("Can't serialize to-device body"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 223 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 224 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 225 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 226 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 227 | impl From<&Box<RoomMessageRequest>> for Request { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 228 | fn from(r: &Box<RoomMessageRequest>) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 229 | Self::RoomMessage { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 230 | request_id: r.txn_id.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 231 | room_id: r.room_id.to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 232 | event_type: r.content.event_type().to_string(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 233 | content: serde_json::to_string(&r.content).expect("Can't serialize message content"), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 234 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 235 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 236 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 237 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 238 | pub(crate) fn response_from_string(body: &str) -> Response<Vec<u8>> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 239 | Response::builder() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 240 | .status(200) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 241 | .body(body.as_bytes().to_vec()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 242 | .expect("Can't create HTTP response") |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 243 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 244 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 245 | #[derive(uniffi::Enum)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 246 | pub enum RequestType { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 247 | KeysQuery, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 248 | KeysClaim, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 249 | KeysUpload, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 250 | ToDevice, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 251 | SignatureUpload, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 252 | KeysBackup, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 253 | RoomMessage, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 254 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 255 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 256 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 257 | pub struct DeviceLists { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 258 | pub changed: Vec<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 259 | pub left: Vec<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 260 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 261 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 262 | impl From<DeviceLists> for RumaDeviceLists { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 263 | fn from(d: DeviceLists) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 264 | assign!(RumaDeviceLists::new(), { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 265 | changed: d |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 266 | .changed |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 267 | .into_iter() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 268 | .filter_map(|u| UserId::parse(u).ok()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 269 | .collect(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 270 | left: d |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 271 | .left |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 272 | .into_iter() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 273 | .filter_map(|u| UserId::parse(u).ok()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 274 | .collect(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 275 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 276 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 277 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 278 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 279 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 280 | pub struct KeysImportResult { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 281 | /// The number of room keys that were imported. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 282 | pub imported: i64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 283 | /// The total number of room keys that were found in the export. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 284 | pub total: i64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 285 | /// The map of keys that were imported. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 286 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 287 | /// It's a map from room id to a map of the sender key to a list of session |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 288 | /// ids. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 289 | pub keys: HashMap<String, HashMap<String, Vec<String>>>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 290 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 291 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 292 | pub(crate) enum OwnedResponse { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 293 | KeysClaim(KeysClaimResponse), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 294 | KeysUpload(KeysUploadResponse), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 295 | KeysQuery(KeysQueryResponse), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 296 | ToDevice(ToDeviceResponse), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 297 | SignatureUpload(SignatureUploadResponse), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 298 | KeysBackup(KeysBackupResponse), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 299 | RoomMessage(RoomMessageResponse), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 300 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 301 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 302 | impl From<KeysClaimResponse> for OwnedResponse { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 303 | fn from(response: KeysClaimResponse) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 304 | OwnedResponse::KeysClaim(response) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 305 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 306 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 307 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 308 | impl From<KeysQueryResponse> for OwnedResponse { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 309 | fn from(response: KeysQueryResponse) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 310 | OwnedResponse::KeysQuery(response) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 311 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 312 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 313 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 314 | impl From<KeysUploadResponse> for OwnedResponse { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 315 | fn from(response: KeysUploadResponse) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 316 | OwnedResponse::KeysUpload(response) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 317 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 318 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 319 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 320 | impl From<ToDeviceResponse> for OwnedResponse { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 321 | fn from(response: ToDeviceResponse) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 322 | OwnedResponse::ToDevice(response) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 323 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 324 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 325 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 326 | impl From<SignatureUploadResponse> for OwnedResponse { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 327 | fn from(response: SignatureUploadResponse) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 328 | Self::SignatureUpload(response) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 329 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 330 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 331 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 332 | impl From<KeysBackupResponse> for OwnedResponse { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 333 | fn from(r: KeysBackupResponse) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 334 | Self::KeysBackup(r) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 335 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 336 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 337 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 338 | impl From<RoomMessageResponse> for OwnedResponse { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 339 | fn from(response: RoomMessageResponse) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 340 | OwnedResponse::RoomMessage(response) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 341 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 342 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 343 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 344 | impl<'a> From<&'a OwnedResponse> for AnyIncomingResponse<'a> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 345 | fn from(r: &'a OwnedResponse) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 346 | match r { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 347 | OwnedResponse::KeysClaim(r) => AnyIncomingResponse::KeysClaim(r), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 348 | OwnedResponse::KeysQuery(r) => AnyIncomingResponse::KeysQuery(r), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 349 | OwnedResponse::KeysUpload(r) => AnyIncomingResponse::KeysUpload(r), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 350 | OwnedResponse::ToDevice(r) => AnyIncomingResponse::ToDevice(r), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 351 | OwnedResponse::SignatureUpload(r) => AnyIncomingResponse::SignatureUpload(r), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 352 | OwnedResponse::KeysBackup(r) => AnyIncomingResponse::KeysBackup(r), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 353 | OwnedResponse::RoomMessage(r) => AnyIncomingResponse::RoomMessage(r), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 354 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 355 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 356 | } |