Struct dryoc::dryocbox::DryocBox

source ·
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>

source

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.

source§

impl<EphemeralPublicKey: NewByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, Mac: NewByteArray<CRYPTO_BOX_MACBYTES> + Zeroize, Data: NewBytes + ResizableBytes + Zeroize> DryocBox<EphemeralPublicKey, Mac, Data>

source

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.

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>

source

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.

source

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.

source§

impl<EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, Mac: ByteArray<CRYPTO_BOX_MACBYTES> + Zeroize, Data: Bytes + Zeroize> DryocBox<EphemeralPublicKey, Mac, Data>

source

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.

source

pub fn to_vec(&self) -> Vec<u8>

Copies self into a new Vec

source

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.

source

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.

source

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_secret_key, and returning the decrypted message upon success.

source

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>>

source

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.

source

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.

source

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.

source

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_secret_key, returning the decrypted message upon success.

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>

source

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.

source

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.

Trait Implementations§

source§

impl<EphemeralPublicKey: Clone + ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, Mac: Clone + ByteArray<CRYPTO_BOX_MACBYTES> + Zeroize, Data: Clone + Bytes + Zeroize> Clone for DryocBox<EphemeralPublicKey, Mac, Data>

source§

fn clone(&self) -> DryocBox<EphemeralPublicKey, Mac, Data>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<EphemeralPublicKey: Debug + ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, Mac: Debug + ByteArray<CRYPTO_BOX_MACBYTES> + Zeroize, Data: Debug + Bytes + Zeroize> Debug for DryocBox<EphemeralPublicKey, Mac, Data>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de, EphemeralPublicKey, Mac, Data> Deserialize<'de> for DryocBox<EphemeralPublicKey, Mac, Data>
where EphemeralPublicKey: Deserialize<'de> + ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, Mac: Deserialize<'de> + ByteArray<CRYPTO_BOX_MACBYTES> + Zeroize, Data: Deserialize<'de> + Bytes + Zeroize,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, Mac: ByteArray<CRYPTO_BOX_MACBYTES> + Zeroize, Data: Bytes + Zeroize> PartialEq for DryocBox<EphemeralPublicKey, Mac, Data>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<EphemeralPublicKey, Mac, Data> Serialize for DryocBox<EphemeralPublicKey, Mac, Data>
where EphemeralPublicKey: Serialize + ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, Mac: Serialize + ByteArray<CRYPTO_BOX_MACBYTES> + Zeroize, Data: Serialize + Bytes + Zeroize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<EphemeralPublicKey: ByteArray<CRYPTO_BOX_PUBLICKEYBYTES> + Zeroize, Mac, Data> Zeroize for DryocBox<EphemeralPublicKey, Mac, Data>
where Mac: Zeroize + ByteArray<CRYPTO_BOX_MACBYTES>, Data: Zeroize + Bytes,

source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.

Auto Trait Implementations§

§

impl<EphemeralPublicKey, Mac, Data> RefUnwindSafe for DryocBox<EphemeralPublicKey, Mac, Data>
where Data: RefUnwindSafe, EphemeralPublicKey: RefUnwindSafe, Mac: RefUnwindSafe,

§

impl<EphemeralPublicKey, Mac, Data> Send for DryocBox<EphemeralPublicKey, Mac, Data>
where Data: Send, EphemeralPublicKey: Send, Mac: Send,

§

impl<EphemeralPublicKey, Mac, Data> Sync for DryocBox<EphemeralPublicKey, Mac, Data>
where Data: Sync, EphemeralPublicKey: Sync, Mac: Sync,

§

impl<EphemeralPublicKey, Mac, Data> Unpin for DryocBox<EphemeralPublicKey, Mac, Data>
where Data: Unpin, EphemeralPublicKey: Unpin, Mac: Unpin,

§

impl<EphemeralPublicKey, Mac, Data> UnwindSafe for DryocBox<EphemeralPublicKey, Mac, Data>
where Data: UnwindSafe, EphemeralPublicKey: UnwindSafe, Mac: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,