From 6a815d67b3560341f1fd321bf69adad6a92a2fc0 Mon Sep 17 00:00:00 2001 From: Avinash Sajjanshetty Date: Sun, 13 Jul 2025 15:29:52 +0530 Subject: [PATCH 1/2] Update `remote_encryption` builder to take obj instead of option --- libsql/src/database/builder.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/libsql/src/database/builder.rs b/libsql/src/database/builder.rs index 990596121a..e691adc2bc 100644 --- a/libsql/src/database/builder.rs +++ b/libsql/src/database/builder.rs @@ -306,8 +306,8 @@ cfg_replication! { /// Set the encryption context if the database is encrypted in remote server. #[cfg(feature = "sync")] - pub fn remote_encryption(mut self, encryption_context: Option) -> Builder { - self.inner.remote_encryption = encryption_context; + pub fn remote_encryption(mut self, encryption_context: EncryptionContext) -> Builder { + self.inner.remote_encryption = Some(encryption_context); self } @@ -432,11 +432,14 @@ cfg_replication! { if res.status().is_success() { tracing::trace!("Using sync protocol v2 for {}", url); - let builder = Builder::new_synced_database(path, url, auth_token) + let mut builder = Builder::new_synced_database(path, url, auth_token) .connector(connector) .remote_writes(true) - .read_your_writes(read_your_writes) - .remote_encryption(remote_encryption); + .read_your_writes(read_your_writes); + + if let Some(encryption) = remote_encryption { + builder = builder.remote_encryption(encryption); + } let builder = if let Some(sync_interval) = sync_interval { builder.sync_interval(sync_interval) @@ -621,8 +624,8 @@ cfg_sync! { } /// Set the encryption context if the database is encrypted in remote server. - pub fn remote_encryption(mut self, encryption_context: Option) -> Builder { - self.inner.remote_encryption = encryption_context; + pub fn remote_encryption(mut self, encryption_context: EncryptionContext) -> Builder { + self.inner.remote_encryption = Some(encryption_context); self } @@ -789,8 +792,8 @@ cfg_remote! { } /// Set the encryption context if the database is encrypted in remote server. - pub fn remote_encryption(mut self, encryption_context: Option) -> Builder { - self.inner.remote_encryption = encryption_context; + pub fn remote_encryption(mut self, encryption_context: EncryptionContext) -> Builder { + self.inner.remote_encryption = Some(encryption_context); self } From 8ab446a0ec509a407fa34a61901be7666124266c Mon Sep 17 00:00:00 2001 From: Avinash Sajjanshetty Date: Sun, 13 Jul 2025 15:30:05 +0530 Subject: [PATCH 2/2] update encryption sync example --- libsql/examples/encryption_sync.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libsql/examples/encryption_sync.rs b/libsql/examples/encryption_sync.rs index 15a3b22eaf..8159b3c5fa 100644 --- a/libsql/examples/encryption_sync.rs +++ b/libsql/examples/encryption_sync.rs @@ -25,8 +25,11 @@ async fn main() { None }; - let db_builder = - Builder::new_synced_database(db_path, sync_url, auth_token).remote_encryption(encryption); + let mut db_builder = Builder::new_synced_database(db_path, sync_url, auth_token); + + if let Some(enc) = encryption { + db_builder = db_builder.remote_encryption(enc); + } let db = match db_builder.build().await { Ok(db) => db,