7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1 | //! Uniffi based bindings for the `matrix-sdk-crypto` crate. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2 | //! |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3 | //! This crate can be used to introduce E2EE support into an existing Matrix |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 4 | //! client or client library in any of the language targets Uniffi supports. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 5 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 6 | #![warn(missing_docs)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 7 | #![allow(unused_qualifications)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 8 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 9 | mod backup_recovery_key; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 10 | mod dehydrated_devices; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 11 | mod device; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 12 | mod error; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 13 | mod logger; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 14 | mod machine; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 15 | mod responses; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 16 | mod users; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 17 | mod verification; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 18 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 19 | use std::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 20 | collections::{BTreeMap, HashMap}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 21 | sync::Arc, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 22 | time::Duration, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 23 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 24 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 25 | use anyhow::Context as _; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 26 | pub use backup_recovery_key::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 27 | BackupRecoveryKey, DecodeError, MegolmV1BackupKey, PassphraseInfo, PkDecryptionError, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 28 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 29 | pub use device::Device; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 30 | pub use error::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 31 | CryptoStoreError, DecryptionError, KeyImportError, SecretImportError, SignatureError, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 32 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 33 | use js_int::UInt; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 34 | pub use logger::{Logger, set_logger}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 35 | pub use machine::{KeyRequestPair, OlmMachine, SignatureVerification}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 36 | use matrix_sdk_common::deserialized_responses::{ShieldState as RustShieldState, ShieldStateCode}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 37 | use matrix_sdk_crypto::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 38 | CollectStrategy, EncryptionSettings as RustEncryptionSettings, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 39 | olm::{IdentityKeys, InboundGroupSession, SenderData, Session}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 40 | store::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 41 | CryptoStore, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 42 | types::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 43 | Changes, DehydratedDeviceKey as InnerDehydratedDeviceKey, PendingChanges, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 44 | RoomSettings as RustRoomSettings, |
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 | types::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 48 | DeviceKey, DeviceKeys, EventEncryptionAlgorithm as RustEventEncryptionAlgorithm, SigningKey, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 49 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 50 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 51 | use matrix_sdk_sqlite::SqliteCryptoStore; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 52 | pub use responses::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 53 | BootstrapCrossSigningResult, DeviceLists, KeysImportResult, OutgoingVerificationRequest, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 54 | Request, RequestType, SignatureUploadRequest, UploadSigningKeysRequest, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 55 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 56 | use ruma::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 57 | DeviceKeyAlgorithm, DeviceKeyId, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedUserId, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 58 | RoomId, SecondsSinceUnixEpoch, UserId, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 59 | events::room::history_visibility::HistoryVisibility as RustHistoryVisibility, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 60 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 61 | use serde::{Deserialize, Serialize}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 62 | use tokio::runtime::Runtime; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 63 | pub use users::UserIdentity; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 64 | pub use verification::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 65 | CancelInfo, ConfirmVerificationResult, QrCode, QrCodeListener, QrCodeState, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 66 | RequestVerificationResult, Sas, SasListener, SasState, ScanResult, StartSasResult, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 67 | Verification, VerificationRequest, VerificationRequestListener, VerificationRequestState, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 68 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 69 | use vodozemac::{Curve25519PublicKey, Ed25519PublicKey}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 70 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 71 | use crate::dehydrated_devices::DehydrationError; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 72 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 73 | /// Struct collecting data that is important to migrate to the rust-sdk |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 74 | #[derive(Deserialize, Serialize, uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 75 | pub struct MigrationData { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 76 | /// The pickled version of the Olm Account |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 77 | account: PickledAccount, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 78 | /// The list of pickleds Olm Sessions. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 79 | sessions: Vec<PickledSession>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 80 | /// The list of Megolm inbound group sessions. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 81 | inbound_group_sessions: Vec<PickledInboundGroupSession>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 82 | /// The Olm pickle key that was used to pickle all the Olm objects. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 83 | pickle_key: Vec<u8>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 84 | /// The backup version that is currently active. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 85 | backup_version: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 86 | // The backup recovery key, as a base58 encoded string. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 87 | backup_recovery_key: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 88 | /// The private cross signing keys. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 89 | cross_signing: CrossSigningKeyExport, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 90 | /// The list of users that the Rust SDK should track. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 91 | tracked_users: Vec<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 92 | /// Map of room settings |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 93 | room_settings: HashMap<String, RoomSettings>, |
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 | /// Struct collecting data that is important to migrate sessions to the rust-sdk |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 97 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 98 | pub struct SessionMigrationData { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 99 | /// The user id that the data belongs to. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 100 | user_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 101 | /// The device id that the data belongs to. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 102 | device_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 103 | /// The Curve25519 public key of the Account that owns this data. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 104 | curve25519_key: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 105 | /// The Ed25519 public key of the Account that owns this data. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 106 | ed25519_key: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 107 | /// The list of pickleds Olm Sessions. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 108 | sessions: Vec<PickledSession>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 109 | /// The list of pickled Megolm inbound group sessions. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 110 | inbound_group_sessions: Vec<PickledInboundGroupSession>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 111 | /// The Olm pickle key that was used to pickle all the Olm objects. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 112 | pickle_key: Vec<u8>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 113 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 114 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 115 | /// A pickled version of an `Account`. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 116 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 117 | /// Holds all the information that needs to be stored in a database to restore |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 118 | /// an account. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 119 | #[derive(Debug, Deserialize, Serialize, uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 120 | pub struct PickledAccount { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 121 | /// The user id of the account owner. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 122 | pub user_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 123 | /// The device ID of the account owner. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 124 | pub device_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 125 | /// The pickled version of the Olm account. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 126 | pub pickle: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 127 | /// Was the account shared. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 128 | pub shared: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 129 | /// The number of uploaded one-time keys we have on the server. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 130 | pub uploaded_signed_key_count: i64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 131 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 132 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 133 | /// A pickled version of a `Session`. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 134 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 135 | /// Holds all the information that needs to be stored in a database to restore |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 136 | /// a Session. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 137 | #[derive(Debug, Deserialize, Serialize, uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 138 | pub struct PickledSession { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 139 | /// The pickle string holding the Olm Session. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 140 | pub pickle: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 141 | /// The curve25519 key of the other user that we share this session with. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 142 | pub sender_key: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 143 | /// Was the session created using a fallback key. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 144 | pub created_using_fallback_key: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 145 | /// Unix timestamp (in seconds) when the session was created. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 146 | pub creation_time: u64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 147 | /// Unix timestamp (in seconds) when the session was last used. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 148 | pub last_use_time: u64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 149 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 150 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 151 | /// A pickled version of an `InboundGroupSession`. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 152 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 153 | /// Holds all the information that needs to be stored in a database to restore |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 154 | /// an InboundGroupSession. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 155 | #[derive(Debug, Deserialize, Serialize, uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 156 | pub struct PickledInboundGroupSession { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 157 | /// The pickle string holding the InboundGroupSession. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 158 | pub pickle: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 159 | /// The public curve25519 key of the account that sent us the session |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 160 | pub sender_key: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 161 | /// The public ed25519 key of the account that sent us the session. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 162 | pub signing_key: HashMap<String, String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 163 | /// The id of the room that the session is used in. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 164 | pub room_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 165 | /// The list of claimed ed25519 that forwarded us this key. Will be empty if |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 166 | /// we directly received this session. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 167 | pub forwarding_chains: Vec<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 168 | /// Flag remembering if the session was directly sent to us by the sender |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 169 | /// or if it was imported. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 170 | pub imported: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 171 | /// Flag remembering if the session has been backed up. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 172 | pub backed_up: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 173 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 174 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 175 | /// Error type for the migration process. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 176 | #[derive(Debug, thiserror::Error, uniffi::Error)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 177 | pub enum MigrationError { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 178 | /// Generic catch all error variant. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 179 | #[error("error migrating database: {error_message}")] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 180 | Generic { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 181 | /// The error message |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 182 | error_message: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 183 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 184 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 185 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 186 | impl From<anyhow::Error> for MigrationError { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 187 | fn from(e: anyhow::Error) -> MigrationError { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 188 | MigrationError::Generic { error_message: e.to_string() } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 189 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 190 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 191 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 192 | /// Migrate a libolm based setup to a vodozemac based setup stored in a SQLite |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 193 | /// store. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 194 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 195 | /// # Arguments |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 196 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 197 | /// * `data` - The data that should be migrated over to the SQLite store. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 198 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 199 | /// * `path` - The path where the SQLite store should be created. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 200 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 201 | /// * `passphrase` - The passphrase that should be used to encrypt the data at |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 202 | /// rest in the SQLite store. **Warning**, if no passphrase is given, the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 203 | /// store and all its data will remain unencrypted. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 204 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 205 | /// * `progress_listener` - A callback that can be used to introspect the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 206 | /// progress of the migration. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 207 | #[matrix_sdk_ffi_macros::export] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 208 | pub fn migrate( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 209 | data: MigrationData, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 210 | path: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 211 | passphrase: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 212 | progress_listener: Box<dyn ProgressListener>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 213 | ) -> Result<(), MigrationError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 214 | let runtime = Runtime::new().context("initializing tokio runtime")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 215 | runtime.block_on(async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 216 | migrate_data(data, &path, passphrase, progress_listener).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 217 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 218 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 219 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 220 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 221 | async fn migrate_data( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 222 | mut data: MigrationData, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 223 | path: &str, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 224 | passphrase: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 225 | progress_listener: Box<dyn ProgressListener>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 226 | ) -> anyhow::Result<()> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 227 | use matrix_sdk_crypto::{olm::PrivateCrossSigningIdentity, store::types::BackupDecryptionKey}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 228 | use vodozemac::olm::Account; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 229 | use zeroize::Zeroize; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 230 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 231 | // The total steps here include all the sessions/inbound group sessions and |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 232 | // additionally some static number of steps: |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 233 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 234 | // 1. opening the store |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 235 | // 2. the Account |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 236 | // 3. the cross signing keys |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 237 | // 4. the tracked users |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 238 | // 5. the final save operation |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 239 | let total_steps = 5 + data.sessions.len() + data.inbound_group_sessions.len(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 240 | let mut processed_steps = 0; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 241 | let listener = |progress: usize, total: usize| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 242 | progress_listener.on_progress(progress as i32, total as i32) |
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 | let store = SqliteCryptoStore::open(path, passphrase.as_deref()).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 246 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 247 | processed_steps += 1; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 248 | listener(processed_steps, total_steps); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 249 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 250 | let user_id = parse_user_id(&data.account.user_id)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 251 | let device_id: OwnedDeviceId = data.account.device_id.into(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 252 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 253 | let account = Account::from_libolm_pickle(&data.account.pickle, &data.pickle_key)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 254 | let pickle = account.pickle(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 255 | let identity_keys = Arc::new(account.identity_keys()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 256 | let pickled_account = matrix_sdk_crypto::olm::PickledAccount { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 257 | user_id: parse_user_id(&data.account.user_id)?, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 258 | device_id: device_id.clone(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 259 | pickle, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 260 | dehydrated: false, // dehydrated devices are never involved in migration |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 261 | shared: data.account.shared, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 262 | uploaded_signed_key_count: data.account.uploaded_signed_key_count as u64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 263 | creation_local_time: MilliSecondsSinceUnixEpoch::now(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 264 | fallback_key_creation_timestamp: Some(MilliSecondsSinceUnixEpoch::now()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 265 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 266 | let account = matrix_sdk_crypto::olm::Account::from_pickle(pickled_account)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 267 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 268 | processed_steps += 1; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 269 | listener(processed_steps, total_steps); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 270 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 271 | let (sessions, inbound_group_sessions) = collect_sessions( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 272 | processed_steps, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 273 | total_steps, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 274 | &listener, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 275 | &data.pickle_key, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 276 | user_id.clone(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 277 | device_id, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 278 | identity_keys, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 279 | data.sessions, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 280 | data.inbound_group_sessions, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 281 | )?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 282 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 283 | let backup_decryption_key = data |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 284 | .backup_recovery_key |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 285 | .map(|k| BackupDecryptionKey::from_base58(k.as_str())) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 286 | .transpose()?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 287 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 288 | let cross_signing = PrivateCrossSigningIdentity::empty((*user_id).into()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 289 | cross_signing |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 290 | .import_secrets_unchecked( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 291 | data.cross_signing.master_key.as_deref(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 292 | data.cross_signing.self_signing_key.as_deref(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 293 | data.cross_signing.user_signing_key.as_deref(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 294 | ) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 295 | .await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 296 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 297 | data.cross_signing.master_key.zeroize(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 298 | data.cross_signing.self_signing_key.zeroize(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 299 | data.cross_signing.user_signing_key.zeroize(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 300 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 301 | processed_steps += 1; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 302 | listener(processed_steps, total_steps); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 303 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 304 | let tracked_users: Vec<_> = data |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 305 | .tracked_users |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 306 | .into_iter() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 307 | .filter_map(|s| parse_user_id(&s).ok().map(|u| (u, true))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 308 | .collect(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 309 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 310 | let tracked_users: Vec<_> = tracked_users.iter().map(|(u, d)| (&**u, *d)).collect(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 311 | store.save_tracked_users(tracked_users.as_slice()).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 312 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 313 | processed_steps += 1; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 314 | listener(processed_steps, total_steps); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 315 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 316 | let mut room_settings = HashMap::new(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 317 | for (room_id, settings) in data.room_settings { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 318 | let room_id = RoomId::parse(room_id)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 319 | room_settings.insert(room_id, settings.into()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 320 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 321 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 322 | store.save_pending_changes(PendingChanges { account: Some(account) }).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 323 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 324 | let changes = Changes { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 325 | private_identity: Some(cross_signing), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 326 | sessions, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 327 | inbound_group_sessions, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 328 | backup_decryption_key, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 329 | backup_version: data.backup_version, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 330 | room_settings, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 331 | ..Default::default() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 332 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 333 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 334 | save_changes(processed_steps, total_steps, &listener, changes, &store).await |
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 | async fn save_changes( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 338 | mut processed_steps: usize, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 339 | total_steps: usize, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 340 | listener: &dyn Fn(usize, usize), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 341 | changes: Changes, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 342 | store: &SqliteCryptoStore, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 343 | ) -> anyhow::Result<()> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 344 | store.save_changes(changes).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 345 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 346 | processed_steps += 1; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 347 | listener(processed_steps, total_steps); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 348 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 349 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 350 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 351 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 352 | /// Migrate sessions and group sessions of a libolm based setup to a vodozemac |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 353 | /// based setup stored in a SQLite store. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 354 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 355 | /// This method allows you to migrate a subset of the data, it should only be |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 356 | /// used after the [`migrate()`] method has been already used. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 357 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 358 | /// # Arguments |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 359 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 360 | /// * `data` - The data that should be migrated over to the SQLite store. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 361 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 362 | /// * `path` - The path where the SQLite store should be created. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 363 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 364 | /// * `passphrase` - The passphrase that should be used to encrypt the data at |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 365 | /// rest in the SQLite store. **Warning**, if no passphrase is given, the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 366 | /// store and all its data will remain unencrypted. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 367 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 368 | /// * `progress_listener` - A callback that can be used to introspect the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 369 | /// progress of the migration. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 370 | #[matrix_sdk_ffi_macros::export] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 371 | pub fn migrate_sessions( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 372 | data: SessionMigrationData, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 373 | path: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 374 | passphrase: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 375 | progress_listener: Box<dyn ProgressListener>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 376 | ) -> Result<(), MigrationError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 377 | let runtime = Runtime::new().context("initializing tokio runtime")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 378 | runtime.block_on(migrate_session_data(data, &path, passphrase, progress_listener))?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 379 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 380 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 381 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 382 | async fn migrate_session_data( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 383 | data: SessionMigrationData, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 384 | path: &str, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 385 | passphrase: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 386 | progress_listener: Box<dyn ProgressListener>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 387 | ) -> anyhow::Result<()> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 388 | let store = SqliteCryptoStore::open(path, passphrase.as_deref()).await?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 389 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 390 | let listener = |progress: usize, total: usize| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 391 | progress_listener.on_progress(progress as i32, total as i32) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 392 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 393 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 394 | let total_steps = 1 + data.sessions.len() + data.inbound_group_sessions.len(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 395 | let processed_steps = 0; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 396 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 397 | let user_id = UserId::parse(data.user_id)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 398 | let device_id: OwnedDeviceId = data.device_id.into(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 399 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 400 | let identity_keys = IdentityKeys { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 401 | ed25519: Ed25519PublicKey::from_base64(&data.ed25519_key)?, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 402 | curve25519: Curve25519PublicKey::from_base64(&data.curve25519_key)?, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 403 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 404 | .into(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 405 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 406 | let (sessions, inbound_group_sessions) = collect_sessions( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 407 | processed_steps, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 408 | total_steps, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 409 | &listener, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 410 | &data.pickle_key, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 411 | user_id, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 412 | device_id, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 413 | identity_keys, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 414 | data.sessions, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 415 | data.inbound_group_sessions, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 416 | )?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 417 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 418 | let changes = Changes { sessions, inbound_group_sessions, ..Default::default() }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 419 | save_changes(processed_steps, total_steps, &listener, changes, &store).await |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 420 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 421 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 422 | #[allow(clippy::too_many_arguments)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 423 | fn collect_sessions( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 424 | mut processed_steps: usize, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 425 | total_steps: usize, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 426 | listener: &dyn Fn(usize, usize), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 427 | pickle_key: &[u8], |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 428 | user_id: OwnedUserId, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 429 | device_id: OwnedDeviceId, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 430 | identity_keys: Arc<IdentityKeys>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 431 | session_pickles: Vec<PickledSession>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 432 | group_session_pickles: Vec<PickledInboundGroupSession>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 433 | ) -> anyhow::Result<(Vec<Session>, Vec<InboundGroupSession>)> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 434 | let mut sessions = Vec::new(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 435 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 436 | // Create a DeviceKeys struct with enough information to get a working |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 437 | // Session, but we will won't actually use the Sessions (and we'll clear |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 438 | // the session cache after migration) so we don't need to worry about |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 439 | // signatures. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 440 | let device_keys = DeviceKeys::new( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 441 | user_id, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 442 | device_id.clone(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 443 | Default::default(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 444 | BTreeMap::from([ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 445 | ( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 446 | DeviceKeyId::from_parts(DeviceKeyAlgorithm::Ed25519, &device_id), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 447 | DeviceKey::Ed25519(identity_keys.ed25519), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 448 | ), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 449 | ( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 450 | DeviceKeyId::from_parts(DeviceKeyAlgorithm::Curve25519, &device_id), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 451 | DeviceKey::Curve25519(identity_keys.curve25519), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 452 | ), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 453 | ]), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 454 | Default::default(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 455 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 456 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 457 | for session_pickle in session_pickles { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 458 | let pickle = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 459 | vodozemac::olm::Session::from_libolm_pickle(&session_pickle.pickle, pickle_key)? |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 460 | .pickle(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 461 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 462 | let creation_time = SecondsSinceUnixEpoch( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 463 | UInt::new(session_pickle.creation_time).context("invalid creation timestamp")?, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 464 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 465 | let last_use_time = SecondsSinceUnixEpoch( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 466 | UInt::new(session_pickle.last_use_time).context("invalid last use timestamp")?, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 467 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 468 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 469 | let pickle = matrix_sdk_crypto::olm::PickledSession { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 470 | pickle, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 471 | sender_key: Curve25519PublicKey::from_base64(&session_pickle.sender_key)?, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 472 | created_using_fallback_key: session_pickle.created_using_fallback_key, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 473 | creation_time, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 474 | last_use_time, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 475 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 476 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 477 | let session = Session::from_pickle(device_keys.clone(), pickle)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 478 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 479 | sessions.push(session); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 480 | processed_steps += 1; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 481 | listener(processed_steps, total_steps); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 482 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 483 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 484 | let mut inbound_group_sessions = Vec::new(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 485 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 486 | for session in group_session_pickles { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 487 | let pickle = vodozemac::megolm::InboundGroupSession::from_libolm_pickle( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 488 | &session.pickle, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 489 | pickle_key, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 490 | )? |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 491 | .pickle(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 492 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 493 | let sender_key = Curve25519PublicKey::from_base64(&session.sender_key)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 494 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 495 | let pickle = matrix_sdk_crypto::olm::PickledInboundGroupSession { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 496 | pickle, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 497 | sender_key, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 498 | signing_key: session |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 499 | .signing_key |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 500 | .into_iter() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 501 | .map(|(k, v)| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 502 | let algorithm = DeviceKeyAlgorithm::from(k); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 503 | let key = SigningKey::from_parts(&algorithm, v)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 504 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 505 | Ok((algorithm, key)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 506 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 507 | .collect::<anyhow::Result<_>>()?, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 508 | sender_data: SenderData::legacy(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 509 | forwarder_data: None, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 510 | room_id: RoomId::parse(session.room_id)?, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 511 | imported: session.imported, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 512 | backed_up: session.backed_up, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 513 | history_visibility: None, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 514 | shared_history: false, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 515 | algorithm: RustEventEncryptionAlgorithm::MegolmV1AesSha2, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 516 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 517 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 518 | let session = matrix_sdk_crypto::olm::InboundGroupSession::from_pickle(pickle)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 519 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 520 | inbound_group_sessions.push(session); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 521 | processed_steps += 1; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 522 | listener(processed_steps, total_steps); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 523 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 524 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 525 | Ok((sessions, inbound_group_sessions)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 526 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 527 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 528 | /// Migrate room settings, including room algorithm and whether to block |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 529 | /// untrusted devices from legacy store to Sqlite store. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 530 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 531 | /// Note that this method should only be used if a client has already migrated |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 532 | /// account data via [migrate](#method.migrate) method, which did not include |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 533 | /// room settings. For a brand new migration, the [migrate](#method.migrate) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 534 | /// method will take care of room settings automatically, if provided. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 535 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 536 | /// # Arguments |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 537 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 538 | /// * `room_settings` - Map of room settings |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 539 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 540 | /// * `path` - The path where the Sqlite store should be created. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 541 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 542 | /// * `passphrase` - The passphrase that should be used to encrypt the data at |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 543 | /// rest in the Sqlite store. **Warning**, if no passphrase is given, the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 544 | /// store and all its data will remain unencrypted. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 545 | #[matrix_sdk_ffi_macros::export] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 546 | pub fn migrate_room_settings( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 547 | room_settings: HashMap<String, RoomSettings>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 548 | path: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 549 | passphrase: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 550 | ) -> Result<(), MigrationError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 551 | let runtime = Runtime::new().context("initializing tokio runtime")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 552 | runtime.block_on(async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 553 | let store = SqliteCryptoStore::open(path, passphrase.as_deref()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 554 | .await |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 555 | .context("opening sqlite crypto store")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 556 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 557 | let mut rust_settings = HashMap::new(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 558 | for (room_id, settings) in room_settings { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 559 | let room_id = RoomId::parse(room_id).context("parsing room ID")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 560 | rust_settings.insert(room_id, settings.into()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 561 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 562 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 563 | let changes = Changes { room_settings: rust_settings, ..Default::default() }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 564 | store.save_changes(changes).await.context("saving changes")?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 565 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 566 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 567 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 568 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 569 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 570 | /// Callback that will be passed over the FFI to report progress |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 571 | #[matrix_sdk_ffi_macros::export(callback_interface)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 572 | pub trait ProgressListener { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 573 | /// The callback that should be called on the Rust side |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 574 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 575 | /// # Arguments |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 576 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 577 | /// * `progress` - The current number of items that have been handled |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 578 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 579 | /// * `total` - The total number of items that will be handled |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 580 | fn on_progress(&self, progress: i32, total: i32); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 581 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 582 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 583 | impl<T: Fn(i32, i32)> ProgressListener for T { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 584 | fn on_progress(&self, progress: i32, total: i32) { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 585 | self(progress, total) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 586 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 587 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 588 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 589 | /// An encryption algorithm to be used to encrypt messages sent to a room. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 590 | #[derive(Debug, Deserialize, Serialize, PartialEq, uniffi::Enum)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 591 | pub enum EventEncryptionAlgorithm { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 592 | /// Olm version 1 using Curve25519, AES-256, and SHA-256. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 593 | OlmV1Curve25519AesSha2, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 594 | /// Megolm version 1 using AES-256 and SHA-256. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 595 | MegolmV1AesSha2, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 596 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 597 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 598 | impl From<EventEncryptionAlgorithm> for RustEventEncryptionAlgorithm { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 599 | fn from(a: EventEncryptionAlgorithm) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 600 | match a { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 601 | EventEncryptionAlgorithm::OlmV1Curve25519AesSha2 => Self::OlmV1Curve25519AesSha2, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 602 | EventEncryptionAlgorithm::MegolmV1AesSha2 => Self::MegolmV1AesSha2, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 603 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 604 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 605 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 606 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 607 | impl TryFrom<RustEventEncryptionAlgorithm> for EventEncryptionAlgorithm { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 608 | type Error = serde_json::Error; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 609 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 610 | fn try_from(value: RustEventEncryptionAlgorithm) -> Result<Self, Self::Error> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 611 | match value { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 612 | RustEventEncryptionAlgorithm::OlmV1Curve25519AesSha2 => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 613 | Ok(Self::OlmV1Curve25519AesSha2) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 614 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 615 | RustEventEncryptionAlgorithm::MegolmV1AesSha2 => Ok(Self::MegolmV1AesSha2), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 616 | _ => Err(serde::de::Error::custom(format!("Unsupported algorithm {value}"))), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 617 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 618 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 619 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 620 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 621 | /// Who can see a room's history. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 622 | #[derive(uniffi::Enum)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 623 | pub enum HistoryVisibility { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 624 | /// Previous events are accessible to newly joined members from the point |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 625 | /// they were invited onwards. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 626 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 627 | /// Events stop being accessible when the member's state changes to |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 628 | /// something other than *invite* or *join*. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 629 | Invited, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 630 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 631 | /// Previous events are accessible to newly joined members from the point |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 632 | /// they joined the room onwards. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 633 | /// Events stop being accessible when the member's state changes to |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 634 | /// something other than *join*. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 635 | Joined, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 636 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 637 | /// Previous events are always accessible to newly joined members. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 638 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 639 | /// All events in the room are accessible, even those sent when the member |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 640 | /// was not a part of the room. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 641 | Shared, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 642 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 643 | /// All events while this is the `HistoryVisibility` value may be shared by |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 644 | /// any participating homeserver with anyone, regardless of whether they |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 645 | /// have ever joined the room. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 646 | WorldReadable, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 647 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 648 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 649 | impl From<HistoryVisibility> for RustHistoryVisibility { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 650 | fn from(h: HistoryVisibility) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 651 | match h { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 652 | HistoryVisibility::Invited => Self::Invited, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 653 | HistoryVisibility::Joined => Self::Joined, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 654 | HistoryVisibility::Shared => Self::Shared, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 655 | HistoryVisibility::WorldReadable => Self::Shared, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 656 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 657 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 658 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 659 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 660 | /// Settings that should be used when a room key is shared. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 661 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 662 | /// These settings control which algorithm the room key should use, how long a |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 663 | /// room key should be used and some other important information that determines |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 664 | /// the lifetime of a room key. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 665 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 666 | pub struct EncryptionSettings { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 667 | /// The encryption algorithm that should be used in the room. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 668 | pub algorithm: EventEncryptionAlgorithm, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 669 | /// Whether state event encryption is enabled. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 670 | #[cfg(feature = "experimental-encrypted-state-events")] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 671 | pub encrypt_state_events: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 672 | /// How long can the room key be used before it should be rotated. Time in |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 673 | /// seconds. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 674 | pub rotation_period: u64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 675 | /// How many messages should be sent before the room key should be rotated. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 676 | pub rotation_period_msgs: u64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 677 | /// The current history visibility of the room. The visibility will be |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 678 | /// tracked by the room key and the key will be rotated if the visibility |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 679 | /// changes. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 680 | pub history_visibility: HistoryVisibility, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 681 | /// Should untrusted devices receive the room key, or should they be |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 682 | /// excluded from the conversation. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 683 | pub only_allow_trusted_devices: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 684 | /// Should fail to send when a verified user has unverified devices, or when |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 685 | /// a previously verified user replaces their identity. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 686 | pub error_on_verified_user_problem: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 687 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 688 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 689 | impl From<EncryptionSettings> for RustEncryptionSettings { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 690 | fn from(v: EncryptionSettings) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 691 | let sharing_strategy = if v.only_allow_trusted_devices { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 692 | CollectStrategy::OnlyTrustedDevices |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 693 | } else if v.error_on_verified_user_problem { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 694 | CollectStrategy::ErrorOnVerifiedUserProblem |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 695 | } else { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 696 | CollectStrategy::AllDevices |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 697 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 698 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 699 | RustEncryptionSettings { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 700 | algorithm: v.algorithm.into(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 701 | #[cfg(feature = "experimental-encrypted-state-events")] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 702 | encrypt_state_events: false, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 703 | rotation_period: Duration::from_secs(v.rotation_period), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 704 | rotation_period_msgs: v.rotation_period_msgs, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 705 | history_visibility: v.history_visibility.into(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 706 | sharing_strategy, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 707 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 708 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 709 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 710 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 711 | /// An event that was successfully decrypted. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 712 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 713 | pub struct DecryptedEvent { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 714 | /// The decrypted version of the event. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 715 | pub clear_event: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 716 | /// The claimed curve25519 key of the sender. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 717 | pub sender_curve25519_key: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 718 | /// The claimed ed25519 key of the sender. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 719 | pub claimed_ed25519_key: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 720 | /// The curve25519 chain of the senders that forwarded the Megolm decryption |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 721 | /// key to us. Is empty if the key came directly from the sender of the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 722 | /// event. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 723 | pub forwarding_curve25519_chain: Vec<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 724 | /// The shield state (color and message to display to user) for the event, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 725 | /// representing the event's authenticity. Computed from the properties of |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 726 | /// the sender user identity and their Olm device. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 727 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 728 | /// Note that this is computed at time of decryption, so the value reflects |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 729 | /// the computed event authenticity at that time. Authenticity-related |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 730 | /// properties can change later on, such as when a user identity is |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 731 | /// subsequently verified or a device is deleted. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 732 | pub shield_state: ShieldState, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 733 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 734 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 735 | /// Take a look at [`matrix_sdk_common::deserialized_responses::ShieldState`] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 736 | /// for more info. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 737 | #[allow(missing_docs)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 738 | #[derive(uniffi::Enum)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 739 | pub enum ShieldColor { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 740 | Red, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 741 | Grey, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 742 | None, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 743 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 744 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 745 | /// Take a look at [`matrix_sdk_common::deserialized_responses::ShieldState`] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 746 | /// for more info. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 747 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 748 | #[allow(missing_docs)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 749 | pub struct ShieldState { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 750 | color: ShieldColor, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 751 | code: Option<ShieldStateCode>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 752 | message: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 753 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 754 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 755 | impl From<RustShieldState> for ShieldState { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 756 | fn from(value: RustShieldState) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 757 | match value { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 758 | RustShieldState::Red { code, message } => Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 759 | color: ShieldColor::Red, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 760 | code: Some(code), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 761 | message: Some(message.to_owned()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 762 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 763 | RustShieldState::Grey { code, message } => Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 764 | color: ShieldColor::Grey, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 765 | code: Some(code), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 766 | message: Some(message.to_owned()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 767 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 768 | RustShieldState::None => Self { color: ShieldColor::None, code: None, message: None }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 769 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 770 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 771 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 772 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 773 | /// Struct representing the state of our private cross signing keys, it shows |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 774 | /// which private cross signing keys we have locally stored. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 775 | #[derive(Debug, Clone, uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 776 | pub struct CrossSigningStatus { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 777 | /// Do we have the master key. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 778 | pub has_master: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 779 | /// Do we have the self signing key, this one is necessary to sign our own |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 780 | /// devices. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 781 | pub has_self_signing: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 782 | /// Do we have the user signing key, this one is necessary to sign other |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 783 | /// users. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 784 | pub has_user_signing: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 785 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 786 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 787 | /// A struct containing private cross signing keys that can be backed up or |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 788 | /// uploaded to the secret store. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 789 | #[derive(Deserialize, Serialize, uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 790 | pub struct CrossSigningKeyExport { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 791 | /// The seed of the master key encoded as unpadded base64. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 792 | pub master_key: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 793 | /// The seed of the self signing key encoded as unpadded base64. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 794 | pub self_signing_key: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 795 | /// The seed of the user signing key encoded as unpadded base64. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 796 | pub user_signing_key: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 797 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 798 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 799 | /// Struct holding the number of room keys we have. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 800 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 801 | pub struct RoomKeyCounts { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 802 | /// The total number of room keys. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 803 | pub total: i64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 804 | /// The number of backed up room keys. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 805 | pub backed_up: i64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 806 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 807 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 808 | /// Backup keys and information we load from the store. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 809 | #[derive(uniffi::Object)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 810 | pub struct BackupKeys { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 811 | /// The recovery key as a base64 encoded string. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 812 | recovery_key: Arc<BackupRecoveryKey>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 813 | /// The version that is used with the recovery key. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 814 | backup_version: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 815 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 816 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 817 | #[matrix_sdk_ffi_macros::export] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 818 | impl BackupKeys { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 819 | /// Get the recovery key that we're holding on to. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 820 | pub fn recovery_key(&self) -> Arc<BackupRecoveryKey> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 821 | self.recovery_key.clone() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 822 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 823 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 824 | /// Get the backups version that we're holding on to. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 825 | pub fn backup_version(&self) -> String { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 826 | self.backup_version.to_owned() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 827 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 828 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 829 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 830 | impl TryFrom<matrix_sdk_crypto::store::types::BackupKeys> for BackupKeys { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 831 | type Error = (); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 832 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 833 | fn try_from(keys: matrix_sdk_crypto::store::types::BackupKeys) -> Result<Self, Self::Error> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 834 | Ok(Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 835 | recovery_key: BackupRecoveryKey { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 836 | inner: keys.decryption_key.ok_or(())?, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 837 | passphrase_info: None, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 838 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 839 | .into(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 840 | backup_version: keys.backup_version.ok_or(())?, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 841 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 842 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 843 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 844 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 845 | /// Dehydrated device key |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 846 | #[derive(uniffi::Record, Clone)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 847 | pub struct DehydratedDeviceKey { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 848 | pub(crate) inner: Vec<u8>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 849 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 850 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 851 | impl DehydratedDeviceKey { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 852 | /// Generates a new random pickle key. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 853 | #[allow(clippy::new_without_default)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 854 | pub fn new() -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 855 | InnerDehydratedDeviceKey::new().into() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 856 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 857 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 858 | /// Creates a new dehydration pickle key from the given slice. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 859 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 860 | /// Fail if the slice length is not 32. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 861 | pub fn from_slice(slice: &[u8]) -> Result<Self, DehydrationError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 862 | let inner = InnerDehydratedDeviceKey::from_slice(slice)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 863 | Ok(inner.into()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 864 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 865 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 866 | /// Export the [`DehydratedDeviceKey`] as a base64 encoded string. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 867 | pub fn to_base64(&self) -> String { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 868 | let inner = InnerDehydratedDeviceKey::from_slice(&self.inner).unwrap(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 869 | inner.to_base64() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 870 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 871 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 872 | impl From<InnerDehydratedDeviceKey> for DehydratedDeviceKey { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 873 | fn from(pickle_key: InnerDehydratedDeviceKey) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 874 | DehydratedDeviceKey { inner: pickle_key.into() } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 875 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 876 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 877 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 878 | impl From<matrix_sdk_crypto::store::types::RoomKeyCounts> for RoomKeyCounts { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 879 | fn from(count: matrix_sdk_crypto::store::types::RoomKeyCounts) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 880 | Self { total: count.total as i64, backed_up: count.backed_up as i64 } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 881 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 882 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 883 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 884 | impl From<matrix_sdk_crypto::CrossSigningKeyExport> for CrossSigningKeyExport { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 885 | fn from(e: matrix_sdk_crypto::CrossSigningKeyExport) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 886 | Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 887 | master_key: e.master_key.clone(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 888 | self_signing_key: e.self_signing_key.clone(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 889 | user_signing_key: e.user_signing_key.clone(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 890 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 891 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 892 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 893 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 894 | impl From<CrossSigningKeyExport> for matrix_sdk_crypto::CrossSigningKeyExport { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 895 | fn from(e: CrossSigningKeyExport) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 896 | matrix_sdk_crypto::CrossSigningKeyExport { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 897 | master_key: e.master_key, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 898 | self_signing_key: e.self_signing_key, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 899 | user_signing_key: e.user_signing_key, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 900 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 901 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 902 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 903 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 904 | impl From<matrix_sdk_crypto::CrossSigningStatus> for CrossSigningStatus { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 905 | fn from(s: matrix_sdk_crypto::CrossSigningStatus) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 906 | Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 907 | has_master: s.has_master, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 908 | has_self_signing: s.has_self_signing, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 909 | has_user_signing: s.has_user_signing, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 910 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 911 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 912 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 913 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 914 | /// Room encryption settings which are modified by state events or user options |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 915 | #[derive(Debug, PartialEq, Deserialize, Serialize, uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 916 | pub struct RoomSettings { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 917 | /// The encryption algorithm that should be used in the room. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 918 | pub algorithm: EventEncryptionAlgorithm, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 919 | /// Whether state event encryption is enabled. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 920 | #[cfg(feature = "experimental-encrypted-state-events")] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 921 | #[serde(default)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 922 | pub encrypt_state_events: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 923 | /// Should untrusted devices receive the room key, or should they be |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 924 | /// excluded from the conversation. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 925 | pub only_allow_trusted_devices: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 926 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 927 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 928 | impl TryFrom<RustRoomSettings> for RoomSettings { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 929 | type Error = serde_json::Error; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 930 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 931 | fn try_from(value: RustRoomSettings) -> Result<Self, Self::Error> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 932 | let algorithm = value.algorithm.try_into()?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 933 | Ok(Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 934 | algorithm, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 935 | #[cfg(feature = "experimental-encrypted-state-events")] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 936 | encrypt_state_events: value.encrypt_state_events, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 937 | only_allow_trusted_devices: value.only_allow_trusted_devices, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 938 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 939 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 940 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 941 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 942 | impl From<RoomSettings> for RustRoomSettings { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 943 | fn from(value: RoomSettings) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 944 | Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 945 | algorithm: value.algorithm.into(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 946 | only_allow_trusted_devices: value.only_allow_trusted_devices, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 947 | ..RustRoomSettings::default() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 948 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 949 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 950 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 951 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 952 | fn parse_user_id(user_id: &str) -> Result<OwnedUserId, CryptoStoreError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 953 | ruma::UserId::parse(user_id).map_err(|e| CryptoStoreError::InvalidUserId(user_id.to_owned(), e)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 954 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 955 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 956 | #[matrix_sdk_ffi_macros::export] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 957 | fn version_info() -> VersionInfo { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 958 | VersionInfo { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 959 | version: matrix_sdk_crypto::VERSION.to_owned(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 960 | vodozemac_version: matrix_sdk_crypto::vodozemac::VERSION.to_owned(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 961 | git_description: env!("VERGEN_GIT_DESCRIBE").to_owned(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 962 | git_sha: env!("VERGEN_GIT_SHA").to_owned(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 963 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 964 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 965 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 966 | /// Build-time information about important crates that are used. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 967 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 968 | pub struct VersionInfo { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 969 | /// The version of the matrix-sdk-crypto crate. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 970 | pub version: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 971 | /// The version of the vodozemac crate. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 972 | pub vodozemac_version: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 973 | /// The Git commit hash of the crate's source tree at build time. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 974 | pub git_sha: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 975 | /// The build-time output of the `git describe` command of the source tree |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 976 | /// of crate. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 977 | pub git_description: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 978 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 979 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 980 | #[matrix_sdk_ffi_macros::export] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 981 | fn version() -> String { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 982 | matrix_sdk_crypto::VERSION.to_owned() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 983 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 984 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 985 | #[matrix_sdk_ffi_macros::export] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 986 | fn vodozemac_version() -> String { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 987 | vodozemac::VERSION.to_owned() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 988 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 989 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 990 | /// The encryption component of PkEncryption support. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 991 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 992 | /// This struct can be created using a [`Curve25519PublicKey`] corresponding to |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 993 | /// a `PkDecryption` object, allowing messages to be encrypted for the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 994 | /// associated decryption object. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 995 | #[derive(uniffi::Object)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 996 | pub struct PkEncryption { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 997 | inner: matrix_sdk_crypto::vodozemac::pk_encryption::PkEncryption, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 998 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 999 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1000 | #[matrix_sdk_ffi_macros::export] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1001 | impl PkEncryption { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1002 | /// Create a new [`PkEncryption`] object from a `Curve25519PublicKey` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1003 | /// encoded as Base64. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1004 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1005 | /// The public key should come from an existing `PkDecryption` object. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1006 | /// Returns a `DecodeError` if the Curve25519 key could not be decoded |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1007 | /// correctly. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1008 | #[uniffi::constructor] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1009 | pub fn from_base64(key: &str) -> Result<Arc<Self>, DecodeError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1010 | let key = vodozemac::Curve25519PublicKey::from_base64(key) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1011 | .map_err(matrix_sdk_crypto::backups::DecodeError::PublicKey)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1012 | let inner = vodozemac::pk_encryption::PkEncryption::from_key(key); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1013 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1014 | Ok(Self { inner }.into()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1015 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1016 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1017 | /// Encrypt a message using this [`PkEncryption`] object. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1018 | pub fn encrypt(&self, plaintext: &str) -> Option<PkMessage> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1019 | use vodozemac::base64_encode; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1020 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1021 | let message = self.inner.encrypt(plaintext.as_ref()).ok()?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1022 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1023 | let vodozemac::pk_encryption::Message { ciphertext, mac, ephemeral_key } = message; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1024 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1025 | Some(PkMessage { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1026 | ciphertext: base64_encode(ciphertext), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1027 | mac: base64_encode(mac), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1028 | ephemeral_key: ephemeral_key.to_base64(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1029 | }) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1030 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1031 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1032 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1033 | /// A message that was encrypted using a [`PkEncryption`] object. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1034 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1035 | pub struct PkMessage { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1036 | /// The ciphertext of the message. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1037 | pub ciphertext: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1038 | /// The message authentication code of the message. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1039 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1040 | /// *Warning*: This does not authenticate the ciphertext. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1041 | pub mac: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1042 | /// The ephemeral Curve25519 key of the message which was used to derive the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1043 | /// individual message key. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1044 | pub ephemeral_key: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1045 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1046 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1047 | uniffi::setup_scaffolding!(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1048 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1049 | #[cfg(test)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1050 | mod tests { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1051 | use anyhow::Result; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1052 | use serde_json::{Value, json}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1053 | use tempfile::tempdir; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1054 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1055 | use super::MigrationData; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1056 | use crate::{EventEncryptionAlgorithm, OlmMachine, RoomSettings, migrate}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1057 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1058 | #[test] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1059 | fn android_migration() -> Result<()> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1060 | let data: Value = json!({ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1061 | "account":{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1062 | "user_id":"@ganfra146:matrix.org", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1063 | "device_id":"DEWRCMENGS", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1064 | "pickle":"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", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1065 | "shared":true, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1066 | "uploaded_signed_key_count":50 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1067 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1068 | "sessions":[ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1069 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1070 | "pickle":"cryZlFaQv0hwWe6tTgv75RExFKGnC8tMHBXJYMHOw4s+SdrKUYAMUdGcYD7QukrPklEOy7fJho9YGK/jV04QdA8JABiOfD+ngJTR4V8eZdmDuG08+Q5EL79V81hQwU2fKndP0y/9nAXPUIADYq0Zrg4EsOnXz7aE+hAeBAm0IBog1s8RYUvynZ15uwjbd/OTLP+gpqpX33DwVg2leiBkQetiUSpOpZCuQ8CcZwIA0MoGCqvaT7h76VHX9JxJx+2fCMhsJMx1nhd99WJH1W9ge5CtdbC4KUP92OSxIrPOnMrNcOPJPp/paZP+HFNQ3PDL+z8pGKXmCnrXGSbd7iPHurPYESrVkBzr", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1071 | "sender_key":"WJ6Ce7U67a6jqkHYHd8o0+5H4bqdi9hInZdk0+swuXs", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1072 | "created_using_fallback_key":false, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1073 | "creation_time": 1649425011424u64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1074 | "last_use_time": 1649425011424u64 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1075 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1076 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1077 | "pickle":"cryZlFaQv0hwWe6tTgv75RExFKGnC8tMHBXJYMHOw4t2W/lowyrV6SXVZp+uG59im0AAfNSKjhjZuiOpQlX7MS+AOJkCNvyujJ2g3KSjLZ94IkoHxkBDHLWSjwaLPu40rfOzJPDpm0XZsR6bQrsxKOmXLGEw2qw5jOTouzMVL2gvuuTix97nSYSU8j3XvTMRUoh0AF/tUpRLcvEFZeGrdUYmTMlyTv4na+FVUalUZ+jrk8t1/sM99JNq3SY1IBSjrBq/0rCOHieiippz0sw2fe2b87id4rqj1g3R9w2MWTWEdOz3ugjMGYF1YDBQZA1tJZ/hmgppk2AU2xKQXE2X3DgSC6fC66D4", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1078 | "sender_key":"RzRROfmHNlBfzxnNCUYBfn/5oZNQ11XYjDg59hS+mV0", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1079 | "created_using_fallback_key":false, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1080 | "creation_time": 1649425011503u64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1081 | "last_use_time": 1649425011503u64 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1082 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1083 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1084 | "pickle":"cryZlFaQv0hwWe6tTgv75RExFKGnC8tMHBXJYMHOw4titbL3SS12PYHpcBPJc6hXnOnZXqrjtjYOD545fck+3utEo8cqqwWubc9tsvxGW3tOWPttLBdAW30Vn8V1M8ebqVCNVWEAb1GKjV4ni8xG7G9SlEcCjLjnF4lJpddSZkqVMFoN0ITr9aSz/eJwXpc3HLreUFXwc8LuQp7krQ4Vt1e5EE/klduqsdurZf5V14RHsmWz2lKjt7nVgtIz/dhtF5F/sGJdg8kCGaHIMSbGAPuPPpa4/Laicb/5otrYt4pg4W4KdFpSGJIcvUQNjXaOZMx3cu/RPJIOyNhx7whG1QiYAUBqAJvr", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1085 | "sender_key":"IXSZugAHig1v8MowE1jxi2wDDDfuZBeJynHlegJVwUc", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1086 | "created_using_fallback_key":false, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1087 | "creation_time": 1649425011566u64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1088 | "last_use_time": 1649425011566u64 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1089 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1090 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1091 | "pickle":"SmkDiFZjNukiarQ7XHQo25FILHsuhNOnxy56cMSQU/Y71jaGbJes4YrvN4Dfy4RSONfejEDXDkbW2JudlHHRP/rWEmnfJiGbK6ArbrG2puqIZgOecPnOUgPfCisr49p1Gmf36dPaO5lm/ZSrngfSoxahoeJJE/CcJN98sYM15XytRk2LBwc+CyYDqr4V1qxfsBt6tzJ4+tsAZeRdD0UtipQgysgH56o8N7nKTCkaZz5lfpYCl3FEgwXpLJ0MGQvtQmbORFvOLqR1jZ/EbmNGKiqDDIYsqG0sf78ii1jqfpLDBXLuYDccsg", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1092 | "sender_key":"EB9SC4jVAydKhM6/GcwMc9biKwVNywqW3TerNTrtb1M", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1093 | "created_using_fallback_key":false, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1094 | "creation_time": 1649542063182u64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1095 | "last_use_time": 1649542063182u64 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1096 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1097 | ], |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1098 | "inbound_group_sessions":[ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1099 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1100 | "pickle":"KoA0sxDNQ7lz0vylU9zlmar0VCVQRMCfRrIfTh1bdMhlAgy8/D2ToT+oKRaKy1HiW6H862bzdpgxprlseSjmip9OfLbIuyd2YZcEinwc2666oEI/hpk4oTlE61uE1M+ThfdFf41yGCmaAP7mhjwF234ZrZ6i/F/qx42TLQ8Unc30wDJaJgyheO5eW85SD/0g0cdg2WnEKrx2/wl7Vg/YijT3JMDZ+OsdfJfSZtxBNjlG+PQ/9D31qb1eHfaovc8vFZh5QLfAFg/5rBrF1PhRsC7xOAZbUNdrTbvypNfMM4mznf84C2SzZRSMeAfg5v/YticM3Keg4eHuEj1WO9DrmRXYl6b/pITdf1xuk5euVT0pyxJpXmq41AoAZKAo1l94HGy1LG1RpruD1uQPhiponh5PGHSOf43Q", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1101 | "sender_key":"vJfH7wiYmGos3C8U1XcJ//YWSmkueAYqrmUA6/ukfAM", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1102 | "signing_key":{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1103 | "ed25519":"JGgPQRuYj3ScMdPS+A0P+k/1qS9Hr3qeKXLscI+hS78" |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1104 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1105 | "room_id":"!AZkqtjvtwPAuyNOXEt:matrix.org", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1106 | "forwarding_chains":[ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1107 | ], |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1108 | "imported":true, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1109 | "backed_up":true |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1110 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1111 | { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1112 | "pickle":"9RF6GBu9CvjZZx2hxIlw2gMdKs36LFhXhLTHAPrLSjT2OTbeE/jK263+iiFdSpF7Cblp/lXzljPKJN6sL8JGzoT7ssYh56nI0kKsp7/y88z+tTOH/5NYYTmZzHYw6yy4Cmaxh0pdHDs+RQpSSIe9jhF/EJJna5jcKYXxDY52m8H4LECQzVuDlYfblCr9zoYWhQrVhiRDGy7eLhk4X6Rp0Yoek4YUKcCQArDfZ/Vf43qfHUpOJgRpm5Oyj42HA/j4xZBb5U0Fmo6YHRPt0/KuWrDfpgJSGiN0zza7641IfADg8f3WdhlPAWMyri7k4vOZMBjlwFNcMpc0wM2TaTmbi2zqXEKZy9Oh/eJqBapFx0oNWaQ1VQ++iXxGUbZhwy7x2vd6UkqUTwYeym+aP23ee3TCtnNWN0aC", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1113 | "sender_key":"EB9SC4jVAydKhM6/GcwMc9biKwVNywqW3TerNTrtb1M", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1114 | "signing_key":{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1115 | "ed25519":"1NXa5GyJ+p2ruAClEque+TL1VktrBzMW4dZFNfNGrvc" |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1116 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1117 | "room_id":"!CWLUCoEWXSFyTCOtfL:matrix.org", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1118 | "forwarding_chains":[], |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1119 | "imported":true, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1120 | "backed_up":true |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1121 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1122 | ], |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1123 | "pickle_key": [17, 36, 120, 74, 95, 78, 56, 36, 62, 123, 5, 105, 74, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1124 | 111, 70, 48, 51, 101, 66, 86, 116, 14, 114, 85, 85, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1125 | 92, 44, 71, 89, 99, 55, 74], |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1126 | "backup_version":"3", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1127 | "backup_recovery_key":"EsTHScmRV5oT1WBhe2mj2Gn3odeYantZ4NEk7L51p6L8hrmB", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1128 | "cross_signing":{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1129 | "master_key":"trnK/dBv/M2x2zZt8lnORHQqmFHWvjYE6rdlAONRUPY", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1130 | "self_signing_key":"SJhsj9jXC4hxhqS/1B3RZ65zWMHuF+1fUjWHrzVRh6w", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1131 | "user_signing_key":"LPYrV11T9Prm4ZIUxrq2a8Y/F64R1+NaGNyo6GlXjGg" |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1132 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1133 | "tracked_users":[ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1134 | "@ganfra146:matrix.org", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1135 | "@this-is-me:matrix.org", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1136 | "@Amandine:matrix.org", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1137 | "@ganfra:matrix.org", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1138 | "NotAUser%ID" |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1139 | ], |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1140 | "room_settings": { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1141 | "!AZkqtjvtwPAuyNOXEt:matrix.org": { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1142 | "algorithm": "OlmV1Curve25519AesSha2", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1143 | "only_allow_trusted_devices": true |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1144 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1145 | "!CWLUCoEWXSFyTCOtfL:matrix.org": { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1146 | "algorithm": "MegolmV1AesSha2", |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1147 | "only_allow_trusted_devices": false |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1148 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1149 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1150 | }); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1151 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1152 | let migration_data: MigrationData = serde_json::from_value(data)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1153 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1154 | let dir = tempdir()?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1155 | let path = dir |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1156 | .path() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1157 | .to_str() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1158 | .expect("Creating a string from the tempdir path should not fail") |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1159 | .to_owned(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1160 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1161 | migrate(migration_data, path.clone(), None, Box::new(|_, _| {}))?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1162 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1163 | let machine = OlmMachine::new( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1164 | "@ganfra146:matrix.org".to_owned(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1165 | "DEWRCMENGS".to_owned(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1166 | path, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1167 | None, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1168 | )?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1169 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1170 | assert_eq!( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1171 | machine.identity_keys()["ed25519"], |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1172 | "JGgPQRuYj3ScMdPS+A0P+k/1qS9Hr3qeKXLscI+hS78" |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1173 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1174 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1175 | let room_keys = |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1176 | machine.runtime.block_on(machine.inner.store().export_room_keys(|_| true))?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1177 | assert_eq!(room_keys.len(), 2); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1178 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1179 | let cross_signing_status = machine.cross_signing_status(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1180 | assert!(cross_signing_status.has_master); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1181 | assert!(cross_signing_status.has_user_signing); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1182 | assert!(cross_signing_status.has_self_signing); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1183 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1184 | let backup_keys = machine.get_backup_keys()?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1185 | assert!(backup_keys.is_some()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1186 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1187 | let settings1 = machine.get_room_settings("!AZkqtjvtwPAuyNOXEt:matrix.org".into())?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1188 | assert_eq!( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1189 | Some(RoomSettings { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1190 | algorithm: EventEncryptionAlgorithm::OlmV1Curve25519AesSha2, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1191 | #[cfg(feature = "experimental-encrypted-state-events")] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1192 | encrypt_state_events: false, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1193 | only_allow_trusted_devices: true |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1194 | }), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1195 | settings1 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1196 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1197 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1198 | let settings2 = machine.get_room_settings("!CWLUCoEWXSFyTCOtfL:matrix.org".into())?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1199 | assert_eq!( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1200 | Some(RoomSettings { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1201 | algorithm: EventEncryptionAlgorithm::MegolmV1AesSha2, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1202 | #[cfg(feature = "experimental-encrypted-state-events")] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1203 | encrypt_state_events: false, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1204 | only_allow_trusted_devices: false |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1205 | }), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1206 | settings2 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1207 | ); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1208 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1209 | let settings3 = machine.get_room_settings("!XYZ:matrix.org".into())?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1210 | assert!(settings3.is_none()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1211 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1212 | assert!(machine.is_user_tracked("@ganfra146:matrix.org".into()).unwrap()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1213 | assert!(machine.is_user_tracked("@Amandine:matrix.org".into()).unwrap()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1214 | assert!(machine.is_user_tracked("@this-is-me:matrix.org".into()).unwrap()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1215 | assert!(machine.is_user_tracked("@ganfra:matrix.org".into()).unwrap()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1216 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1217 | Ok(()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1218 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1219 | } |