@@ -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,7 @@ impl Builder<()> {
6463 connector: None ,
6564 version: None ,
6665 namespace: None ,
66+ remote_encryption: None
6767 } ,
6868 encryption_config: None ,
6969 read_your_writes: true ,
@@ -73,7 +73,7 @@ impl Builder<()> {
7373 #[ cfg( feature = "sync" ) ]
7474 sync_protocol: Default :: default ( ) ,
7575 #[ cfg( feature = "sync" ) ]
76- remote_encryption,
76+ remote_encryption: None
7777 } ,
7878 }
7979 }
@@ -98,7 +98,6 @@ impl Builder<()> {
9898 path: impl AsRef <std:: path:: Path >,
9999 url: String ,
100100 auth_token: String ,
101- remote_encryption: Option <EncryptionContext >,
102101 ) -> Builder <SyncedDatabase > {
103102 Builder {
104103 inner: SyncedDatabase {
@@ -110,13 +109,14 @@ impl Builder<()> {
110109 connector: None ,
111110 version: None ,
112111 namespace: None ,
112+ remote_encryption: None ,
113113 } ,
114114 connector: None ,
115115 read_your_writes: true ,
116116 remote_writes: false ,
117117 push_batch_size: 0 ,
118118 sync_interval: None ,
119- remote_encryption,
119+ remote_encryption: None ,
120120 } ,
121121 }
122122 }
@@ -132,6 +132,7 @@ impl Builder<()> {
132132 connector: None ,
133133 version: None ,
134134 namespace: None ,
135+ remote_encryption: None ,
135136 } ,
136137 }
137138 }
@@ -146,6 +147,7 @@ cfg_replication_or_remote_or_sync! {
146147 connector: Option <crate :: util:: ConnectorService >,
147148 version: Option <String >,
148149 namespace: Option <String >,
150+ remote_encryption: Option <EncryptionContext >,
149151 }
150152}
151153
@@ -238,7 +240,7 @@ cfg_replication! {
238240 #[ cfg( feature = "sync" ) ]
239241 sync_protocol: super :: SyncProtocol ,
240242 #[ cfg( feature = "sync" ) ]
241- remote_encryption: Option <crate :: sync :: EncryptionContext >,
243+ remote_encryption: Option <EncryptionContext >,
242244 }
243245
244246 /// Local replica configuration type in [`Builder`].
@@ -300,6 +302,13 @@ cfg_replication! {
300302 self
301303 }
302304
305+ /// Set the encryption context if the database is encrypted in remote server.
306+ #[ cfg( feature = "sync" ) ]
307+ pub fn remote_encryption( mut self , encryption_context: EncryptionContext ) -> Builder <RemoteReplica > {
308+ self . inner. remote_encryption = Some ( encryption_context) ;
309+ self
310+ }
311+
303312 pub fn http_request_callback<F >( mut self , f: F ) -> Builder <RemoteReplica >
304313 where
305314 F : Fn ( & mut http:: Request <( ) >) + Send + Sync + ' static
@@ -347,6 +356,7 @@ cfg_replication! {
347356 connector,
348357 version,
349358 namespace,
359+ ..
350360 } ,
351361 encryption_config,
352362 read_your_writes,
@@ -415,10 +425,11 @@ cfg_replication! {
415425
416426 if res. status( ) . is_success( ) {
417427 tracing:: trace!( "Using sync protocol v2 for {}" , url) ;
418- let builder = Builder :: new_synced_database( path, url, auth_token, remote_encryption )
428+ let builder = Builder :: new_synced_database( path, url, auth_token)
419429 . connector( connector)
420430 . remote_writes( true )
421- . read_your_writes( read_your_writes) ;
431+ . read_your_writes( read_your_writes)
432+ . remote_encryption( remote_encryption) ;
422433
423434 let builder = if let Some ( sync_interval) = sync_interval {
424435 builder. sync_interval( sync_interval)
@@ -475,7 +486,10 @@ cfg_replication! {
475486
476487
477488 Ok ( Database {
478- db_type: DbType :: Sync { db, encryption_config } ,
489+ db_type: DbType :: Sync {
490+ db,
491+ encryption_config,
492+ } ,
479493 max_write_replication_index: Default :: default ( ) ,
480494 } )
481495 }
@@ -515,6 +529,7 @@ cfg_replication! {
515529 connector,
516530 version,
517531 namespace,
532+ ..
518533 } ) = remote
519534 {
520535 let connector = if let Some ( connector) = connector {
@@ -565,7 +580,7 @@ cfg_sync! {
565580 read_your_writes: bool ,
566581 push_batch_size: u32 ,
567582 sync_interval: Option <std:: time:: Duration >,
568- remote_encryption: Option <crate :: sync :: EncryptionContext >,
583+ remote_encryption: Option <EncryptionContext >,
569584 }
570585
571586 impl Builder <SyncedDatabase > {
@@ -598,6 +613,12 @@ cfg_sync! {
598613 self
599614 }
600615
616+ /// Set the encryption context if the database is encrypted in remote server.
617+ pub fn remote_encryption( mut self , encryption_context: Option <EncryptionContext >) -> Builder <SyncedDatabase > {
618+ self . inner. remote_encryption = encryption_context;
619+ self
620+ }
621+
601622 /// Provide a custom http connector that will be used to create http connections.
602623 pub fn connector<C >( mut self , connector: C ) -> Builder <SyncedDatabase >
603624 where
@@ -624,6 +645,7 @@ cfg_sync! {
624645 connector: _,
625646 version: _,
626647 namespace: _,
648+ ..
627649 } ,
628650 connector,
629651 remote_writes,
@@ -759,6 +781,12 @@ cfg_remote! {
759781 self
760782 }
761783
784+ /// Set the encryption context if the database is encrypted in remote server.
785+ pub fn remote_encryption( mut self , encryption_context: EncryptionContext ) -> Builder <Remote > {
786+ self . inner. remote_encryption = Some ( encryption_context) ;
787+ self
788+ }
789+
762790 /// Build the remote database client.
763791 pub async fn build( self ) -> Result <Database > {
764792 let Remote {
@@ -767,6 +795,7 @@ cfg_remote! {
767795 connector,
768796 version,
769797 namespace,
798+ remote_encryption,
770799 } = self . inner;
771800
772801 let connector = if let Some ( connector) = connector {
@@ -789,6 +818,7 @@ cfg_remote! {
789818 connector,
790819 version,
791820 namespace,
821+ remote_encryption
792822 } ,
793823 max_write_replication_index: Default :: default ( ) ,
794824 } )
0 commit comments