@@ -5,7 +5,8 @@ cfg_core! {
55use super :: DbType ;
66use crate :: { Database , Result } ;
77
8- pub use crate :: sync:: EncryptionContext ;
8+ #[ cfg( any( feature = "remote" , feature = "sync" ) ) ]
9+ pub use crate :: database:: EncryptionContext ;
910
1011/// A builder for [`Database`]. This struct can be used to build
1112/// all variants of [`Database`]. These variants include:
@@ -52,8 +53,6 @@ impl Builder<()> {
5253 path: impl AsRef <std:: path:: Path >,
5354 url: String ,
5455 auth_token: String ,
55- #[ cfg( feature = "sync" ) ]
56- remote_encryption: Option <crate :: sync:: EncryptionContext >,
5756 ) -> Builder <RemoteReplica > {
5857 Builder {
5958 inner: RemoteReplica {
@@ -64,6 +63,8 @@ impl Builder<()> {
6463 connector: None ,
6564 version: None ,
6665 namespace: None ,
66+ #[ cfg( any( feature = "remote" , feature = "sync" ) ) ]
67+ remote_encryption: None ,
6768 } ,
6869 encryption_config: None ,
6970 read_your_writes: true ,
@@ -73,7 +74,7 @@ impl Builder<()> {
7374 #[ cfg( feature = "sync" ) ]
7475 sync_protocol: Default :: default ( ) ,
7576 #[ cfg( feature = "sync" ) ]
76- remote_encryption,
77+ remote_encryption: None
7778 } ,
7879 }
7980 }
@@ -98,7 +99,6 @@ impl Builder<()> {
9899 path: impl AsRef <std:: path:: Path >,
99100 url: String ,
100101 auth_token: String ,
101- remote_encryption: Option <EncryptionContext >,
102102 ) -> Builder <SyncedDatabase > {
103103 Builder {
104104 inner: SyncedDatabase {
@@ -110,13 +110,14 @@ impl Builder<()> {
110110 connector: None ,
111111 version: None ,
112112 namespace: None ,
113+ remote_encryption: None ,
113114 } ,
114115 connector: None ,
115116 read_your_writes: true ,
116117 remote_writes: false ,
117118 push_batch_size: 0 ,
118119 sync_interval: None ,
119- remote_encryption,
120+ remote_encryption: None ,
120121 } ,
121122 }
122123 }
@@ -132,6 +133,7 @@ impl Builder<()> {
132133 connector: None ,
133134 version: None ,
134135 namespace: None ,
136+ remote_encryption: None ,
135137 } ,
136138 }
137139 }
@@ -146,6 +148,8 @@ cfg_replication_or_remote_or_sync! {
146148 connector: Option <crate :: util:: ConnectorService >,
147149 version: Option <String >,
148150 namespace: Option <String >,
151+ #[ cfg( any( feature = "remote" , feature = "sync" ) ) ]
152+ remote_encryption: Option <EncryptionContext >,
149153 }
150154}
151155
@@ -238,7 +242,7 @@ cfg_replication! {
238242 #[ cfg( feature = "sync" ) ]
239243 sync_protocol: super :: SyncProtocol ,
240244 #[ cfg( feature = "sync" ) ]
241- remote_encryption: Option <crate :: sync :: EncryptionContext >,
245+ remote_encryption: Option <EncryptionContext >,
242246 }
243247
244248 /// Local replica configuration type in [`Builder`].
@@ -300,6 +304,13 @@ cfg_replication! {
300304 self
301305 }
302306
307+ /// Set the encryption context if the database is encrypted in remote server.
308+ #[ cfg( feature = "sync" ) ]
309+ pub fn remote_encryption( mut self , encryption_context: Option <EncryptionContext >) -> Builder <RemoteReplica > {
310+ self . inner. remote_encryption = encryption_context;
311+ self
312+ }
313+
303314 pub fn http_request_callback<F >( mut self , f: F ) -> Builder <RemoteReplica >
304315 where
305316 F : Fn ( & mut http:: Request <( ) >) + Send + Sync + ' static
@@ -347,6 +358,7 @@ cfg_replication! {
347358 connector,
348359 version,
349360 namespace,
361+ ..
350362 } ,
351363 encryption_config,
352364 read_your_writes,
@@ -415,10 +427,11 @@ cfg_replication! {
415427
416428 if res. status( ) . is_success( ) {
417429 tracing:: trace!( "Using sync protocol v2 for {}" , url) ;
418- let builder = Builder :: new_synced_database( path, url, auth_token, remote_encryption )
430+ let builder = Builder :: new_synced_database( path, url, auth_token)
419431 . connector( connector)
420432 . remote_writes( true )
421- . read_your_writes( read_your_writes) ;
433+ . read_your_writes( read_your_writes)
434+ . remote_encryption( remote_encryption) ;
422435
423436 let builder = if let Some ( sync_interval) = sync_interval {
424437 builder. sync_interval( sync_interval)
@@ -475,7 +488,10 @@ cfg_replication! {
475488
476489
477490 Ok ( Database {
478- db_type: DbType :: Sync { db, encryption_config } ,
491+ db_type: DbType :: Sync {
492+ db,
493+ encryption_config,
494+ } ,
479495 max_write_replication_index: Default :: default ( ) ,
480496 } )
481497 }
@@ -515,6 +531,7 @@ cfg_replication! {
515531 connector,
516532 version,
517533 namespace,
534+ ..
518535 } ) = remote
519536 {
520537 let connector = if let Some ( connector) = connector {
@@ -565,7 +582,7 @@ cfg_sync! {
565582 read_your_writes: bool ,
566583 push_batch_size: u32 ,
567584 sync_interval: Option <std:: time:: Duration >,
568- remote_encryption: Option <crate :: sync :: EncryptionContext >,
585+ remote_encryption: Option <EncryptionContext >,
569586 }
570587
571588 impl Builder <SyncedDatabase > {
@@ -598,6 +615,12 @@ cfg_sync! {
598615 self
599616 }
600617
618+ /// 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;
621+ self
622+ }
623+
601624 /// Provide a custom http connector that will be used to create http connections.
602625 pub fn connector<C >( mut self , connector: C ) -> Builder <SyncedDatabase >
603626 where
@@ -624,6 +647,7 @@ cfg_sync! {
624647 connector: _,
625648 version: _,
626649 namespace: _,
650+ ..
627651 } ,
628652 connector,
629653 remote_writes,
@@ -759,6 +783,12 @@ cfg_remote! {
759783 self
760784 }
761785
786+ /// 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;
789+ self
790+ }
791+
762792 /// Build the remote database client.
763793 pub async fn build( self ) -> Result <Database > {
764794 let Remote {
@@ -767,6 +797,7 @@ cfg_remote! {
767797 connector,
768798 version,
769799 namespace,
800+ remote_encryption,
770801 } = self . inner;
771802
772803 let connector = if let Some ( connector) = connector {
@@ -789,6 +820,7 @@ cfg_remote! {
789820 connector,
790821 version,
791822 namespace,
823+ remote_encryption
792824 } ,
793825 max_write_replication_index: Default :: default ( ) ,
794826 } )
0 commit comments