pub struct DryocBox<EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, Mac: ByteArray<CRYPTO_BOX_MACBYTES> + Zeroize, Data: Bytes + Zeroize> { /* private fields */ }Expand description
A libsodium public-key authenticated encrypted box.
Refer to crate::dryocbox for sample usage.
Implementations§
Source§impl<EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, Mac: NewByteArray<CRYPTO_BOX_MACBYTES> + Zeroize, Data: NewBytes + ResizableBytes + Zeroize> DryocBox<EphemeralPublicKey, Mac, Data>
impl<EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, Mac: NewByteArray<CRYPTO_BOX_MACBYTES> + Zeroize, Data: NewBytes + ResizableBytes + Zeroize> DryocBox<EphemeralPublicKey, Mac, Data>
Sourcepub fn encrypt<Message: Bytes + ?Sized, Nonce: ByteArray<CRYPTO_BOX_NONCEBYTES>, RecipientPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, SenderSecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES>>(
message: &Message,
nonce: &Nonce,
recipient_public_key: &RecipientPublicKey,
sender_secret_key: &SenderSecretKey,
) -> Result<Self, Error>
pub fn encrypt<Message: Bytes + ?Sized, Nonce: ByteArray<CRYPTO_BOX_NONCEBYTES>, RecipientPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, SenderSecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES>>( message: &Message, nonce: &Nonce, recipient_public_key: &RecipientPublicKey, sender_secret_key: &SenderSecretKey, ) -> Result<Self, Error>
Source§impl<EphemeralPublicKey: NewByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, Mac: NewByteArray<CRYPTO_BOX_MACBYTES> + Zeroize, Data: NewBytes + ResizableBytes + Zeroize> DryocBox<EphemeralPublicKey, Mac, Data>
impl<EphemeralPublicKey: NewByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, Mac: NewByteArray<CRYPTO_BOX_MACBYTES> + Zeroize, Data: NewBytes + ResizableBytes + Zeroize> DryocBox<EphemeralPublicKey, Mac, Data>
Sourcepub fn seal<Message: Bytes + ?Sized, RecipientPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>>(
message: &Message,
recipient_public_key: &RecipientPublicKey,
) -> Result<Self, Error>
pub fn seal<Message: Bytes + ?Sized, RecipientPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>>( message: &Message, recipient_public_key: &RecipientPublicKey, ) -> Result<Self, Error>
Encrypts a message for recipient_public_key, using an ephemeral secret
key and nonce. Returns a new DryocBox with ciphertext, tag, and
ephemeral public key.
§Errors
Returns an error if the message is too long, recipient_public_key is
an unacceptable low-order key, or the output storage does not resize to
the message length.
§Panics
Panics if the operating system’s random number generator fails while creating the ephemeral keypair.
Source§impl<'a, EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + TryFrom<&'a [u8]> + Zeroize, Mac: ByteArray<CRYPTO_BOX_MACBYTES> + TryFrom<&'a [u8]> + Zeroize, Data: Bytes + From<&'a [u8]> + Zeroize> DryocBox<EphemeralPublicKey, Mac, Data>
impl<'a, EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + TryFrom<&'a [u8]> + Zeroize, Mac: ByteArray<CRYPTO_BOX_MACBYTES> + TryFrom<&'a [u8]> + Zeroize, Data: Bytes + From<&'a [u8]> + Zeroize> DryocBox<EphemeralPublicKey, Mac, Data>
Sourcepub fn from_bytes(bytes: &'a [u8]) -> Result<Self, Error>
pub fn from_bytes(bytes: &'a [u8]) -> Result<Self, Error>
Initializes a DryocBox from a slice. Expects the first
CRYPTO_BOX_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.
Sourcepub fn from_sealed_bytes(bytes: &'a [u8]) -> Result<Self, Error>
pub fn from_sealed_bytes(bytes: &'a [u8]) -> Result<Self, Error>
Initializes a sealed DryocBox from a slice. Expects the first
CRYPTO_BOX_PUBLICKEYBYTES bytes to contain the ephemeral public key,
the next CRYPTO_BOX_MACBYTES bytes to be the message authentication
tag, with the remaining bytes containing the encrypted message.
§Errors
Returns an error if bytes is shorter than one ephemeral public key
plus one authentication tag, or if either field cannot be converted to
its target type.
Source§impl<EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, Mac: ByteArray<CRYPTO_BOX_MACBYTES> + Zeroize, Data: Bytes + Zeroize> DryocBox<EphemeralPublicKey, Mac, Data>
impl<EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, Mac: ByteArray<CRYPTO_BOX_MACBYTES> + Zeroize, Data: Bytes + Zeroize> DryocBox<EphemeralPublicKey, Mac, Data>
Sourcepub fn from_parts(
tag: Mac,
data: Data,
ephemeral_pk: Option<EphemeralPublicKey>,
) -> Self
pub fn from_parts( tag: Mac, data: Data, ephemeral_pk: Option<EphemeralPublicKey>, ) -> Self
Returns a new box with tag, data and (optional) ephemeral_pk,
consuming each.
Sourcepub fn into_parts(self) -> (Mac, Data, Option<EphemeralPublicKey>)
pub fn into_parts(self) -> (Mac, Data, Option<EphemeralPublicKey>)
Moves the tag, data, and (optional) ephemeral public key out of this instance, returning them as a tuple.
Sourcepub fn decrypt<Nonce: ByteArray<CRYPTO_BOX_NONCEBYTES>, SenderPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, RecipientSecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES>, Output: ResizableBytes + NewBytes>(
&self,
nonce: &Nonce,
sender_public_key: &SenderPublicKey,
recipient_secret_key: &RecipientSecretKey,
) -> Result<Output, Error>
pub fn decrypt<Nonce: ByteArray<CRYPTO_BOX_NONCEBYTES>, SenderPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, RecipientSecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES>, Output: ResizableBytes + NewBytes>( &self, nonce: &Nonce, sender_public_key: &SenderPublicKey, recipient_secret_key: &RecipientSecretKey, ) -> Result<Output, Error>
Decrypts this box using nonce, recipient_secret_key, and
sender_public_key, returning the decrypted message upon success.
§Errors
Returns an error if the ciphertext is too long, sender_public_key is
an unacceptable low-order key, the output storage has the wrong length,
or authentication fails. Authentication fails for a wrong key, nonce,
tag, or ciphertext.
Sourcepub fn precalc_decrypt<PrecalcSecretKey: ByteArray<CRYPTO_BOX_BEFORENMBYTES> + Zeroize, Nonce: ByteArray<CRYPTO_BOX_NONCEBYTES>, Output: ResizableBytes + NewBytes>(
&self,
nonce: &Nonce,
precalc_secret_key: &PrecalcSecretKey,
) -> Result<Output, Error>
pub fn precalc_decrypt<PrecalcSecretKey: ByteArray<CRYPTO_BOX_BEFORENMBYTES> + Zeroize, Nonce: ByteArray<CRYPTO_BOX_NONCEBYTES>, Output: ResizableBytes + NewBytes>( &self, nonce: &Nonce, precalc_secret_key: &PrecalcSecretKey, ) -> Result<Output, Error>
Decrypts this box using nonce and precalc_secret_key, returning the
decrypted message upon success.
§Errors
Returns an error if the ciphertext is too long, the output storage has the wrong length, or authentication fails because the precomputed key, nonce, tag, or ciphertext does not match.
Sourcepub fn unseal<RecipientPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, RecipientSecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize, Output: ResizableBytes + NewBytes + Zeroize>(
&self,
recipient_keypair: &KeyPair<RecipientPublicKey, RecipientSecretKey>,
) -> Result<Output, Error>
pub fn unseal<RecipientPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, RecipientSecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize, Output: ResizableBytes + NewBytes + Zeroize>( &self, recipient_keypair: &KeyPair<RecipientPublicKey, RecipientSecretKey>, ) -> Result<Output, Error>
Decrypts this sealed box using recipient_keypair.
§Errors
Returns an error if the ciphertext is too long, the box has no ephemeral public key, that key is an unacceptable low-order key, the output storage has the wrong length, or authentication fails. Authentication fails for the wrong recipient key pair or modified box data.
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 DryocBox<PublicKey, Mac, Vec<u8>>
impl DryocBox<PublicKey, Mac, Vec<u8>>
Sourcepub fn encrypt_to_vecbox<Message: Bytes + ?Sized, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES>>(
message: &Message,
nonce: &Nonce,
recipient_public_key: &PublicKey,
sender_secret_key: &SecretKey,
) -> Result<Self, Error>
pub fn encrypt_to_vecbox<Message: Bytes + ?Sized, SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES>>( message: &Message, nonce: &Nonce, recipient_public_key: &PublicKey, sender_secret_key: &SecretKey, ) -> Result<Self, Error>
Sourcepub fn precalc_encrypt_to_vecbox<Message: Bytes + ?Sized, PrecalcSecretKey: ByteArray<CRYPTO_BOX_BEFORENMBYTES> + Zeroize>(
message: &Message,
nonce: &Nonce,
precalc_secret_key: &PrecalcSecretKey,
) -> Result<Self, Error>
pub fn precalc_encrypt_to_vecbox<Message: Bytes + ?Sized, PrecalcSecretKey: ByteArray<CRYPTO_BOX_BEFORENMBYTES> + Zeroize>( message: &Message, nonce: &Nonce, precalc_secret_key: &PrecalcSecretKey, ) -> Result<Self, Error>
Sourcepub fn seal_to_vecbox<Message: Bytes + ?Sized>(
message: &Message,
recipient_public_key: &PublicKey,
) -> Result<Self, Error>
pub fn seal_to_vecbox<Message: Bytes + ?Sized>( message: &Message, recipient_public_key: &PublicKey, ) -> Result<Self, Error>
Encrypts a message for recipient_public_key, using an ephemeral secret
key and nonce, and returns a new DryocBox with the ciphertext,
ephemeral public key, and tag.
§Errors
Returns an error if the message is too long or recipient_public_key is
an unacceptable low-order key.
§Panics
Panics if the operating system’s random number generator fails while creating the ephemeral keypair.
Sourcepub fn decrypt_to_vec<SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES>>(
&self,
nonce: &Nonce,
sender_public_key: &PublicKey,
recipient_secret_key: &SecretKey,
) -> Result<Vec<u8>, Error>
pub fn decrypt_to_vec<SecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES>>( &self, nonce: &Nonce, sender_public_key: &PublicKey, recipient_secret_key: &SecretKey, ) -> Result<Vec<u8>, Error>
Decrypts this box using nonce, recipient_secret_key and
sender_public_key, returning the decrypted message upon success.
§Errors
Returns an error if the ciphertext is too long, sender_public_key is
an unacceptable low-order key, or authentication fails because a key,
nonce, tag, or ciphertext is wrong.
Sourcepub fn precalc_decrypt_to_vec<PrecalcSecretKey: ByteArray<CRYPTO_BOX_BEFORENMBYTES> + Zeroize>(
&self,
nonce: &Nonce,
precalc_secret_key: &PrecalcSecretKey,
) -> Result<Vec<u8>, Error>
pub fn precalc_decrypt_to_vec<PrecalcSecretKey: ByteArray<CRYPTO_BOX_BEFORENMBYTES> + Zeroize>( &self, nonce: &Nonce, precalc_secret_key: &PrecalcSecretKey, ) -> Result<Vec<u8>, Error>
Decrypts this box using nonce and
precalc_secret_key, returning the decrypted message upon
success.
§Errors
Returns an error if the ciphertext is too long or authentication fails because the precomputed key, nonce, tag, or ciphertext does not match.
Sourcepub fn unseal_to_vec<RecipientPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, RecipientSecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize>(
&self,
recipient_keypair: &KeyPair<RecipientPublicKey, RecipientSecretKey>,
) -> Result<Vec<u8>, Error>
pub fn unseal_to_vec<RecipientPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, RecipientSecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES> + Zeroize>( &self, recipient_keypair: &KeyPair<RecipientPublicKey, RecipientSecretKey>, ) -> Result<Vec<u8>, Error>
Decrypts this sealed box using recipient_keypair.
§Errors
Returns an error if the ciphertext is too long, the box has no ephemeral public key, that key is an unacceptable low-order key, or authentication fails because the recipient key pair or box data is wrong.
Source§impl<'a, EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, Mac: ByteArray<CRYPTO_BOX_MACBYTES> + Zeroize, Data: Bytes + ResizableBytes + From<&'a [u8]> + Zeroize> DryocBox<EphemeralPublicKey, Mac, Data>
impl<'a, EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, Mac: ByteArray<CRYPTO_BOX_MACBYTES> + Zeroize, Data: Bytes + ResizableBytes + From<&'a [u8]> + Zeroize> DryocBox<EphemeralPublicKey, Mac, Data>
Sourcepub fn new_with_data_and_mac(tag: Mac, input: &'a [u8]) -> Self
pub fn new_with_data_and_mac(tag: Mac, input: &'a [u8]) -> Self
Returns a new box with ciphertext copied from input and the supplied
tag. The box has no ephemeral public key.
Sourcepub fn new_with_epk_data_and_mac(
ephemeral_pk: EphemeralPublicKey,
tag: Mac,
input: &'a [u8],
) -> Self
pub fn new_with_epk_data_and_mac( ephemeral_pk: EphemeralPublicKey, tag: Mac, input: &'a [u8], ) -> Self
Returns a new sealed box with ciphertext copied from input and the
supplied ephemeral_pk and tag.