@@ -98,6 +98,7 @@ pub unsafe extern "C" fn libsql_open_sync(
9898 sync_interval : 0 ,
9999 with_webpki : 0 ,
100100 offline : 0 ,
101+ remote_encryption_key : std:: ptr:: null ( ) ,
101102 } ;
102103 libsql_open_sync_with_config ( config, out_db, out_err_msg)
103104}
@@ -121,6 +122,7 @@ pub unsafe extern "C" fn libsql_open_sync_with_webpki(
121122 sync_interval : 0 ,
122123 with_webpki : 1 ,
123124 offline : 0 ,
125+ remote_encryption_key : std:: ptr:: null ( ) ,
124126 } ;
125127 libsql_open_sync_with_config ( config, out_db, out_err_msg)
126128}
@@ -271,6 +273,19 @@ pub unsafe extern "C" fn libsql_open_sync_with_config(
271273 . build ( ) ;
272274 builder = builder. connector ( https) ;
273275 }
276+ if !config. remote_encryption_key . is_null ( ) {
277+ let key = unsafe { std:: ffi:: CStr :: from_ptr ( config. remote_encryption_key ) } ;
278+ let key = match key. to_str ( ) {
279+ Ok ( k) => k,
280+ Err ( e) => {
281+ set_err_msg ( format ! ( "Wrong encryption key: {e}" ) , out_err_msg) ;
282+ return 5 ;
283+ }
284+ } ;
285+ builder = builder. remote_encryption ( libsql:: EncryptionContext {
286+ key : libsql:: EncryptionKey :: Base64Encoded ( key. to_string ( ) ) ,
287+ } ) ;
288+ } ;
274289 match RT . block_on ( builder. build ( ) ) {
275290 Ok ( db) => {
276291 let db = Box :: leak ( Box :: new ( libsql_database { db } ) ) ;
@@ -325,6 +340,19 @@ pub unsafe extern "C" fn libsql_open_sync_with_config(
325340 let config = libsql:: EncryptionConfig :: new ( libsql:: Cipher :: Aes256Cbc , key) ;
326341 builder = builder. encryption_config ( config)
327342 } ;
343+ if !config. remote_encryption_key . is_null ( ) {
344+ let key = unsafe { std:: ffi:: CStr :: from_ptr ( config. remote_encryption_key ) } ;
345+ let key = match key. to_str ( ) {
346+ Ok ( k) => k,
347+ Err ( e) => {
348+ set_err_msg ( format ! ( "Wrong encryption key: {e}" ) , out_err_msg) ;
349+ return 5 ;
350+ }
351+ } ;
352+ builder = builder. remote_encryption ( libsql:: EncryptionContext {
353+ key : libsql:: EncryptionKey :: Base64Encoded ( key. to_string ( ) ) ,
354+ } ) ;
355+ } ;
328356 match RT . block_on ( builder. build ( ) ) {
329357 Ok ( db) => {
330358 let db = Box :: leak ( Box :: new ( libsql_database { db } ) ) ;
0 commit comments