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
1 change: 1 addition & 0 deletions bindings/c/include/libsql.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef struct {
int sync_interval;
char with_webpki;
char offline;
const char *remote_encryption_key;
} libsql_config;

typedef const libsql_connection *libsql_connection_t;
Expand Down
28 changes: 28 additions & 0 deletions bindings/c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub unsafe extern "C" fn libsql_open_sync(
sync_interval: 0,
with_webpki: 0,
offline: 0,
remote_encryption_key: std::ptr::null(),
};
libsql_open_sync_with_config(config, out_db, out_err_msg)
}
Expand All @@ -121,6 +122,7 @@ pub unsafe extern "C" fn libsql_open_sync_with_webpki(
sync_interval: 0,
with_webpki: 1,
offline: 0,
remote_encryption_key: std::ptr::null(),
};
libsql_open_sync_with_config(config, out_db, out_err_msg)
}
Expand Down Expand Up @@ -271,6 +273,19 @@ pub unsafe extern "C" fn libsql_open_sync_with_config(
.build();
builder = builder.connector(https);
}
if !config.remote_encryption_key.is_null() {
let key = unsafe { std::ffi::CStr::from_ptr(config.remote_encryption_key) };
let key = match key.to_str() {
Ok(k) => k,
Err(e) => {
set_err_msg(format!("Wrong encryption key: {e}"), out_err_msg);
return 5;
}
};
builder = builder.remote_encryption(libsql::EncryptionContext {
key: libsql::EncryptionKey::Base64Encoded(key.to_string()),
});
};
match RT.block_on(builder.build()) {
Ok(db) => {
let db = Box::leak(Box::new(libsql_database { db }));
Expand Down Expand Up @@ -325,6 +340,19 @@ pub unsafe extern "C" fn libsql_open_sync_with_config(
let config = libsql::EncryptionConfig::new(libsql::Cipher::Aes256Cbc, key);
builder = builder.encryption_config(config)
};
if !config.remote_encryption_key.is_null() {
let key = unsafe { std::ffi::CStr::from_ptr(config.remote_encryption_key) };
let key = match key.to_str() {
Ok(k) => k,
Err(e) => {
set_err_msg(format!("Wrong encryption key: {e}"), out_err_msg);
return 5;
}
};
builder = builder.remote_encryption(libsql::EncryptionContext {
key: libsql::EncryptionKey::Base64Encoded(key.to_string()),
});
};
match RT.block_on(builder.build()) {
Ok(db) => {
let db = Box::leak(Box::new(libsql_database { db }));
Expand Down
1 change: 1 addition & 0 deletions bindings/c/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct libsql_config {
pub sync_interval: std::ffi::c_int,
pub with_webpki: std::ffi::c_char,
pub offline: std::ffi::c_char,
pub remote_encryption_key: *const std::ffi::c_char,
}

#[derive(Clone, Debug)]
Expand Down
Loading