@@ -5,7 +5,7 @@ cfg_core! {
55use super :: DbType ;
66use crate :: { Database , Result } ;
77
8- pub use crate :: sync :: EncryptionContext ;
8+ pub use crate :: database :: EncryptionContext ;
99
1010/// A builder for [`Database`]. This struct can be used to build
1111/// all variants of [`Database`]. These variants include:
@@ -52,8 +52,6 @@ impl Builder<()> {
5252 path: impl AsRef <std:: path:: Path >,
5353 url: String ,
5454 auth_token: String ,
55- #[ cfg( feature = "sync" ) ]
56- remote_encryption: Option <crate :: sync:: EncryptionContext >,
5755 ) -> Builder <RemoteReplica > {
5856 Builder {
5957 inner: RemoteReplica {
@@ -64,6 +62,7 @@ impl Builder<()> {
6462 connector: None ,
6563 version: None ,
6664 namespace: None ,
65+ remote_encryption: None
6766 } ,
6867 encryption_config: None ,
6968 read_your_writes: true ,
@@ -73,7 +72,7 @@ impl Builder<()> {
7372 #[ cfg( feature = "sync" ) ]
7473 sync_protocol: Default :: default ( ) ,
7574 #[ cfg( feature = "sync" ) ]
76- remote_encryption,
75+ remote_encryption: None
7776 } ,
7877 }
7978 }
@@ -98,7 +97,6 @@ impl Builder<()> {
9897 path: impl AsRef <std:: path:: Path >,
9998 url: String ,
10099 auth_token: String ,
101- remote_encryption: Option <EncryptionContext >,
102100 ) -> Builder <SyncedDatabase > {
103101 Builder {
104102 inner: SyncedDatabase {
@@ -110,13 +108,14 @@ impl Builder<()> {
110108 connector: None ,
111109 version: None ,
112110 namespace: None ,
111+ remote_encryption: None ,
113112 } ,
114113 connector: None ,
115114 read_your_writes: true ,
116115 remote_writes: false ,
117116 push_batch_size: 0 ,
118117 sync_interval: None ,
119- remote_encryption,
118+ remote_encryption: None ,
120119 } ,
121120 }
122121 }
@@ -132,6 +131,7 @@ impl Builder<()> {
132131 connector: None ,
133132 version: None ,
134133 namespace: None ,
134+ remote_encryption: None ,
135135 } ,
136136 }
137137 }
@@ -146,6 +146,7 @@ cfg_replication_or_remote_or_sync! {
146146 connector: Option <crate :: util:: ConnectorService >,
147147 version: Option <String >,
148148 namespace: Option <String >,
149+ remote_encryption: Option <EncryptionContext >,
149150 }
150151}
151152
@@ -238,7 +239,7 @@ cfg_replication! {
238239 #[ cfg( feature = "sync" ) ]
239240 sync_protocol: super :: SyncProtocol ,
240241 #[ cfg( feature = "sync" ) ]
241- remote_encryption: Option <crate :: sync :: EncryptionContext >,
242+ remote_encryption: Option <EncryptionContext >,
242243 }
243244
244245 /// Local replica configuration type in [`Builder`].
@@ -300,6 +301,13 @@ cfg_replication! {
300301 self
301302 }
302303
304+ /// Set the encryption context if the database is encrypted in remote server.
305+ #[ cfg( feature = "sync" ) ]
306+ pub fn remote_encryption( mut self , encryption_context: EncryptionContext ) -> Builder <RemoteReplica > {
307+ self . inner. remote_encryption = Some ( encryption_context) ;
308+ self
309+ }
310+
303311 pub fn http_request_callback<F >( mut self , f: F ) -> Builder <RemoteReplica >
304312 where
305313 F : Fn ( & mut http:: Request <( ) >) + Send + Sync + ' static
@@ -347,6 +355,7 @@ cfg_replication! {
347355 connector,
348356 version,
349357 namespace,
358+ ..
350359 } ,
351360 encryption_config,
352361 read_your_writes,
@@ -415,10 +424,11 @@ cfg_replication! {
415424
416425 if res. status( ) . is_success( ) {
417426 tracing:: trace!( "Using sync protocol v2 for {}" , url) ;
418- let builder = Builder :: new_synced_database( path, url, auth_token, remote_encryption )
427+ let builder = Builder :: new_synced_database( path, url, auth_token)
419428 . connector( connector)
420429 . remote_writes( true )
421- . read_your_writes( read_your_writes) ;
430+ . read_your_writes( read_your_writes)
431+ . remote_encryption( remote_encryption) ;
422432
423433 let builder = if let Some ( sync_interval) = sync_interval {
424434 builder. sync_interval( sync_interval)
@@ -475,7 +485,10 @@ cfg_replication! {
475485
476486
477487 Ok ( Database {
478- db_type: DbType :: Sync { db, encryption_config } ,
488+ db_type: DbType :: Sync {
489+ db,
490+ encryption_config,
491+ } ,
479492 max_write_replication_index: Default :: default ( ) ,
480493 } )
481494 }
@@ -515,6 +528,7 @@ cfg_replication! {
515528 connector,
516529 version,
517530 namespace,
531+ ..
518532 } ) = remote
519533 {
520534 let connector = if let Some ( connector) = connector {
@@ -565,7 +579,7 @@ cfg_sync! {
565579 read_your_writes: bool ,
566580 push_batch_size: u32 ,
567581 sync_interval: Option <std:: time:: Duration >,
568- remote_encryption: Option <crate :: sync :: EncryptionContext >,
582+ remote_encryption: Option <EncryptionContext >,
569583 }
570584
571585 impl Builder <SyncedDatabase > {
@@ -598,6 +612,12 @@ cfg_sync! {
598612 self
599613 }
600614
615+ /// Set the encryption context if the database is encrypted in remote server.
616+ pub fn remote_encryption( mut self , encryption_context: Option <EncryptionContext >) -> Builder <SyncedDatabase > {
617+ self . inner. remote_encryption = encryption_context;
618+ self
619+ }
620+
601621 /// Provide a custom http connector that will be used to create http connections.
602622 pub fn connector<C >( mut self , connector: C ) -> Builder <SyncedDatabase >
603623 where
@@ -624,6 +644,7 @@ cfg_sync! {
624644 connector: _,
625645 version: _,
626646 namespace: _,
647+ ..
627648 } ,
628649 connector,
629650 remote_writes,
@@ -759,6 +780,12 @@ cfg_remote! {
759780 self
760781 }
761782
783+ /// Set the encryption context if the database is encrypted in remote server.
784+ pub fn remote_encryption( mut self , encryption_context: EncryptionContext ) -> Builder <Remote > {
785+ self . inner. remote_encryption = Some ( encryption_context) ;
786+ self
787+ }
788+
762789 /// Build the remote database client.
763790 pub async fn build( self ) -> Result <Database > {
764791 let Remote {
@@ -767,6 +794,7 @@ cfg_remote! {
767794 connector,
768795 version,
769796 namespace,
797+ remote_encryption,
770798 } = self . inner;
771799
772800 let connector = if let Some ( connector) = connector {
@@ -789,6 +817,7 @@ cfg_remote! {
789817 connector,
790818 version,
791819 namespace,
820+ remote_encryption
792821 } ,
793822 max_write_replication_index: Default :: default ( ) ,
794823 } )
0 commit comments