Struct crypto_secretbox::SecretBox

source ·
pub struct SecretBox<C> { /* private fields */ }
Expand description

The NaCl crypto_secretbox authenticated symmetric encryption primitive, generic

Implementations§

source§

impl<C> SecretBox<C>

source

pub const KEY_SIZE: usize = 32usize

Size of an XSalsa20Poly1305 key in bytes

source

pub const NONCE_SIZE: usize = 24usize

Size of an XSalsa20Poly1305 nonce in bytes

source

pub const TAG_SIZE: usize = 16usize

Size of a Poly1305 tag in bytes

Trait Implementations§

source§

impl<C> AeadCore for SecretBox<C>

source§

type NonceSize = UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B0>, B0>, B0>

The length of a nonce.
source§

type TagSize = UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>

The maximum length of the nonce.
source§

type CiphertextOverhead = UTerm

The upper bound amount of additional space required to support a ciphertext vs. a plaintext.
source§

fn generate_nonce( rng: impl CryptoRng + RngCore, ) -> GenericArray<u8, Self::NonceSize>

Generate a random nonce for this AEAD algorithm. Read more
source§

impl<C> AeadInPlace for SecretBox<C>
where C: Kdf + KeyIvInit + KeySizeUser<KeySize = U32> + IvSizeUser<IvSize = U8> + StreamCipher,

source§

fn encrypt_in_place( &self, nonce: &Nonce, associated_data: &[u8], buffer: &mut dyn Buffer, ) -> Result<(), Error>

Encrypt the given buffer containing a plaintext message in-place. Read more
source§

fn encrypt_in_place_detached( &self, nonce: &Nonce, associated_data: &[u8], buffer: &mut [u8], ) -> Result<Tag, Error>

Encrypt the data in-place, returning the authentication tag
source§

fn decrypt_in_place( &self, nonce: &Nonce, associated_data: &[u8], buffer: &mut dyn Buffer, ) -> Result<(), Error>

Decrypt the message in-place, returning an error in the event the provided authentication tag does not match the given ciphertext. Read more
source§

fn decrypt_in_place_detached( &self, nonce: &Nonce, associated_data: &[u8], buffer: &mut [u8], tag: &Tag, ) -> Result<(), Error>

Decrypt the message in-place, returning an error in the event the provided authentication tag does not match the given ciphertext (i.e. ciphertext is modified/unauthentic)
source§

impl<C> Clone for SecretBox<C>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<C> Drop for SecretBox<C>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<C> Kdf for SecretBox<C>
where C: Kdf,

source§

fn kdf(key: &Key, nonce: &GenericArray<u8, U16>) -> Key

Derive a new key from the provided input key and nonce.
source§

impl<C> KeyInit for SecretBox<C>

source§

fn new(key: &Key) -> Self

Create new value from fixed size key.
source§

fn new_from_slice(key: &[u8]) -> Result<Self, InvalidLength>

Create new value from variable size key.
source§

fn generate_key( rng: impl CryptoRng + RngCore, ) -> GenericArray<u8, Self::KeySize>

Generate random key using the provided CryptoRng.
source§

impl<C> KeySizeUser for SecretBox<C>

source§

type KeySize = UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>

Key size in bytes.
source§

fn key_size() -> usize

Return key size in bytes.

Auto Trait Implementations§

§

impl<C> Freeze for SecretBox<C>

§

impl<C> RefUnwindSafe for SecretBox<C>
where C: RefUnwindSafe,

§

impl<C> Send for SecretBox<C>
where C: Send,

§

impl<C> Sync for SecretBox<C>
where C: Sync,

§

impl<C> Unpin for SecretBox<C>
where C: Unpin,

§

impl<C> UnwindSafe for SecretBox<C>
where C: UnwindSafe,

Blanket Implementations§

source§

impl<Alg> Aead for Alg
where Alg: AeadInPlace,

source§

fn encrypt<'msg, 'aad>( &self, nonce: &GenericArray<u8, <Alg as AeadCore>::NonceSize>, plaintext: impl Into<Payload<'msg, 'aad>>, ) -> Result<Vec<u8>, Error>

Encrypt the given plaintext payload, and return the resulting ciphertext as a vector of bytes. Read more
source§

fn decrypt<'msg, 'aad>( &self, nonce: &GenericArray<u8, <Alg as AeadCore>::NonceSize>, ciphertext: impl Into<Payload<'msg, 'aad>>, ) -> Result<Vec<u8>, Error>

Decrypt the given ciphertext slice, and return the resulting plaintext as a vector of bytes. Read more
source§

impl<Alg> AeadMut for Alg
where Alg: AeadMutInPlace,

source§

fn encrypt<'msg, 'aad>( &mut self, nonce: &GenericArray<u8, <Alg as AeadCore>::NonceSize>, plaintext: impl Into<Payload<'msg, 'aad>>, ) -> Result<Vec<u8>, Error>

Encrypt the given plaintext slice, and return the resulting ciphertext as a vector of bytes. Read more
source§

fn decrypt<'msg, 'aad>( &mut self, nonce: &GenericArray<u8, <Alg as AeadCore>::NonceSize>, ciphertext: impl Into<Payload<'msg, 'aad>>, ) -> Result<Vec<u8>, Error>

Decrypt the given ciphertext slice, and return the resulting plaintext as a vector of bytes. Read more
source§

impl<Alg> AeadMutInPlace for Alg
where Alg: AeadInPlace,

source§

fn encrypt_in_place( &mut self, nonce: &GenericArray<u8, <Alg as AeadCore>::NonceSize>, associated_data: &[u8], buffer: &mut impl Buffer, ) -> Result<(), Error>

Encrypt the given buffer containing a plaintext message in-place. Read more
source§

fn encrypt_in_place_detached( &mut self, nonce: &GenericArray<u8, <Alg as AeadCore>::NonceSize>, associated_data: &[u8], buffer: &mut [u8], ) -> Result<GenericArray<u8, <Alg as AeadCore>::TagSize>, Error>

Encrypt the data in-place, returning the authentication tag
source§

fn decrypt_in_place( &mut self, nonce: &GenericArray<u8, <Alg as AeadCore>::NonceSize>, associated_data: &[u8], buffer: &mut impl Buffer, ) -> Result<(), Error>

Decrypt the message in-place, returning an error in the event the provided authentication tag does not match the given ciphertext. Read more
source§

fn decrypt_in_place_detached( &mut self, nonce: &GenericArray<u8, <Alg as AeadCore>::NonceSize>, associated_data: &[u8], buffer: &mut [u8], tag: &GenericArray<u8, <Alg as AeadCore>::TagSize>, ) -> Result<(), Error>

Decrypt the data in-place, returning an error in the event the provided authentication tag does not match the given ciphertext (i.e. ciphertext is modified/unauthentic)
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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> Same for T

source§

type Output = T

Should always be Self
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 = 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.