Skip to main content

AeadEnvelope

Struct AeadEnvelope 

Source
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<'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>

Source

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_XCHACHA20POLY1305_IETF_NPUBBYTES>, Mac: ByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_ABYTES>, Data: Bytes> AeadEnvelope<XChaCha20Poly1305Ietf, Nonce, Mac, Data>

Source

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

Source

pub fn open_to_vec<SecretKey: ByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES>>( &self, associated_data: Option<&[u8]>, key: &SecretKey, ) -> Result<Vec<u8>, Error>

Available on crate feature alloc only.

Decrypts this envelope and returns the plaintext as a Vec.

§Errors

Returns an error if the ciphertext exceeds the construction’s maximum length or authentication fails because the key, associated data, stored nonce, ciphertext, or tag does not match.

Source

pub fn into_vec(self) -> Vec<u8> ⓘ

Available on crate feature alloc only.

Consumes this envelope and returns it as nonce || ciphertext || tag.

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>

Source

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 AeadEnvelope<XChaCha20Poly1305Ietf, StackByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES>, StackByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_ABYTES>, Vec<u8>>

Source

pub fn seal_to_vecbox<Message: Bytes + ?Sized, SecretKey: ByteArray<CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES>>( message: &Message, associated_data: Option<&[u8]>, key: &SecretKey, ) -> Result<Self, Error>

Available on crate feature alloc only.

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.

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>

Source

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>

Source

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, StackByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES>, StackByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES>, Vec<u8>>

Source

pub fn open_to_vec<SecretKey: ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES>>( &self, associated_data: Option<&[u8]>, key: &SecretKey, ) -> Result<Vec<u8>, Error>

Available on crate feature alloc only.

Decrypts this envelope and returns the plaintext as a Vec.

§Errors

Returns an error if the ciphertext exceeds the construction’s maximum length or authentication fails because the key, associated data, stored nonce, ciphertext, or tag does not match.

Source

pub fn into_vec(self) -> Vec<u8> ⓘ

Available on crate feature alloc only.

Consumes this envelope and returns it as nonce || ciphertext || tag.

Source§

impl<Algorithm: AeadAlgorithm, Nonce, Mac, Data> AeadEnvelope<Algorithm, Nonce, Mac, Data>

Source

pub fn from_parts(nonce: Nonce, tag: Mac, data: Data) -> Self

Returns a new AEAD envelope from nonce, tag, and ciphertext data.

Source

pub fn nonce(&self) -> &Nonce

Returns the stored nonce.

Source

pub fn tag(&self) -> &Mac

Returns the authentication tag.

Source

pub fn data(&self) -> &Data

Returns the ciphertext.

Source

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>

Source

pub fn to_vec(&self) -> Vec<u8> ⓘ

Available on crate feature alloc only.

Copies self into a new Vec.

Source

pub fn to_bytes<Output: NewBytes + ResizableBytes>(&self) -> Output

Copies self into the target as nonce || ciphertext || tag, where the nonce and tag are the first nonce-size and tag-size bytes of Nonce and Mac.

§Panics

Panics if the nonce or tag is shorter than the algorithm’s size.

Trait Implementations§

Source§

impl<Algorithm: Clone + AeadAlgorithm, Nonce: Clone, Mac: Clone, Data: Clone> Clone for AeadEnvelope<Algorithm, Nonce, Mac, Data>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Algorithm: Debug + AeadAlgorithm, Nonce: Debug, Mac: Debug, Data: Debug> Debug for AeadEnvelope<Algorithm, Nonce, Mac, Data>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de, Algorithm: AeadAlgorithm, Nonce, Mac, Data> Deserialize<'de> for AeadEnvelope<Algorithm, Nonce, Mac, Data>
where Nonce: Deserialize<'de>, Mac: Deserialize<'de>, Data: Deserialize<'de>,

Available on crate feature serde only.
Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<Algorithm: AeadAlgorithm, Nonce: Bytes, Mac: Bytes, Data: Bytes> PartialEq for AeadEnvelope<Algorithm, Nonce, Mac, Data>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<Algorithm: AeadAlgorithm, Nonce, Mac, Data> Serialize for AeadEnvelope<Algorithm, Nonce, Mac, Data>
where Nonce: Serialize, Mac: Serialize, Data: Serialize,

Available on crate feature serde only.
Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<Algorithm: AeadAlgorithm, Nonce: Zeroize, Mac: Zeroize, Data: Zeroize> Zeroize for AeadEnvelope<Algorithm, Nonce, Mac, Data>

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.

Auto Trait Implementations§

§

impl<Algorithm, Nonce, Mac, Data> Freeze for AeadEnvelope<Algorithm, Nonce, Mac, Data>
where PhantomData<Algorithm>: Freeze, Nonce: Freeze, Mac: Freeze, Data: Freeze,

§

impl<Algorithm, Nonce, Mac, Data> RefUnwindSafe for AeadEnvelope<Algorithm, Nonce, Mac, Data>
where PhantomData<Algorithm>: RefUnwindSafe, Nonce: RefUnwindSafe, Mac: RefUnwindSafe, Data: RefUnwindSafe,

§

