pub struct RecvCipher { /* private fields */ }Expand description
Decrypts incoming messages with an auto-incrementing nonce.
Implementations§
Source§impl RecvCipher
impl RecvCipher
Sourcepub fn new(rng: impl CryptoRngCore) -> Self
pub fn new(rng: impl CryptoRngCore) -> Self
Creates a new receiving cipher with a random key.
Sourcepub fn recv_in_place(
&mut self,
encrypted_data: &mut [u8],
) -> Result<usize, Error>
pub fn recv_in_place( &mut self, encrypted_data: &mut [u8], ) -> Result<usize, Error>
Decrypts encrypted_data in-place and returns the plaintext length.
The buffer must contain ciphertext with the authentication tag appended
(last TAG_SIZE bytes). After decryption, the plaintext is in
encrypted_data[..returned_len].
§Errors
Returns an error if:
encrypted_data.len() < TAG_SIZE- Too many messages have been received with this cipher
- The ciphertext was corrupted or tampered with
In the last two cases, the RecvCipher will no longer be able to return
valid ciphertexts, and will always return an error on subsequent calls
to Self::recv. Terminating (and optionally reestablishing) the connection
is a simple (and safe) way to handle this scenario.
Sourcepub fn recv(&mut self, encrypted_data: &[u8]) -> Result<Vec<u8>, Error>
pub fn recv(&mut self, encrypted_data: &[u8]) -> Result<Vec<u8>, Error>
Decrypts ciphertext and returns the original data.
§Errors
This function will return an error in the following situations:
- Too many messages have been received with this cipher.
- The ciphertext was corrupted in some way.
In both cases, the RecvCipher will no longer be able to return
valid ciphertexts, and will always return an error on subsequent calls
to Self::recv. Terminating (and optionally reestablishing) the connection
is a simple (and safe) way to handle this scenario.
Auto Trait Implementations§
impl Freeze for RecvCipher
impl RefUnwindSafe for RecvCipher
impl Send for RecvCipher
impl Sync for RecvCipher
impl Unpin for RecvCipher
impl UnwindSafe for RecvCipher
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
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