#[repr(C)]pub struct Key(pub [u8; 32]);Expand description
A key used to seal and open an encrypted box.
The underlying memory is zeroed on drop.
Tuple Fields§
§0: [u8; 32]Implementations§
Source§impl Key
impl Key
Sourcepub fn from_slice(s: &[u8]) -> Option<Self>
pub fn from_slice(s: &[u8]) -> Option<Self>
Deserialize a key from a byte slice.
Returns None if the slice length is not 32.
Sourcepub fn generate_with_rng<R>(r: &mut R) -> Key
pub fn generate_with_rng<R>(r: &mut R) -> Key
Generate a new random key using the given cryptographically-secure random number generator.
Source§impl Key
impl Key
Sourcepub fn seal(&self, msg: &mut [u8], n: &Nonce) -> Hmac
pub fn seal(&self, msg: &mut [u8], n: &Nonce) -> Hmac
Encrypt a message in place, returning the authentication code.
Sourcepub fn open(&self, c: &mut [u8], hmac: &Hmac, n: &Nonce) -> bool
pub fn open(&self, c: &mut [u8], hmac: &Hmac, n: &Nonce) -> bool
Decrypt an encrypted message in place.
Sourcepub fn open_attached_into(
&self,
input: &[u8],
n: &Nonce,
out: &mut [u8],
) -> bool
pub fn open_attached_into( &self, input: &[u8], n: &Nonce, out: &mut [u8], ) -> bool
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.
Trait Implementations§
impl FromBytes for Key
Auto Trait Implementations§
impl Freeze for Key
impl RefUnwindSafe for Key
impl Send for Key
impl Sync for Key
impl Unpin for Key
impl UnwindSafe for Key
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
Mutably borrows from an owned value. Read more