Skip to content

Commit 6a8ac8e

Browse files
authored
RUST-1385 Implement explicit encryption (#726)
1 parent ea42b65 commit 6a8ac8e

File tree

7 files changed

+476
-44
lines changed

7 files changed

+476
-44
lines changed

src/client/csfle.rs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod client_encryption;
12
pub mod options;
23
mod state_machine;
34

@@ -8,7 +9,6 @@ use std::{
89

910
use derivative::Derivative;
1011
use mongocrypt::Crypt;
11-
use rayon::ThreadPool;
1212

1313
use crate::{
1414
error::{Error, Result},
@@ -26,46 +26,55 @@ use options::{
2626
EO_MONGOCRYPTD_URI,
2727
};
2828

29+
use self::state_machine::CryptExecutor;
30+
2931
use super::WeakClient;
3032

3133
#[derive(Derivative)]
3234
#[derivative(Debug)]
3335
pub(super) struct ClientState {
3436
#[derivative(Debug = "ignore")]
35-
pub(crate) crypt: Crypt,
36-
mongocryptd_client: Option<Client>,
37-
aux_clients: AuxClients,
37+
crypt: Crypt,
38+
exec: CryptExecutor,
39+
internal_client: Option<Client>,
3840
opts: AutoEncryptionOptions,
39-
crypto_threads: ThreadPool,
4041
}
4142

42-
#[derive(Debug)]
4343
struct AuxClients {
4444
key_vault_client: WeakClient,
4545
metadata_client: Option<WeakClient>,
46-
_internal_client: Option<Client>,
46+
internal_client: Option<Client>,
4747
}
4848

4949
impl ClientState {
50-
pub(super) async fn new(client: &Client, opts: AutoEncryptionOptions) -> Result<Self> {
50+
pub(super) async fn new(client: &Client, mut opts: AutoEncryptionOptions) -> Result<Self> {
5151
let crypt = Self::make_crypt(&opts)?;
5252
let mongocryptd_client = Self::spawn_mongocryptd_if_needed(&opts, &crypt).await?;
5353
let aux_clients = Self::make_aux_clients(client, &opts)?;
54-
let num_cpus = std::thread::available_parallelism()?.get();
55-
let crypto_threads = rayon::ThreadPoolBuilder::new()
56-
.num_threads(num_cpus)
57-
.build()
58-
.map_err(|e| Error::internal(format!("could not initialize thread pool: {}", e)))?;
54+
let exec = CryptExecutor::new(
55+
aux_clients.key_vault_client,
56+
opts.key_vault_namespace.clone(),
57+
mongocryptd_client,
58+
aux_clients.metadata_client,
59+
opts.tls_options.take(),
60+
)?;
5961

6062
Ok(Self {
6163
crypt,
62-
mongocryptd_client,
63-
aux_clients,
64+
exec,
65+
internal_client: aux_clients.internal_client,
6466
opts,
65-
crypto_threads,
6667
})
6768
}
6869

70+
pub(super) fn crypt(&self) -> &Crypt {
71+
&self.crypt
72+
}
73+
74+
pub(super) fn exec(&self) -> &CryptExecutor {
75+
&self.exec
76+
}
77+
6978
pub(super) fn opts(&self) -> &AutoEncryptionOptions {
7079
&self.opts
7180
}
@@ -176,7 +185,7 @@ impl ClientState {
176185
Ok(AuxClients {
177186
key_vault_client,
178187
metadata_client,
179-
_internal_client: internal_client,
188+
internal_client,
180189
})
181190
}
182191
}

0 commit comments

Comments
 (0)