From d47306045fde4cf505ee4b0b9a4b6bea8140318e Mon Sep 17 00:00:00 2001 From: Daniel Salinas Date: Thu, 9 Apr 2026 12:01:50 -0400 Subject: [PATCH] Add cfg around inadvertent use of sqlite in matrix-sdk-ffi crate Several new functions implicitly rely on the sqlite config. sqlite might not be present if you are using the indexedb store, in which case these functions are likely irrelevant. This change conditionalizes their compilation. --- bindings/matrix-sdk-ffi/src/encryption.rs | 52 +++++++++++++---------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/encryption.rs b/bindings/matrix-sdk-ffi/src/encryption.rs index 9c4c222c3..06fa0fae4 100644 --- a/bindings/matrix-sdk-ffi/src/encryption.rs +++ b/bindings/matrix-sdk-ffi/src/encryption.rs @@ -290,6 +290,7 @@ pub enum BundleExportError { InvalidBackup, } +#[cfg(feature = "sqlite")] impl From for BundleExportError { fn from(value: matrix_sdk::encryption::BundleExportError) -> Self { match value { @@ -312,31 +313,9 @@ impl From for BundleExportError { } } +#[cfg(feature = "sqlite")] #[matrix_sdk_ffi_macros::export] impl SecretsBundleWithUserId { - /// Attempt to create a [`SecretsBundle`] from a previously JSON serialized - /// bundle. - #[uniffi::constructor] - pub fn from_str( - user_id: &str, - bundle: &str, - backup_info: &str, - ) -> Result, BundleExportError> { - let user_id = - OwnedUserId::from_str(user_id).map_err(|e| serde_json::Error::custom(e.to_string()))?; - let bundle: matrix_sdk_base::crypto::types::SecretsBundle = serde_json::from_str(bundle)?; - let backup_info = serde_json::from_str(backup_info)?; - - let is_backup_ok = - bundle.backup.as_ref().is_some_and(|backup| is_valid_backup(backup, &backup_info)); - - if is_backup_ok { - Ok(Self { user_id, inner: bundle }.into()) - } else { - Err(BundleExportError::InvalidBackup) - } - } - /// Attempt to export a [`SecretsBundle`] from a crypto store. /// /// This method can be used to retrieve a [`SecretsBundle`] from an existing @@ -376,6 +355,32 @@ impl SecretsBundleWithUserId { ret } +} + +#[matrix_sdk_ffi_macros::export] +impl SecretsBundleWithUserId { + /// Attempt to create a [`SecretsBundle`] from a previously JSON serialized + /// bundle. + #[uniffi::constructor] + pub fn from_str( + user_id: &str, + bundle: &str, + backup_info: &str, + ) -> Result, BundleExportError> { + let user_id = + OwnedUserId::from_str(user_id).map_err(|e| serde_json::Error::custom(e.to_string()))?; + let bundle: matrix_sdk_base::crypto::types::SecretsBundle = serde_json::from_str(bundle)?; + let backup_info = serde_json::from_str(backup_info)?; + + let is_backup_ok = + bundle.backup.as_ref().is_some_and(|backup| is_valid_backup(backup, &backup_info)); + + if is_backup_ok { + Ok(Self { user_id, inner: bundle }.into()) + } else { + Err(BundleExportError::InvalidBackup) + } + } /// Does the bundle contain a backup key. /// @@ -428,6 +433,7 @@ pub fn json_string_contains_secrets_bundle( } /// Check if a crypto store contains a valid [`SecretsBundle`]. +#[cfg(feature = "sqlite")] #[matrix_sdk_ffi_macros::export] pub async fn database_contains_secrets_bundle( database_path: &str,