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.
§Panics
Panics if allocation or resizing panics, the message exceeds
CRYPTO_SECRETBOX_MESSAGEBYTES_MAX,
or a custom Data implementation leaves its buffer shorter than the
message.
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.
§Errors
Returns an error if bytes is shorter than one authentication tag or
the tag cannot be converted to Mac.
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 this box using secret_key.
§Errors
Returns an error if the output storage is shorter than the ciphertext or authentication fails. Authentication fails when the key, nonce, tag, or ciphertext does not match the value used during encryption.
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 this box using secret_key and returns the plaintext.
§Errors
Returns an error if authentication fails because the key, nonce, tag, or ciphertext does not match.
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 ciphertext copied from input and the supplied
tag.
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 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more