Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions libsql/examples/encryption_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 12 additions & 9 deletions libsql/src/database/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EncryptionContext>) -> Builder<RemoteReplica> {
self.inner.remote_encryption = encryption_context;
pub fn remote_encryption(mut self, encryption_context: EncryptionContext) -> Builder<RemoteReplica> {
self.inner.remote_encryption = Some(encryption_context);
self
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<EncryptionContext>) -> Builder<SyncedDatabase> {
self.inner.remote_encryption = encryption_context;
pub fn remote_encryption(mut self, encryption_context: EncryptionContext) -> Builder<SyncedDatabase> {
self.inner.remote_encryption = Some(encryption_context);
self
}

Expand Down Expand Up @@ -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<EncryptionContext>) -> Builder<Remote> {
self.inner.remote_encryption = encryption_context;
pub fn remote_encryption(mut self, encryption_context: EncryptionContext) -> Builder<Remote> {
self.inner.remote_encryption = Some(encryption_context);
self
}

Expand Down
Loading