impl<Algorithm, Nonce, Mac, Data> Send for AeadEnvelope<Algorithm, Nonce, Mac, Data>
where PhantomData<Algorithm>: Send, Nonce: Send, Mac: Send, Data: Send,

§

impl<Algorithm, Nonce, Mac, Data> Sync for AeadEnvelope<Algorithm, Nonce, Mac, Data>
where PhantomData<Algorithm>: Sync, Nonce: Sync, Mac: Sync, Data: Sync,

§

impl<Algorithm, Nonce, Mac, Data> Unpin for AeadEnvelope<Algorithm, Nonce, Mac, Data>
where PhantomData<Algorithm>: Unpin, Nonce: Unpin, Mac: Unpin, Data: Unpin,

§

impl<Algorithm, Nonce, Mac, Data> UnsafeUnpin for AeadEnvelope<Algorithm, Nonce, Mac, Data>
where PhantomData<Algorithm>: UnsafeUnpin, Nonce: UnsafeUnpin, Mac: UnsafeUnpin, Data: UnsafeUnpin,

§

impl<Algorithm, Nonce, Mac, Data> UnwindSafe for AeadEnvelope<Algorithm, Nonce, Mac, Data>
where PhantomData<Algorithm>: UnwindSafe, Nonce: UnwindSafe, Mac: UnwindSafe, Data: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<'de, T, C> Deserialize<'de, C> for T
where C: Config, T: SchemaRead<'de, C>,

Source§

fn deserialize(src: &'de [u8], config: C) -> Result<Self::Dst, ReadError>

Deserialize the input bytes into a new Self::Dst.
Source§

fn deserialize_into( src: &'de [u8], dst: &mut MaybeUninit<Self::Dst>, config: C, ) -> Result<(), ReadError>

Deserialize the input bytes into dst.
Source§

impl<'de, T> Deserialize<'de> for T
where T: SchemaRead<'de, Configuration>,

Source§

fn deserialize(src: &'de [u8]) -> Result<Self::Dst, ReadError>

Deserialize the input src bytes into a new Self::Dst.
Source§

fn deserialize_into( src: &'de [u8], dst: &mut MaybeUninit<Self::Dst>, ) -> Result<(), ReadError>

Deserialize the input src bytes into dst.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DeserializeOwned for T

Source§

fn deserialize_from<'de>(src: impl Reader<'de>) -> Result<Self::Dst, ReadError>

Deserialize from the given Reader into a new Self::Dst.
Source§

fn deserialize_from_into<'de>( src: impl Reader<'de>, dst: &mut MaybeUninit<Self::Dst>, ) -> Result<(), ReadError>

Deserialize from the given Reader into dst.
Source§

impl<T, C> DeserializeOwned<C> for T
where C: Config, T: SchemaReadOwned<C>,

Source§

fn deserialize_from<'de>(src: impl Reader<'de>) -> Result<Self::Dst, ReadError>

Deserialize from the given Reader into a new Self::Dst.
Source§

fn deserialize_from_into<'de>( src: impl Reader<'de>, dst: &mut MaybeUninit<Self::Dst>, ) -> Result<(), ReadError>

Deserialize from the given Reader into dst.
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, C> SchemaReadOwned<C> for T
where C: ConfigCore, T: for<'de> SchemaRead<'de, C>,

Source§

impl<T> Serialize for T

Source§

fn serialize(src: &Self::Src) -> Result<Vec<u8>, WriteError>

Available on crate feature alloc only.
Serialize a serializable type into a Vec of bytes.
Source§

fn serialize_into(dst: impl Writer, src: &Self::Src) -> Result<(), WriteError>

Serialize a serializable type into the given byte buffer. Read more
Source§

fn serialized_size(src: &Self::Src) -> Result<u64, WriteError>

Get the size in bytes of the type when serialized.
Source§

impl<T, C> Serialize<C> for T
where C: Config, T: SchemaWrite<C> + ?Sized,

Source§

fn serialize(src: &Self::Src, config: C) -> Result<Vec<u8>, WriteError>

Available on crate feature alloc only.
Serialize a serializable type into a Vec of bytes.
Source§

fn serialize_into( dst: impl Writer, src: &Self::Src, config: C, ) -> Result<(), WriteError>

Serialize a serializable type into the given Writer. Read more
Source§

fn serialized_size(src: &Self::Src, config: C) -> Result<u64, WriteError>

Get the size in bytes of the type when serialized.
Source§

impl<T, Target, C> TagEncoding<C> for T
where C: ConfigCore, T: for<'de> SchemaRead<'de, C, Dst = Target> + SchemaWrite<C, Src = Target> + 'static, Target: TryFrom<u32>, u32: TryFrom<Target>,

Source§

type Target = Target

Source§

fn try_from_u32( value: u32, ) -> Result<<T as TagEncoding<C>>::Target, TagEncodingOverflow>

Convert a u32 to the encoding target.
Source§

fn try_into_u32( x: <T as TagEncoding<C>>::Target, ) -> Result<u32, TagEncodingOverflow>

Convert the encoding target to a u32.
Source§

fn size_of_from_u32(value: u32) -> Result<usize, WriteError>

Get the size of the encoding target from the given u32. Read more
Source§

fn write_from_u32(writer: impl Writer, value: u32) -> Result<(), WriteError>

Write the encoding target from the given u32 to the given Writer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.