Struct OpeningKey
pub struct OpeningKey<N>where
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§
§impl<N> OpeningKey<N>where
N: NonceSequence,
impl<N> OpeningKey<N>where
N: NonceSequence,
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>
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>
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.
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>
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>
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.
pub fn prepare_nonce(
&mut self,
) -> Result<OpeningKeyPreparedNonce<'_, N>, Unspecified>
pub fn prepare_nonce( &mut self, ) -> Result<OpeningKeyPreparedNonce<'_, N>, Unspecified>
Returns a OpeningKeyPreparedNonce containing the next computed Nonce consumed from NonceSequence.
The encapsulated Nonce will be used if and only if either
OpeningKeyPreparedNonce::open_in_place or OpeningKeyPreparedNonce::open_within
are invoked. Dropping OpeningKeyPreparedNonce without invoking either method results in the nonce remaining
consumed and unused within the associated NonceSequence. Subsequent calls to OpeningKey methods will
always use a proceeding nonce from the NonceSequence regardless of whether
a OpeningKeyPreparedNonce is consumed or not.
§Errors
Unspecified if there is a failure computing the nonce for the next operation, i.e. NonceSequence exhausted.
Trait Implementations§
§impl<N> BoundKey<N> for OpeningKey<N>where
N: NonceSequence,
impl<N> BoundKey<N> for OpeningKey<N>where
N: NonceSequence,
§fn new(key: UnboundKey, nonce_sequence: N) -> OpeningKey<N>
fn new(key: UnboundKey, nonce_sequence: N) -> OpeningKey<N>
UnboundKey and NonceSequence.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§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more