Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libsql: Force AES256CBC for embedded replica's #1128

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 1 addition & 2 deletions bindings/c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ pub unsafe extern "C" fn libsql_open_sync(
}
};
let key = bytes::Bytes::copy_from_slice(key.as_bytes());
let config = libsql::EncryptionConfig::new(libsql::Cipher::Aes256Cbc, key);
builder.encryption_config(config)
builder.encryption_key(key)
};
match RT.block_on(builder.build()) {
Ok(db) => {
Expand Down
8 changes: 2 additions & 6 deletions libsql/examples/replica.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use libsql::{Builder, Cipher, EncryptionConfig, Value};
use libsql::{Builder, Value};
use std::time::Duration;

#[tokio::main]
Expand All @@ -21,12 +21,8 @@ async fn main() {
.replace("libsql", "https");

let db = if cfg!(feature = "encryption") {
let encryption_config = EncryptionConfig {
cipher: Cipher::Aes256Cbc,
encryption_key: "s3cr3t".into(),
};
Builder::new_remote_replica(db_file.path(), url, auth_token)
.encryption_config(encryption_config)
.encryption_key("s3cr3t")
.build()
.await
.unwrap()
Expand Down
17 changes: 13 additions & 4 deletions libsql/src/database/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ cfg_core! {
}

/// Set an encryption config that will encrypt the local database.
#[cfg(feature = "encryption")]
#[cfg_attr(docsrs, doc(cfg(feature = "encryption")))]
pub fn encryption_config(
mut self,
encryption_config: EncryptionConfig,
Expand Down Expand Up @@ -183,15 +185,22 @@ cfg_replication! {
self
}

/// Set an encryption key that will encrypt the local database.
pub fn encryption_config(
/// Set an encryption key that will encrypt the local database. This will default to
/// `AES256CBC` encryption cipher.
#[cfg(feature = "encryption")]
#[cfg_attr(docsrs, doc(cfg(feature = "encryption")))]
pub fn encryption_key(
mut self,
encryption_config: EncryptionConfig,
encryption_key: impl Into<bytes::Bytes>,
) -> Builder<RemoteReplica> {
self.inner.encryption_config = Some(encryption_config.into());
self.inner.encryption_config = Some(EncryptionConfig {
cipher: libsql_sys::Cipher::Aes256Cbc,
encryption_key: encryption_key.into()
});
self
}


/// Set weather you want writes to be visible locally before the write query returns. This
/// means that you will be able to read your own writes if this is set to `true`.
///
Expand Down
Loading