use std::fmt::Debug;
use macro_magic::export_tokens;
use crate::{
action::{deeplink, export_doc, option_setters, options_doc},
client_encryption::{ClientEncryption, MasterKey},
};
impl ClientEncryption {
#[deeplink]
#[options_doc(create_data_keys)]
pub fn create_data_key(&self, master_key: impl Into<MasterKey>) -> CreateDataKey<'_> {
CreateDataKey {
client_enc: self,
master_key: master_key.into(),
options: None,
#[cfg(test)]
test_kms_provider: None,
}
}
}
#[must_use]
pub struct CreateDataKey<'a> {
pub(crate) client_enc: &'a ClientEncryption,
pub(crate) master_key: MasterKey,
pub(crate) options: Option<DataKeyOptions>,
#[cfg(test)]
pub(crate) test_kms_provider: Option<mongocrypt::ctx::KmsProvider>,
}
#[derive(Clone, Default)]
#[non_exhaustive]
#[export_tokens]
pub struct DataKeyOptions {
pub key_alt_names: Option<Vec<String>>,
pub key_material: Option<Vec<u8>>,
}
impl Debug for DataKeyOptions {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let DataKeyOptions {
key_alt_names,
key_material,
} = self;
f.debug_struct("DataKeyOptions")
.field("key_alt_names", key_alt_names)
.field(
"key_material",
&key_material.is_some().then_some("REDACTED"),
)
.finish()
}
}
#[option_setters(DataKeyOptions)]
#[export_doc(create_data_keys)]
impl CreateDataKey<'_> {
#[cfg(test)]
pub(crate) fn test_kms_provider(mut self, value: mongocrypt::ctx::KmsProvider) -> Self {
self.test_kms_provider = Some(value);
self
}
}