aws_lc_rs::aead

Struct OpeningKey

Source
pub struct OpeningKey<N: NonceSequence> { /* private fields */ }
Expand description

An AEAD key for authenticating and decrypting (“opening”), bound to a nonce sequence.

Intentionally not Clone or Copy since cloning would allow duplication of the nonce sequence.

Prefer RandomizedNonceKey for opening operations.

Implementations§

Source§

impl<N: NonceSequence> OpeningKey<N>

Source

pub fn open_in_place<'in_out, A>( &mut self, aad: Aad<A>, in_out: &'in_out mut [u8], ) -> Result<&'in_out mut [u8], Unspecified>
where A: AsRef<[u8]>,

Authenticates and decrypts (“opens”) data in place.

aad is the additional authenticated data (AAD), if any.

On input, in_out must be the ciphertext followed by the tag. When open_in_place() returns Ok(plaintext), the input ciphertext has been overwritten by the plaintext; plaintext will refer to the plaintext without the tag.

Prefer RandomizedNonceKey::open_in_place.

§Errors

error::Unspecified when ciphertext is invalid. In this case, in_out may have been overwritten in an unspecified way.

Source

pub fn open_within<'in_out, A>( &mut self, aad: Aad<A>, in_out: &'in_out mut [u8], ciphertext_and_tag: RangeFrom<usize>, ) -> Result<&'in_out mut [u8], Unspecified>
where A: AsRef<[u8]>,

Authenticates and decrypts (“opens”) data in place, with a shift.

aad is the additional authenticated data (AAD), if any.

On input, in_out[ciphertext_and_tag] must be the ciphertext followed by the tag. When open_within() returns Ok(plaintext), the plaintext will be at in_out[0..plaintext.len()]. In other words, the following two code fragments are equivalent for valid values of ciphertext_and_tag, except open_within will often be more efficient:

let plaintext = key.open_within(aad, in_out, cipertext_and_tag)?;
let ciphertext_and_tag_len = in_out[ciphertext_and_tag].len();
in_out.copy_within(ciphertext_and_tag, 0);
let plaintext = key.open_in_place(aad, &mut in_out[..ciphertext_and_tag_len])?;

Similarly, key.open_within(aad, in_out, 0..) is equivalent to key.open_in_place(aad, in_out).

The shifting feature is useful in the case where multiple packets are being reassembled in place. Consider this example where the peer has sent the message “Split stream reassembled in place” split into three sealed packets:

                Packet 1                  Packet 2                 Packet 3
Input:  [Header][Ciphertext][Tag][Header][Ciphertext][Tag][Header][Ciphertext][Tag]
                     |         +--------------+                        |
              +------+   +-----+    +----------------------------------+
              v          v          v
Output: [Plaintext][Plaintext][Plaintext]
       “Split stream reassembled in place”

This reassembly be accomplished with three calls to open_within().

Prefer RandomizedNonceKey::open_in_place.

§Errors

error::Unspecified when ciphertext is invalid. In this case, in_out may have been overwritten in an unspecified way.

Trait Implementations§

Source§

impl<N: NonceSequence> BoundKey<N> for OpeningKey<N>

Source§

fn new(key: UnboundKey, nonce_sequence: N) -> Self

Constructs a new key from the given UnboundKey and NonceSequence.
Source§

fn algorithm(&self) -> &'static Algorithm

The key’s AEAD algorithm.
Source§

impl<N: NonceSequence> Debug for OpeningKey<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<N> Freeze for OpeningKey<N>
where N: Freeze,

§

impl<N> RefUnwindSafe for OpeningKey<N>
where N: RefUnwindSafe,

§

impl<N> Send for OpeningKey<N>
where N: Send,

§

impl<N> Sync for OpeningKey<N>
where N: Sync,

§

impl<N> Unpin for OpeningKey<N>
where N: Unpin,

§

impl<N> UnwindSafe for OpeningKey<N>
where N: UnwindSafe,

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, 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.