pub struct AeadEnvelope<Algorithm: AeadAlgorithm, Nonce, Mac, Data> { /* private fields */ }Expand description
Authenticated encrypted data with its nonce stored alongside it.
The byte representation for the supported algorithms is
nonce || ciphertext || tag.
Implementations§
Source§impl<Nonce: NewByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES> + Zeroize, Mac: NewByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_ABYTES> + Zeroize, Data: NewBytes + ResizableBytes + Zeroize> AeadEnvelope<XChaCha20Poly1305Ietf, Nonce, Mac, Data>
impl<Nonce: NewByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES> + Zeroize, Mac: NewByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_ABYTES> + Zeroize, Data: NewBytes + ResizableBytes + Zeroize> AeadEnvelope<XChaCha20Poly1305Ietf, Nonce, Mac, Data>
Sourcepub fn seal<Message: Bytes + ?Sized, SecretKey: ByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES>>(
message: &Message,
associated_data: Option<&[u8]>,
key: &SecretKey,
) -> Result<Self, Error>
pub fn seal<Message: Bytes + ?Sized, SecretKey: ByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES>>( message: &Message, associated_data: Option<&[u8]>, key: &SecretKey, ) -> Result<Self, Error>
Encrypts a message with a generated nonce and stores that nonce with the ciphertext and tag.
§Errors
Returns an error if the message exceeds the construction’s maximum length or the output storage does not resize to the message length.
§Panics
Panics if the operating system’s random number generator fails.
Source§impl<'a, Nonce: ByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES> + TryFrom<&'a [u8]> + Zeroize, Mac: ByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_ABYTES> + TryFrom<&'a [u8]> + Zeroize, Data: Bytes + From<&'a [u8]> + Zeroize> AeadEnvelope<XChaCha20Poly1305Ietf, Nonce, Mac, Data>
impl<'a, Nonce: ByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES> + TryFrom<&'a [u8]> + Zeroize, Mac: ByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_ABYTES> + TryFrom<&'a [u8]> + Zeroize, Data: Bytes + From<&'a [u8]> + Zeroize> AeadEnvelope<XChaCha20Poly1305Ietf, Nonce, Mac, Data>
Sourcepub fn from_bytes(bytes: &'a [u8]) -> Result<Self, Error>
pub fn from_bytes(bytes: &'a [u8]) -> Result<Self, Error>
Initializes an AeadEnvelope from nonce || ciphertext || tag.
§Errors
Returns an error if bytes is shorter than one nonce plus one
authentication tag, or if either field cannot be converted to its
target type.
Source§impl<'a, Nonce: ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES> + TryFrom<&'a [u8]> + Zeroize, Mac: ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES> + TryFrom<&'a [u8]> + Zeroize, Data: Bytes + From<&'a [u8]> + Zeroize> AeadEnvelope<ChaCha20Poly1305Ietf, Nonce, Mac, Data>
impl<'a, Nonce: ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES> + TryFrom<&'a [u8]> + Zeroize, Mac: ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES> + TryFrom<&'a [u8]> + Zeroize, Data: Bytes + From<&'a [u8]> + Zeroize> AeadEnvelope<ChaCha20Poly1305Ietf, Nonce, Mac, Data>
Sourcepub fn from_bytes(bytes: &'a [u8]) -> Result<Self, Error>
pub fn from_bytes(bytes: &'a [u8]) -> Result<Self, Error>
Initializes an AeadEnvelope from nonce || ciphertext || tag.
§Errors
Returns an error if bytes is shorter than one nonce plus one
authentication tag, or if either field cannot be converted to its
target type.
Source§impl<Nonce: ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES>, Mac: ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES>, Data: Bytes> AeadEnvelope<ChaCha20Poly1305Ietf, Nonce, Mac, Data>
impl<Nonce: ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES>, Mac: ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES>, Data: Bytes> AeadEnvelope<ChaCha20Poly1305Ietf, Nonce, Mac, Data>
Sourcepub fn open<Output: ResizableBytes + NewBytes, SecretKey: ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES>>(
&self,
associated_data: Option<&[u8]>,
key: &SecretKey,
) -> Result<Output, Error>
pub fn open<Output: ResizableBytes + NewBytes, SecretKey: ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES>>( &self, associated_data: Option<&[u8]>, key: &SecretKey, ) -> Result<Output, Error>
Decrypts this envelope using key and optional associated data.
§Errors
Returns an error if the ciphertext exceeds the construction’s maximum length, the output storage has the wrong length, or authentication fails. Authentication fails when the key, associated data, stored nonce, ciphertext, or tag does not match the value used during encryption.
Source§impl AeadEnvelope<ChaCha20Poly1305Ietf, Nonce, Mac, Vec<u8>>
impl AeadEnvelope<ChaCha20Poly1305Ietf, Nonce, Mac, Vec<u8>>
Sourcepub fn open_to_vec<SecretKey: ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES>>(
&self,
associated_data: Option<&[u8]>,
key: &SecretKey,
) -> Result<Vec<u8>, Error>
pub fn open_to_vec<SecretKey: ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES>>( &self, associated_data: Option<&[u8]>, key: &SecretKey, ) -> Result<Vec<u8>, Error>
Source§impl<Algorithm: AeadAlgorithm, Nonce, Mac, Data> AeadEnvelope<Algorithm, Nonce, Mac, Data>
impl<Algorithm: AeadAlgorithm, Nonce, Mac, Data> AeadEnvelope<Algorithm, Nonce, Mac, Data>
Sourcepub fn from_parts(nonce: Nonce, tag: Mac, data: Data) -> Self
pub fn from_parts(nonce: Nonce, tag: Mac, data: Data) -> Self
Returns a new AEAD envelope from nonce, tag, and ciphertext data.
Sourcepub fn into_parts(self) -> (Nonce, Mac, Data)
pub fn into_parts(self) -> (Nonce, Mac, Data)
Moves the nonce, tag, and ciphertext out of this instance.
Source§impl<Algorithm: AeadAlgorithm, Nonce: Bytes, Mac: Bytes, Data: Bytes> AeadEnvelope<Algorithm, Nonce, Mac, Data>
impl<Algorithm: AeadAlgorithm, Nonce: Bytes, Mac: Bytes, Data: Bytes> AeadEnvelope<Algorithm, Nonce, Mac, Data>
Source§impl<Nonce: ByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES>, Mac: ByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_ABYTES>, Data: Bytes> AeadEnvelope<XChaCha20Poly1305Ietf, Nonce, Mac, Data>
impl<Nonce: ByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES>, Mac: ByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_ABYTES>, Data: Bytes> AeadEnvelope<XChaCha20Poly1305Ietf, Nonce, Mac, Data>
Sourcepub fn open<Output: ResizableBytes + NewBytes, SecretKey: ByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES>>(
&self,
associated_data: Option<&[u8]>,
key: &SecretKey,
) -> Result<Output, Error>
pub fn open<Output: ResizableBytes + NewBytes, SecretKey: ByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES>>( &self, associated_data: Option<&[u8]>, key: &SecretKey, ) -> Result<Output, Error>
Decrypts this envelope using key and optional associated data.
§Errors
Returns an error if the ciphertext exceeds the construction’s maximum length, the output storage has the wrong length, or authentication fails. Authentication fails when the key, associated data, stored nonce, ciphertext, or tag does not match the value used during encryption.
Source§impl AeadEnvelope<XChaCha20Poly1305Ietf, StackByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES>, StackByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_ABYTES>, Vec<u8>>
impl AeadEnvelope<XChaCha20Poly1305Ietf, StackByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES>, StackByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_ABYTES>, Vec<u8>>
Sourcepub fn seal_to_vec<Message: Bytes + ?Sized, SecretKey: ByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES>>(
message: &Message,
associated_data: Option<&[u8]>,
key: &SecretKey,
) -> Result<Self, Error>
pub fn seal_to_vec<Message: Bytes + ?Sized, SecretKey: ByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES>>( message: &Message, associated_data: Option<&[u8]>, key: &SecretKey, ) -> Result<Self, Error>
Encrypts a message with a generated nonce and returns a VecEnvelope.
§Errors
Returns an error if the message exceeds the construction’s maximum length.
§Panics
Panics if the operating system’s random number generator fails.
Sourcepub fn open_to_vec<SecretKey: ByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES>>(
&self,
associated_data: Option<&[u8]>,
key: &SecretKey,
) -> Result<Vec<u8>, Error>
pub fn open_to_vec<SecretKey: ByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES>>( &self, associated_data: Option<&[u8]>, key: &SecretKey, ) -> Result<Vec<u8>, Error>
Source§impl<'a, Algorithm: AeadAlgorithm, Nonce, Mac, Data: From<&'a [u8]>> AeadEnvelope<Algorithm, Nonce, Mac, Data>
impl<'a, Algorithm: AeadAlgorithm, Nonce, Mac, Data: From<&'a [u8]>> AeadEnvelope<Algorithm, Nonce, Mac, Data>
Sourcepub fn with_nonce_data_and_mac(nonce: Nonce, tag: Mac, input: &'a [u8]) -> Self
pub fn with_nonce_data_and_mac(nonce: Nonce, tag: Mac, input: &'a [u8]) -> Self
Returns a new envelope with nonce and tag consumed and ciphertext copied
from input.
Trait Implementations§
Source§impl<Algorithm: Clone + AeadAlgorithm, Nonce: Clone, Mac: Clone, Data: Clone> Clone for AeadEnvelope<Algorithm, Nonce, Mac, Data>
impl<Algorithm: Clone + AeadAlgorithm, Nonce: Clone, Mac: Clone, Data: Clone> Clone for AeadEnvelope<Algorithm, Nonce, Mac, Data>
Source§fn clone(&self) -> AeadEnvelope<Algorithm, Nonce, Mac, Data>
fn clone(&self) -> AeadEnvelope<Algorithm, Nonce, Mac, Data>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more