// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // Copyright by contributors to this project. // SPDX-License-Identifier: (Apache-2.0 OR MIT)
use mls_rs_core::{
crypto::{HpkeContextR, HpkeContextS},
error::IntoAnyError,
}; use mls_rs_crypto_traits::{AeadType, KdfType};
usecrate::{hpke::HpkeError, kdf::HpkeKdf};
use alloc::vec::Vec; use core::fmt::{self, Debug};
/// A type representing an HPKE context #[derive(Clone)] pub(super) struct Context<KDF: KdfType, AEAD: AeadType> {
exporter_secret: Vec<u8>,
encryption_context: Option<EncryptionContext<AEAD>>,
kdf: HpkeKdf<KDF>,
}
/// # Errors /// /// Returns [SequenceNumberOverflow](HpkeError::SequenceNumberOverflow) /// in the event that the sequence number overflows. The sequence number is a u64 and starts /// at 0. asyncfn seal(&mutself, aad: Option<&[u8]>, data: &[u8]) -> Result<Vec<u8>, Self::Error> { self.0.seal(aad, data).await
}
}
/// # Errors /// /// Returns [SequenceNumberOverflow](HpkeError::SequenceNumberOverflow) /// in the event that the sequence number overflows. The sequence number is a u64 and starts /// at 0. /// /// Returns [AeadError](HpkeError::AeadError) if decryption fails due to either an invalid /// `aad` value, or incorrect cipher key. asyncfn open(
&mutself,
aad: Option<&[u8]>,
ciphertext: &[u8],
) -> Result<Vec<u8>, Self::Error> { self.0.open(aad, ciphertext).await
}
}
// XOR the sequence number into the last 4 bytes of the nonce
nonce
.iter_mut()
.rev()
.zip(self.seq_number.to_le_bytes())
.for_each(|(n, s)| *n ^= s);
nonce
}
#[inline] fn increment_seq(&mutself) -> Result<(), HpkeError> { // If the sequence number is going to roll over just throw an error self.seq_number = self
.seq_number
.checked_add(1)
.ok_or(HpkeError::SequenceNumberOverflow)?;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.