pub struct DryocBox<EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, Mac: ByteArray<CRYPTO_BOX_MACBYTES>, Data: Bytes> { /* private fields */ }
Expand description
A libsodium public-key authenticated encrypted box.
Refer to crate::dryocbox for sample usage.
Implementations
sourceimpl<EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, Mac: NewByteArray<CRYPTO_BOX_MACBYTES>, Data: NewBytes + ResizableBytes> DryocBox<EphemeralPublicKey, Mac, Data>
impl<EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, Mac: NewByteArray<CRYPTO_BOX_MACBYTES>, Data: NewBytes + ResizableBytes> 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>
Encrypts a message using sender_secret_key
for recipient_public_key
,
and returns a new DryocBox with ciphertext and tag.
sourceimpl<EphemeralPublicKey: NewByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, Mac: NewByteArray<CRYPTO_BOX_MACBYTES>, Data: NewBytes + ResizableBytes> DryocBox<EphemeralPublicKey, Mac, Data>
impl<EphemeralPublicKey: NewByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, Mac: NewByteArray<CRYPTO_BOX_MACBYTES>, Data: NewBytes + ResizableBytes> 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.
sourceimpl<'a, EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + TryFrom<&'a [u8]>, Mac: ByteArray<CRYPTO_BOX_MACBYTES> + TryFrom<&'a [u8]>, Data: Bytes + From<&'a [u8]>> DryocBox<EphemeralPublicKey, Mac, Data>
impl<'a, EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + TryFrom<&'a [u8]>, Mac: ByteArray<CRYPTO_BOX_MACBYTES> + TryFrom<&'a [u8]>, Data: Bytes + From<&'a [u8]>> 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.
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.
sourceimpl<EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, Mac: ByteArray<CRYPTO_BOX_MACBYTES>, Data: Bytes> DryocBox<EphemeralPublicKey, Mac, Data>
impl<EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, Mac: ByteArray<CRYPTO_BOX_MACBYTES>, Data: Bytes> 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.
sourcepub fn unseal<RecipientPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, RecipientSecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES>, Output: ResizableBytes + NewBytes>(
&self,
recipient_keypair: &KeyPair<RecipientPublicKey, RecipientSecretKey>
) -> Result<Output, Error>
pub fn unseal<RecipientPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, RecipientSecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES>, Output: ResizableBytes + NewBytes>(
&self,
recipient_keypair: &KeyPair<RecipientPublicKey, RecipientSecretKey>
) -> Result<Output, Error>
Decrypts this sealed box using recipient_secret_key
, and
returning the decrypted message upon success.
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.
sourceimpl 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>
Encrypts a message using sender_secret_key
for recipient_public_key
,
and returns a new DryocBox with ciphertext and tag.
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.
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.
sourcepub fn unseal_to_vec<RecipientPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, RecipientSecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES>>(
&self,
recipient_keypair: &KeyPair<RecipientPublicKey, RecipientSecretKey>
) -> Result<Vec<u8>, Error>
pub fn unseal_to_vec<RecipientPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, RecipientSecretKey: ByteArray<CRYPTO_BOX_SECRETKEYBYTES>>(
&self,
recipient_keypair: &KeyPair<RecipientPublicKey, RecipientSecretKey>
) -> Result<Vec<u8>, Error>
Decrypts this sealed box using recipient_secret_key
, returning the
decrypted message upon success.
sourceimpl<'a, EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, Mac: ByteArray<CRYPTO_BOX_MACBYTES>, Data: Bytes + ResizableBytes + From<&'a [u8]>> DryocBox<EphemeralPublicKey, Mac, Data>
impl<'a, EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES>, Mac: ByteArray<CRYPTO_BOX_MACBYTES>, Data: Bytes + ResizableBytes + From<&'a [u8]>> 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 data
and tag
, with data copied from input
and tag
consumed. The ephemeral public key is assumed not to be
present.
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 ephemeral_pk
, data
and tag
, where
data copied from input
and ephemeral_pk
& tag
are consumed.