pub struct DryocSecretBox<Mac: ByteArray<CRYPTO_SECRETBOX_MACBYTES> + Zeroize, Data: Bytes + Zeroize> { /* private fields */ }Expand description
An authenticated secret-key encrypted box, compatible with a libsodium box.
Use with either VecBox or protected::LockedBox type aliases.
Refer to crate::dryocsecretbox for sample usage.
Implementations§
Source§impl<Mac: NewByteArray<CRYPTO_SECRETBOX_MACBYTES> + Zeroize, Data: NewBytes + ResizableBytes + Zeroize> DryocSecretBox<Mac, Data>
impl<Mac: NewByteArray<CRYPTO_SECRETBOX_MACBYTES> + Zeroize, Data: NewBytes + ResizableBytes + Zeroize> DryocSecretBox<Mac, Data>
Sourcepub fn encrypt<Message: Bytes + ?Sized, Nonce: ByteArray<CRYPTO_SECRETBOX_NONCEBYTES>, SecretKey: ByteArray<CRYPTO_SECRETBOX_KEYBYTES>>(
message: &Message,
nonce: &Nonce,
secret_key: &SecretKey,
) -> Self
pub fn encrypt<Message: Bytes + ?Sized, Nonce: ByteArray<CRYPTO_SECRETBOX_NONCEBYTES>, SecretKey: ByteArray<CRYPTO_SECRETBOX_KEYBYTES>>( message: &Message, nonce: &Nonce, secret_key: &SecretKey, ) -> Self
Encrypts a message using secret_key, and returns a new
DryocSecretBox with ciphertext and tag
Source§impl<'a, Mac: ByteArray<CRYPTO_SECRETBOX_MACBYTES> + TryFrom<&'a [u8]> + Zeroize, Data: Bytes + From<&'a [u8]> + Zeroize> DryocSecretBox<Mac, Data>
impl<'a, Mac: ByteArray<CRYPTO_SECRETBOX_MACBYTES> + TryFrom<&'a [u8]> + Zeroize, Data: Bytes + From<&'a [u8]> + Zeroize> DryocSecretBox<Mac, Data>
Sourcepub fn from_bytes(bytes: &'a [u8]) -> Result<Self, Error>
pub fn from_bytes(bytes: &'a [u8]) -> Result<Self, Error>
Initializes a DryocSecretBox from a slice. Expects the first
CRYPTO_SECRETBOX_MACBYTES bytes to contain the message
authentication tag, with the remaining bytes containing the
encrypted message.
Source§impl<Mac: ByteArray<CRYPTO_SECRETBOX_MACBYTES> + Zeroize, Data: Bytes + Zeroize> DryocSecretBox<Mac, Data>
impl<Mac: ByteArray<CRYPTO_SECRETBOX_MACBYTES> + Zeroize, Data: Bytes + Zeroize> DryocSecretBox<Mac, Data>
Sourcepub fn from_parts(tag: Mac, data: Data) -> Self
pub fn from_parts(tag: Mac, data: Data) -> Self
Returns a new box with tag and data, consuming both
Sourcepub fn into_parts(self) -> (Mac, Data)
pub fn into_parts(self) -> (Mac, Data)
Moves the tag and data out of this instance, returning them as a tuple.
Source§impl<Mac: ByteArray<CRYPTO_SECRETBOX_MACBYTES> + Zeroize, Data: Bytes + Zeroize> DryocSecretBox<Mac, Data>
impl<Mac: ByteArray<CRYPTO_SECRETBOX_MACBYTES> + Zeroize, Data: Bytes + Zeroize> DryocSecretBox<Mac, Data>
Sourcepub fn decrypt<Output: ResizableBytes + NewBytes, Nonce: ByteArray<CRYPTO_SECRETBOX_NONCEBYTES>, SecretKey: ByteArray<CRYPTO_SECRETBOX_KEYBYTES>>(
&self,
nonce: &Nonce,
secret_key: &SecretKey,
) -> Result<Output, Error>
pub fn decrypt<Output: ResizableBytes + NewBytes, Nonce: ByteArray<CRYPTO_SECRETBOX_NONCEBYTES>, SecretKey: ByteArray<CRYPTO_SECRETBOX_KEYBYTES>>( &self, nonce: &Nonce, secret_key: &SecretKey, ) -> Result<Output, Error>
Decrypts ciphertext using secret_key, returning a new
DryocSecretBox with decrypted message
Sourcepub fn to_bytes<Bytes: NewBytes + ResizableBytes>(&self) -> Bytes
pub fn to_bytes<Bytes: NewBytes + ResizableBytes>(&self) -> Bytes
Copies self into the target. Can be used with protected memory.
Source§impl DryocSecretBox<Mac, Vec<u8>>
impl DryocSecretBox<Mac, Vec<u8>>
Sourcepub fn encrypt_to_vecbox<Message: Bytes + ?Sized, Nonce: ByteArray<CRYPTO_SECRETBOX_NONCEBYTES>, SecretKey: ByteArray<CRYPTO_SECRETBOX_KEYBYTES>>(
message: &Message,
nonce: &Nonce,
secret_key: &SecretKey,
) -> Self
pub fn encrypt_to_vecbox<Message: Bytes + ?Sized, Nonce: ByteArray<CRYPTO_SECRETBOX_NONCEBYTES>, SecretKey: ByteArray<CRYPTO_SECRETBOX_KEYBYTES>>( message: &Message, nonce: &Nonce, secret_key: &SecretKey, ) -> Self
Encrypts a message using secret_key, and returns a new
DryocSecretBox with ciphertext and tag
Sourcepub fn decrypt_to_vec<Nonce: ByteArray<CRYPTO_SECRETBOX_NONCEBYTES>, SecretKey: ByteArray<CRYPTO_SECRETBOX_KEYBYTES>>(
&self,
nonce: &Nonce,
secret_key: &SecretKey,
) -> Result<Vec<u8>, Error>
pub fn decrypt_to_vec<Nonce: ByteArray<CRYPTO_SECRETBOX_NONCEBYTES>, SecretKey: ByteArray<CRYPTO_SECRETBOX_KEYBYTES>>( &self, nonce: &Nonce, secret_key: &SecretKey, ) -> Result<Vec<u8>, Error>
Decrypts ciphertext using secret_key, returning a new
DryocSecretBox with decrypted message
Source§impl<'a, Mac: NewByteArray<CRYPTO_SECRETBOX_MACBYTES> + Zeroize, Data: NewBytes + ResizableBytes + From<&'a [u8]> + Zeroize> DryocSecretBox<Mac, Data>
impl<'a, Mac: NewByteArray<CRYPTO_SECRETBOX_MACBYTES> + Zeroize, Data: NewBytes + ResizableBytes + From<&'a [u8]> + Zeroize> DryocSecretBox<Mac, Data>
Source§impl<'a, Mac: ByteArray<CRYPTO_SECRETBOX_MACBYTES> + Zeroize, Data: Bytes + ResizableBytes + From<&'a [u8]> + Zeroize> DryocSecretBox<Mac, Data>
impl<'a, Mac: ByteArray<CRYPTO_SECRETBOX_MACBYTES> + Zeroize, Data: Bytes + ResizableBytes + From<&'a [u8]> + Zeroize> DryocSecretBox<Mac, Data>
Sourcepub fn with_data_and_mac(tag: Mac, input: &'a [u8]) -> Self
pub fn with_data_and_mac(tag: Mac, input: &'a [u8]) -> Self
Returns a new box with data and tag, with data copied from input
and tag consumed.
Trait Implementations§
Source§impl<Mac: Clone + ByteArray<CRYPTO_SECRETBOX_MACBYTES> + Zeroize, Data: Clone + Bytes + Zeroize> Clone for DryocSecretBox<Mac, Data>
impl<Mac: Clone + ByteArray<CRYPTO_SECRETBOX_MACBYTES> + Zeroize, Data: Clone + Bytes + Zeroize> Clone for DryocSecretBox<Mac, Data>
Source§fn clone(&self) -> DryocSecretBox<Mac, Data>
fn clone(&self) -> DryocSecretBox<Mac, Data>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more