@@ -25,7 +25,7 @@ pub use crate::database::EncryptionContext;
2525///
2626/// # Note
2727///
28- /// Embedded replica's require a clean database (no database file) or a previously synced database or else it will
28+ /// Embedded replicas require a clean database (no database file) or a previously synced database or else it will
2929/// throw an error to prevent any misuse. To work around this error a user can delete the database
3030/// and let it resync and create the wal_index metadata file.
3131pub struct Builder < T = ( ) > {
@@ -276,7 +276,7 @@ cfg_replication! {
276276 self
277277 }
278278
279- /// Set weather you want writes to be visible locally before the write query returns. This
279+ /// Set whether you want writes to be visible locally before the write query returns. This
280280 /// means that you will be able to read your own writes if this is set to `true`.
281281 ///
282282 /// # Default
@@ -306,8 +306,8 @@ cfg_replication! {
306306
307307 /// Set the encryption context if the database is encrypted in remote server.
308308 #[ cfg( feature = "sync" ) ]
309- pub fn remote_encryption( mut self , encryption_context: Option < EncryptionContext > ) -> Builder <RemoteReplica > {
310- self . inner. remote_encryption = encryption_context;
309+ pub fn remote_encryption( mut self , encryption_context: EncryptionContext ) -> Builder <RemoteReplica > {
310+ self . inner. remote_encryption = Some ( encryption_context) ;
311311 self
312312 }
313313
@@ -333,7 +333,7 @@ cfg_replication! {
333333 self
334334 }
335335
336- /// Skip the saftey assert used to ensure that sqlite3 is configured correctly for the way
336+ /// Skip the safety assert used to ensure that sqlite3 is configured correctly for the way
337337 /// that libsql uses the ffi code. By default, libsql will try to use the SERIALIZED
338338 /// threadsafe mode for sqlite3. This allows us to implement Send/Sync for all the types to
339339 /// allow them to move between threads safely. Due to the fact that sqlite3 has a global
@@ -399,9 +399,14 @@ cfg_replication! {
399399 url. to_string( )
400400 } ;
401401 let req = http:: Request :: get( format!( "{prefix}/info" ) )
402- . header( "Authorization" , format!( "Bearer {}" , auth_token) )
403- . body( hyper:: Body :: empty( ) )
404- . unwrap( ) ;
402+ . header( "Authorization" , format!( "Bearer {}" , auth_token) ) ;
403+
404+ let req = if let Some ( ref remote_encryption) = remote_encryption {
405+ req. header( "x-turso-encryption-key" , remote_encryption. key. as_string( ) )
406+ } else {
407+ req
408+ } ;
409+ let req = req. body( hyper:: Body :: empty( ) ) . unwrap( ) ;
405410
406411 let res = client
407412 . request( req)
@@ -427,11 +432,14 @@ cfg_replication! {
427432
428433 if res. status( ) . is_success( ) {
429434 tracing:: trace!( "Using sync protocol v2 for {}" , url) ;
430- let builder = Builder :: new_synced_database( path, url, auth_token)
435+ let mut builder = Builder :: new_synced_database( path, url, auth_token)
431436 . connector( connector)
432437 . remote_writes( true )
433- . read_your_writes( read_your_writes)
434- . remote_encryption( remote_encryption) ;
438+ . read_your_writes( read_your_writes) ;
439+
440+ if let Some ( encryption) = remote_encryption {
441+ builder = builder. remote_encryption( encryption) ;
442+ }
435443
436444 let builder = if let Some ( sync_interval) = sync_interval {
437445 builder. sync_interval( sync_interval)
@@ -616,8 +624,8 @@ cfg_sync! {
616624 }
617625
618626 /// Set the encryption context if the database is encrypted in remote server.
619- pub fn remote_encryption( mut self , encryption_context: Option < EncryptionContext > ) -> Builder <SyncedDatabase > {
620- self . inner. remote_encryption = encryption_context;
627+ pub fn remote_encryption( mut self , encryption_context: EncryptionContext ) -> Builder <SyncedDatabase > {
628+ self . inner. remote_encryption = Some ( encryption_context) ;
621629 self
622630 }
623631
@@ -784,8 +792,8 @@ cfg_remote! {
784792 }
785793
786794 /// Set the encryption context if the database is encrypted in remote server.
787- pub fn remote_encryption( mut self , encryption_context: Option < EncryptionContext > ) -> Builder <Remote > {
788- self . inner. remote_encryption = encryption_context;
795+ pub fn remote_encryption( mut self , encryption_context: EncryptionContext ) -> Builder <Remote > {
796+ self . inner. remote_encryption = Some ( encryption_context) ;
789797 self
790798 }
791799
0 commit comments