@@ -98,6 +98,7 @@ pub unsafe extern "C" fn libsql_open_sync(
98
98
sync_interval : 0 ,
99
99
with_webpki : 0 ,
100
100
offline : 0 ,
101
+ remote_encryption_key : std:: ptr:: null ( ) ,
101
102
} ;
102
103
libsql_open_sync_with_config ( config, out_db, out_err_msg)
103
104
}
@@ -121,6 +122,7 @@ pub unsafe extern "C" fn libsql_open_sync_with_webpki(
121
122
sync_interval : 0 ,
122
123
with_webpki : 1 ,
123
124
offline : 0 ,
125
+ remote_encryption_key : std:: ptr:: null ( ) ,
124
126
} ;
125
127
libsql_open_sync_with_config ( config, out_db, out_err_msg)
126
128
}
@@ -271,6 +273,19 @@ pub unsafe extern "C" fn libsql_open_sync_with_config(
271
273
. build ( ) ;
272
274
builder = builder. connector ( https) ;
273
275
}
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
+ } ;
274
289
match RT . block_on ( builder. build ( ) ) {
275
290
Ok ( db) => {
276
291
let db = Box :: leak ( Box :: new ( libsql_database { db } ) ) ;
@@ -325,6 +340,19 @@ pub unsafe extern "C" fn libsql_open_sync_with_config(
325
340
let config = libsql:: EncryptionConfig :: new ( libsql:: Cipher :: Aes256Cbc , key) ;
326
341
builder = builder. encryption_config ( config)
327
342
} ;
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
+ } ;
328
356
match RT . block_on ( builder. build ( ) ) {
329
357
Ok ( db) => {
330
358
let db = Box :: leak ( Box :: new ( libsql_database { db } ) ) ;
0 commit comments