[][src]Struct ssb_crypto::secretbox::Key

#[repr(C)]pub struct Key(pub [u8; 32]);

A key used to seal and open an encrypted box.

The underlying memory is zeroed on drop.

Implementations

impl Key[src]

pub const SIZE: usize[src]

The size of a key, in bytes (32).

pub fn from_slice(s: &[u8]) -> Option<Self>[src]

Deserialize a key from a byte slice.

Returns None if the slice length is not 32.

pub fn generate_with_rng<R>(r: &mut R) -> Key where
    R: CryptoRng + RngCore
[src]

Generate a new random key using the given cryptographically-secure random number generator.

pub fn generate() -> Key[src]

Generate a new random key.

impl Key[src]

pub fn seal(&self, msg: &mut [u8], n: &Nonce) -> Hmac[src]

Encrypt a message in place, returning the authentication code.

#[must_use]pub fn open(&self, c: &mut [u8], hmac: &Hmac, n: &Nonce) -> bool[src]

Decrypt an encrypted message in place.

#[must_use]pub fn open_attached_into(
    &self,
    input: &[u8],
    n: &Nonce,
    out: &mut [u8]
) -> bool
[src]

Decrypt an encrypted message with attached authentication code, writing the decrypted message into the provided buffer.

If the decryption fails, out will contain a copy of the encrypted message.

Panics

Panics if the output buffer length isn't big enough to hold the plaintext message. The output buffer length should be at least input.len() - Hmac::SIZE.

pub fn seal_attached_into(&self, msg: &[u8], nonce: &Nonce, out: &mut [u8])[src]

Encrypt a message, writing the resulting Hmac and ciphertext into the given output buffer. The output buffer size must be at least msg.len() + Hmac::SIZE.

Trait Implementations

impl AsBytes for Key[src]

impl Clone for Key[src]

impl Drop for Key[src]

impl FromBytes for Key[src]

impl Zeroize for Key[src]

Auto Trait Implementations

impl RefUnwindSafe for Key

impl Send for Key

impl Sync for Key

impl Unpin for Key

impl UnwindSafe for Key

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<Z> Zeroize for Z where
    Z: DefaultIsZeroes
[src]