Skip to content

Commit 762360e

Browse files
committed
review updates
1 parent 2a81337 commit 762360e

File tree

6 files changed

+250
-228
lines changed

6 files changed

+250
-228
lines changed

src/client/csfle/client_encryption.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ pub struct ClientEncryption {
3232
key_vault: Collection<RawDocumentBuf>,
3333
}
3434

35-
impl std::fmt::Debug for ClientEncryption {
36-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37-
f.debug_struct("ClientEncryption").finish()
38-
}
39-
}
40-
4135
impl ClientEncryption {
4236
/// Create a new key vault handle with the given options.
4337
pub fn new(options: ClientEncryptionOptions) -> Result<Self> {
@@ -277,27 +271,6 @@ pub struct DataKeyOptions {
277271
pub key_material: Option<Vec<u8>>,
278272
}
279273

280-
impl<'de> Deserialize<'de> for DataKeyOptions {
281-
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
282-
where
283-
D: serde::Deserializer<'de>,
284-
{
285-
#[derive(Deserialize)]
286-
#[serde(rename_all = "camelCase")]
287-
struct Helper {
288-
master_key: Option<MasterKey>,
289-
key_alt_names: Option<Vec<String>>,
290-
key_material: Option<Binary>,
291-
}
292-
let h = Helper::deserialize(deserializer)?;
293-
Ok(DataKeyOptions {
294-
master_key: h.master_key.unwrap_or(MasterKey::Local),
295-
key_alt_names: h.key_alt_names,
296-
key_material: h.key_material.map(|bin| bin.bytes),
297-
})
298-
}
299-
}
300-
301274
/// A KMS-specific key used to encrypt data keys.
302275
#[serde_with::skip_serializing_none]
303276
#[derive(Debug, Clone, Serialize, Deserialize)]

src/test/spec/unified_runner/entity.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ pub(crate) enum Entity {
5050
None,
5151
}
5252

53+
#[cfg(feature = "csfle")]
54+
impl std::fmt::Debug for crate::client_encryption::ClientEncryption {
55+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56+
f.debug_struct("ClientEncryption").finish()
57+
}
58+
}
59+
5360
#[derive(Clone, Debug)]
5461
pub(crate) struct ClientEntity {
5562
client: Client,
@@ -205,7 +212,7 @@ impl ClientEntity {
205212
self.client.sync_workers().await;
206213
}
207214

208-
#[allow(dead_code)]
215+
#[cfg(feature = "csfle")]
209216
pub(crate) fn client(&self) -> &Client {
210217
&self.client
211218
}

src/test/spec/unified_runner/operation.rs

Lines changed: 5 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#[cfg(feature = "csfle")]
2+
mod csfle;
3+
#[cfg(feature = "csfle")]
4+
use self::csfle::*;
5+
16
use std::{
27
collections::HashMap,
38
convert::TryInto,
@@ -2792,189 +2797,6 @@ impl TestOperation for Upload {
27922797
}
27932798
}
27942799

2795-
#[cfg(feature = "csfle")]
2796-
#[derive(Debug, Deserialize)]
2797-
#[serde(rename_all = "camelCase", deny_unknown_fields)]
2798-
pub(super) struct GetKeyByAltName {
2799-
key_alt_name: String,
2800-
}
2801-
2802-
#[cfg(feature = "csfle")]
2803-
impl TestOperation for GetKeyByAltName {
2804-
fn execute_entity_operation<'a>(
2805-
&'a self,
2806-
id: &'a str,
2807-
test_runner: &'a TestRunner,
2808-
) -> BoxFuture<'a, Result<Option<Entity>>> {
2809-
async move {
2810-
let ce = test_runner.get_client_encryption(id).await;
2811-
let key = ce.get_key_by_alt_name(&self.key_alt_name).await?;
2812-
let ent = match key {
2813-
Some(rd) => Entity::Bson(Bson::Document(rd.to_document()?)),
2814-
None => Entity::None,
2815-
};
2816-
Ok(Some(ent))
2817-
}
2818-
.boxed()
2819-
}
2820-
}
2821-
2822-
#[cfg(feature = "csfle")]
2823-
#[derive(Debug, Deserialize)]
2824-
#[serde(rename_all = "camelCase", deny_unknown_fields)]
2825-
pub(super) struct DeleteKey {
2826-
id: bson::Binary,
2827-
}
2828-
2829-
#[cfg(feature = "csfle")]
2830-
impl TestOperation for DeleteKey {
2831-
fn execute_entity_operation<'a>(
2832-
&'a self,
2833-
id: &'a str,
2834-
test_runner: &'a TestRunner,
2835-
) -> BoxFuture<'a, Result<Option<Entity>>> {
2836-
async move {
2837-
let ce = test_runner.get_client_encryption(id).await;
2838-
let result = ce.delete_key(&self.id).await?;
2839-
Ok(Some(Entity::Bson(Bson::Document(bson::to_document(
2840-
&result,
2841-
)?))))
2842-
}
2843-
.boxed()
2844-
}
2845-
}
2846-
2847-
#[cfg(feature = "csfle")]
2848-
#[derive(Debug, Deserialize)]
2849-
#[serde(rename_all = "camelCase", deny_unknown_fields)]
2850-
pub(super) struct GetKey {
2851-
id: bson::Binary,
2852-
}
2853-
2854-
#[cfg(feature = "csfle")]
2855-
impl TestOperation for GetKey {
2856-
fn execute_entity_operation<'a>(
2857-
&'a self,
2858-
id: &'a str,
2859-
test_runner: &'a TestRunner,
2860-
) -> BoxFuture<'a, Result<Option<Entity>>> {
2861-
async move {
2862-
let ce = test_runner.get_client_encryption(id).await;
2863-
let entity = match ce.get_key(&self.id).await? {
2864-
Some(key) => Entity::Bson(Bson::Document(key.to_document()?)),
2865-
None => Entity::None,
2866-
};
2867-
Ok(Some(entity))
2868-
}
2869-
.boxed()
2870-
}
2871-
}
2872-
2873-
#[cfg(feature = "csfle")]
2874-
#[derive(Debug, Deserialize)]
2875-
#[serde(rename_all = "camelCase", deny_unknown_fields)]
2876-
pub(super) struct AddKeyAltName {
2877-
id: bson::Binary,
2878-
key_alt_name: String,
2879-
}
2880-
2881-
#[cfg(feature = "csfle")]
2882-
impl TestOperation for AddKeyAltName {
2883-
fn execute_entity_operation<'a>(
2884-
&'a self,
2885-
id: &'a str,
2886-
test_runner: &'a TestRunner,
2887-
) -> BoxFuture<'a, Result<Option<Entity>>> {
2888-
async move {
2889-
let ce = test_runner.get_client_encryption(id).await;
2890-
let entity = match ce.add_key_alt_name(&self.id, &self.key_alt_name).await? {
2891-
Some(key) => Entity::Bson(Bson::Document(key.to_document()?)),
2892-
None => Entity::None,
2893-
};
2894-
Ok(Some(entity))
2895-
}
2896-
.boxed()
2897-
}
2898-
}
2899-
2900-
#[cfg(feature = "csfle")]
2901-
#[derive(Debug, Deserialize)]
2902-
#[serde(rename_all = "camelCase", deny_unknown_fields)]
2903-
pub(super) struct CreateDataKey {
2904-
kms_provider: mongocrypt::ctx::KmsProvider,
2905-
opts: Option<crate::client_encryption::DataKeyOptions>,
2906-
}
2907-
2908-
#[cfg(feature = "csfle")]
2909-
impl TestOperation for CreateDataKey {
2910-
fn execute_entity_operation<'a>(
2911-
&'a self,
2912-
id: &'a str,
2913-
test_runner: &'a TestRunner,
2914-
) -> BoxFuture<'a, Result<Option<Entity>>> {
2915-
async move {
2916-
let ce = test_runner.get_client_encryption(id).await;
2917-
let key = ce
2918-
.create_data_key(&self.kms_provider, self.opts.clone())
2919-
.await?;
2920-
Ok(Some(Entity::Bson(Bson::Binary(key))))
2921-
}
2922-
.boxed()
2923-
}
2924-
}
2925-
2926-
#[cfg(feature = "csfle")]
2927-
#[derive(Debug, Deserialize)]
2928-
#[serde(rename_all = "camelCase", deny_unknown_fields)]
2929-
pub(super) struct GetKeys {}
2930-
2931-
#[cfg(feature = "csfle")]
2932-
impl TestOperation for GetKeys {
2933-
fn execute_entity_operation<'a>(
2934-
&'a self,
2935-
id: &'a str,
2936-
test_runner: &'a TestRunner,
2937-
) -> BoxFuture<'a, Result<Option<Entity>>> {
2938-
async move {
2939-
let ce = test_runner.get_client_encryption(id).await;
2940-
let mut cursor = ce.get_keys().await?;
2941-
let mut keys = vec![];
2942-
while let Some(key) = cursor.try_next().await? {
2943-
keys.push(Bson::Document(key.to_document()?));
2944-
}
2945-
Ok(Some(Entity::Bson(Bson::Array(keys))))
2946-
}
2947-
.boxed()
2948-
}
2949-
}
2950-
2951-
#[cfg(feature = "csfle")]
2952-
#[derive(Debug, Deserialize)]
2953-
#[serde(rename_all = "camelCase", deny_unknown_fields)]
2954-
pub(super) struct RemoveKeyAltName {
2955-
id: bson::Binary,
2956-
key_alt_name: String,
2957-
}
2958-
2959-
#[cfg(feature = "csfle")]
2960-
impl TestOperation for RemoveKeyAltName {
2961-
fn execute_entity_operation<'a>(
2962-
&'a self,
2963-
id: &'a str,
2964-
test_runner: &'a TestRunner,
2965-
) -> BoxFuture<'a, Result<Option<Entity>>> {
2966-
async move {
2967-
let ce = test_runner.get_client_encryption(id).await;
2968-
let entity = match ce.remove_key_alt_name(&self.id, &self.key_alt_name).await? {
2969-
Some(key) => Entity::Bson(Bson::Document(key.to_document()?)),
2970-
None => Entity::None,
2971-
};
2972-
Ok(Some(entity))
2973-
}
2974-
.boxed()
2975-
}
2976-
}
2977-
29782800
#[derive(Debug, Deserialize)]
29792801
pub(super) struct UnimplementedOperation {
29802802
_name: String,

0 commit comments

Comments
 (0)