pub struct EnvelopedDataContent { /* private fields */ }Expand description
Main interaction point for the EnvelopedData content
This struct is used to create, read and manipulate EnvelopedData content
§Example
use quantcrypt::content::EnvelopedDataContent;
use quantcrypt::content::ContentEncryptionAlgorithm;
use quantcrypt::certificates::Certificate;
use quantcrypt::keys::PrivateKey;
use quantcrypt::kdfs::KdfType;
use quantcrypt::wraps::WrapType;
use quantcrypt::content::UserKeyingMaterial;
use quantcrypt::content::ObjectIdentifier;
use quantcrypt::content::Attribute;
use quantcrypt::content::Tag;
use quantcrypt::content::AttributeValue;
use quantcrypt::content::SetOfVec;
let rc_filename = if quantcrypt::is_ipd_mode_enabled() {
"test/data_ipd/cms_cw/1.3.6.1.4.1.22554.5.6.1_ML-KEM-512-ipd_ee.der"
} else {
"test/data/cms/2.16.840.1.101.3.4.4.1_MlKem512_ee.der"
};
let recipient_cert = Certificate::from_file(
rc_filename,
).unwrap();
let sk_filename = if quantcrypt::is_ipd_mode_enabled() {
"test/data_ipd/cms_cw/1.3.6.1.4.1.22554.5.6.1_ML-KEM-512-ipd_priv.der"
} else {
"test/data/cms/2.16.840.1.101.3.4.4.1_MlKem512_priv.der"
};
let private_key = PrivateKey::from_file(
sk_filename
).unwrap();
let ukm = UserKeyingMaterial::new("test".as_bytes()).unwrap();
let data = b"abc";
let attribute_oid = ObjectIdentifier::new("1.3.6.1.4.1.22554.5.6").unwrap();
let mut attribute_vals: SetOfVec<AttributeValue> = SetOfVec::<AttributeValue>::new();
let attr_val = AttributeValue::new(Tag::OctetString, data.to_vec()).unwrap();
attribute_vals.insert(attr_val).unwrap();
let attribute = Attribute {
oid: attribute_oid,
values: attribute_vals,
};
let mut builder =
EnvelopedDataContent::get_builder(ContentEncryptionAlgorithm::Aes128Cbc).unwrap();
builder
.kem_recipient(
&recipient_cert,
&KdfType::HkdfWithSha256,
&WrapType::Aes256,
Some(ukm),
)
.unwrap()
.content(data)
.unwrap()
.unprotected_attribute(&attribute)
.unwrap();
let content = builder.build().unwrap();
// Now use this content to create a new EnvelopedDataContent
let edc = EnvelopedDataContent::from_bytes_for_kem_recipient(
&content,
&recipient_cert,
&private_key,
)
.unwrap();
assert_eq!(edc.get_content(), data);Implementations§
Source§impl EnvelopedDataContent
impl EnvelopedDataContent
Sourcepub fn from_file_for_kem_recipient(
file: &str,
recipient_cert: &Certificate,
recipient_private_key: &PrivateKey,
) -> Result<EnvelopedDataContent, QuantCryptError>
pub fn from_file_for_kem_recipient( file: &str, recipient_cert: &Certificate, recipient_private_key: &PrivateKey, ) -> Result<EnvelopedDataContent, QuantCryptError>
Create a new EnvelopedDataContent object from a file. The encrypted content is wrapped in a ContentInfo object and the file contains the DER encoded bytes of the ContentInfo object.
§Arguments
file- The file path to read the EnvelopedData content fromrecipient_cert- The recipient certificaterecipient_private_key- The recipient private key
§Returns
A new EnvelopedDataContent object
Sourcepub fn from_bytes_for_kem_recipient(
data: &[u8],
recipient_cert: &Certificate,
recipient_private_key: &PrivateKey,
) -> Result<EnvelopedDataContent, QuantCryptError>
pub fn from_bytes_for_kem_recipient( data: &[u8], recipient_cert: &Certificate, recipient_private_key: &PrivateKey, ) -> Result<EnvelopedDataContent, QuantCryptError>
Create a new EnvelopedDataContent object from bytes. The encrypted content is wrapped in a ContentInfo object and the data is the DER encoded bytes of the ContentInfo object.
§Arguments
data- The bytes to read the EnvelopedData content fromrecipient_cert- The recipient certificaterecipient_private_key- The recipient private key
§Returns
A new EnvelopedDataContent object
Sourcepub fn get_version(&self) -> CmsVersion
pub fn get_version(&self) -> CmsVersion
Get the version of the EnvelopedData Cms content
Sourcepub fn get_originator_info(&self) -> Option<OriginatorInfo>
pub fn get_originator_info(&self) -> Option<OriginatorInfo>
Get the originator info
Sourcepub fn get_content(&self) -> Vec<u8> ⓘ
pub fn get_content(&self) -> Vec<u8> ⓘ
Get the content
Sourcepub fn get_unprotected_attrs(&self) -> Option<Attributes>
pub fn get_unprotected_attrs(&self) -> Option<Attributes>
Get the unprotected attributes
Sourcepub fn get_recipient_infos(&self) -> RecipientInfos
pub fn get_recipient_infos(&self) -> RecipientInfos
Get the recipient infos
Sourcepub fn get_builder(
content_encryption_alg: ContentEncryptionAlgorithm,
) -> Result<EnvelopedDataBuilder<'static>, QuantCryptError>
pub fn get_builder( content_encryption_alg: ContentEncryptionAlgorithm, ) -> Result<EnvelopedDataBuilder<'static>, QuantCryptError>
Auto Trait Implementations§
impl Freeze for EnvelopedDataContent
impl RefUnwindSafe for EnvelopedDataContent
impl Send for EnvelopedDataContent
impl Sync for EnvelopedDataContent
impl Unpin for EnvelopedDataContent
impl UnsafeUnpin for EnvelopedDataContent
impl UnwindSafe for EnvelopedDataContent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more