quantcrypt::content

Struct AuthEnvelopedDataContent

source
pub struct AuthEnvelopedDataContent { /* private fields */ }
Expand description

Main interaction point for the AuthEnvelopedData content

This struct is used to create, read and manipulate AuthEnvelopedData content

§Example

use quantcrypt::content::AuthEnvelopedDataContent;
use quantcrypt::content::ContentEncryptionAlgorithmAead;
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 recipient_cert = Certificate::from_file(
    "test/data/cms_cw/1.3.6.1.4.1.22554.5.6.1_ML-KEM-512-ipd_ee.der",
)
.unwrap();

let private_key = PrivateKey::from_file(
    "test/data/cms_cw/1.3.6.1.4.1.22554.5.6.1_ML-KEM-512-ipd_priv.der",
)
.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 =
    AuthEnvelopedDataContent::get_builder(ContentEncryptionAlgorithmAead::Aes256Gcm).unwrap();

builder
    .kem_recipient(
        &recipient_cert,
        &KdfType::HkdfWithSha256,
        &WrapType::Aes256,
        Some(ukm),
    )
    .unwrap()
    .content(data)
    .unwrap()
    .auth_attribute(&attribute)
    .unwrap();
     

let content = builder.build().unwrap();
// Now use this content to create a new EnvelopedDataContent
let edc = AuthEnvelopedDataContent::from_bytes_for_kem_recipient(
    &content,
    &recipient_cert,
    &private_key,
)
.unwrap();
assert_eq!(edc.get_content(), data);

Implementations§

source§

impl AuthEnvelopedDataContent

source

pub fn from_file_for_kem_recipient( file: &str, recipient_cert: &Certificate, recipient_private_key: &PrivateKey, ) -> Result<AuthEnvelopedDataContent, QuantCryptError>

Load a AuthEnvelopedDataContent from a file. The content is wrapped in a ContentInfo object. The content is decrypted using the provided recipient certificate and private key.

§Arguments
  • file - The file to read the content from
  • recipient_cert - The recipient certificate
  • recipient_private_key - The recipient private key
§Returns

The AuthEnvelopedDataContent object

source

pub fn from_bytes_for_kem_recipient( data: &[u8], recipient_cert: &Certificate, recipient_private_key: &PrivateKey, ) -> Result<AuthEnvelopedDataContent, QuantCryptError>

Load a AuthEnvelopedDataContent from a byte array. The content is wrapped in a ContentInfo object. The content is decrypted using the provided recipient certificate and private key.

§Arguments
  • data - The byte array to read the content from
  • recipient_cert - The recipient certificate
  • recipient_private_key - The recipient private key
§Returns

The AuthEnvelopedDataContent object

source

pub fn get_version(&self) -> CmsVersion

Get the CmsVersion

source

pub fn get_originator_info(&self) -> Option<OriginatorInfo>

Get the OriginatorInfo

source

pub fn get_content(&self) -> Vec<u8>

Get the content

source

pub fn get_unprotected_attrs(&self) -> Option<Attributes>

Get the unprotected attributes

source

pub fn get_auth_attrs(&self) -> Option<Attributes>

Get the authenticated attributes

source

pub fn get_recipient_infos(&self) -> RecipientInfos

Get the RecipientInfos

source

pub fn get_builder( content_encryption_alg: ContentEncryptionAlgorithmAead, ) -> Result<EnvelopedDataBuilder<'static>, QuantCryptError>

Get a builder for the AuthEnvelopedDataContent. This is used to create new AuthEnvelopedDataContent objects

§Arguments
  • content_encryption_alg - The content encryption algorithm
§Returns

The AuthEnvelopedDataContent builder

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V