Struct dryoc::dryocsecretbox::DryocSecretBox
source · pub struct DryocSecretBox<Mac: ByteArray<CRYPTO_SECRETBOX_MACBYTES>, Data: Bytes> { /* private fields */ }
Expand description
A public-key authenticated 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>, Data: NewBytes + ResizableBytes> DryocSecretBox<Mac, Data>
impl<Mac: NewByteArray<CRYPTO_SECRETBOX_MACBYTES>, Data: NewBytes + ResizableBytes> 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 sender_secret_key
for recipient_public_key
,
and returns a new DryocSecretBox with ciphertext and tag
source§impl<'a, Mac: ByteArray<CRYPTO_SECRETBOX_MACBYTES> + TryFrom<&'a [u8]>, Data: Bytes + From<&'a [u8]>> DryocSecretBox<Mac, Data>
impl<'a, Mac: ByteArray<CRYPTO_SECRETBOX_MACBYTES> + TryFrom<&'a [u8]>, Data: Bytes + From<&'a [u8]>> 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>, Data: Bytes> DryocSecretBox<Mac, Data>
impl<Mac: ByteArray<CRYPTO_SECRETBOX_MACBYTES>, Data: Bytes> 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>, Data: Bytes> DryocSecretBox<Mac, Data>
impl<Mac: ByteArray<CRYPTO_SECRETBOX_MACBYTES>, Data: Bytes> 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 recipient_secret_key
and
sender_public_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 sender_secret_key
for recipient_public_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 recipient_secret_key
and
sender_public_key
, returning a new DryocSecretBox with decrypted
message
source§impl<'a, Mac: NewByteArray<CRYPTO_SECRETBOX_MACBYTES>, Data: NewBytes + ResizableBytes + From<&'a [u8]>> DryocSecretBox<Mac, Data>
impl<'a, Mac: NewByteArray<CRYPTO_SECRETBOX_MACBYTES>, Data: NewBytes + ResizableBytes + From<&'a [u8]>> DryocSecretBox<Mac, Data>
source§impl<'a, Mac: ByteArray<CRYPTO_SECRETBOX_MACBYTES>, Data: Bytes + ResizableBytes + From<&'a [u8]>> DryocSecretBox<Mac, Data>
impl<'a, Mac: ByteArray<CRYPTO_SECRETBOX_MACBYTES>, Data: Bytes + ResizableBytes + From<&'a [u8]>> 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>, Data: Clone + Bytes> Clone for DryocSecretBox<Mac, Data>
impl<Mac: Clone + ByteArray<CRYPTO_SECRETBOX_MACBYTES>, Data: Clone + Bytes> 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