Skip to main content

DryocSealedBox

Struct DryocSealedBox 

Source
pub struct DryocSealedBox<EncapsulatedKey: ByteArray<CRYPTO_KEM_XWING_CIPHERTEXTBYTES> + Zeroize, Mac: ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES> + Zeroize, Data: Bytes + Zeroize> { /* private fields */ }
Expand description

A post-quantum sealed box: an HPKE-encrypted message for one recipient.

Refer to crate::dryocsealedbox for the byte format and sample usage.

Implementations§

Source§

impl<EncapsulatedKey: NewByteArray<CRYPTO_KEM_XWING_CIPHERTEXTBYTES> + Zeroize, Mac: NewByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES> + Zeroize, Data: NewBytes + ResizableBytes + Zeroize> DryocSealedBox<EncapsulatedKey, Mac, Data>

Source

pub fn seal<Message: Bytes + ?Sized, RecipientPublicKey: ByteArray<CRYPTO_KEM_XWING_PUBLICKEYBYTES>>( message: &Message, recipient_public_key: &RecipientPublicKey, ) -> Result<Self, Error>

Encrypts message for recipient_public_key, returning a new DryocSealedBox.

§Errors

Returns an error if the message is too long or recipient_public_key is not a valid X-Wing public key.

§Panics

Panics if the operating system’s random number generator fails.

Source§

impl<'a, EncapsulatedKey: ByteArray<CRYPTO_KEM_XWING_CIPHERTEXTBYTES> + TryFrom<&'a [u8]> + Zeroize, Mac: ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES> + TryFrom<&'a [u8]> + Zeroize, Data: Bytes + From<&'a [u8]> + Zeroize> DryocSealedBox<EncapsulatedKey, Mac, Data>

Source

pub fn from_bytes(bytes: &'a [u8]) -> Result<Self, Error>

Reads a sealed box from its wire format: the X-Wing ciphertext, the encrypted message, then the tag.

§Errors

Returns an error if bytes is shorter than SEALBYTES or a field cannot be converted to its target type.

Source§

impl<EncapsulatedKey: ByteArray<CRYPTO_KEM_XWING_CIPHERTEXTBYTES> + Zeroize, Mac: ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES> + Zeroize, Data: Bytes + Zeroize> DryocSealedBox<EncapsulatedKey, Mac, Data>

Source

pub fn from_parts(enc: EncapsulatedKey, tag: Mac, data: Data) -> Self

Returns a new box from its parts, consuming each.

Source

pub fn enc(&self) -> &EncapsulatedKey

Returns the X-Wing ciphertext (HPKE enc).

Source

pub fn tag(&self) -> &Mac

Returns the authentication tag.

Source

pub fn data(&self) -> &Data

Returns the encrypted message.

Source

pub fn into_parts(self) -> (EncapsulatedKey, Mac, Data)

Moves the X-Wing ciphertext, tag and encrypted message out of this box.

Source

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

Available on crate feature alloc only.

Copies the box’s wire format into a new Vec.

Source

pub fn to_bytes<Bytes: NewBytes + ResizableBytes>(&self) -> Bytes

Copies the box’s wire format into new Bytes.

Source

pub fn open<Output: ResizableBytes + NewBytes + Zeroize, RecipientPublicKey: ByteArray<CRYPTO_KEM_XWING_PUBLICKEYBYTES> + Zeroize, RecipientSecretKey: ByteArray<CRYPTO_KEM_XWING_SECRETKEYBYTES> + Zeroize>( &self, recipient_keypair: &KeyPair<RecipientPublicKey, RecipientSecretKey>, ) -> Result<Output, Error>

Decrypts this box with recipient_keypair, returning the message.

§Errors

Returns Error::AuthenticationFailed if the box was not sealed for this key pair or was modified, or an error if the X-Wing ciphertext carries a low-order X25519 point.

Source§

impl DryocSealedBox<EncapsulatedKey, Mac, Vec<u8>>

Source

pub fn seal_to_vecbox<Message: Bytes + ?Sized, RecipientPublicKey: ByteArray<CRYPTO_KEM_XWING_PUBLICKEYBYTES>>( message: &Message, recipient_public_key: &RecipientPublicKey, ) -> Result<Self, Error>

Available on crate feature alloc only.

Encrypts message for recipient_public_key into a VecBox. Provided for convenience.

§Errors

Returns the same errors as DryocSealedBox::seal.

Source

pub fn open_to_vec<RecipientPublicKey: ByteArray<CRYPTO_KEM_XWING_PUBLICKEYBYTES> + Zeroize, RecipientSecretKey: ByteArray<CRYPTO_KEM_XWING_SECRETKEYBYTES> + Zeroize>( &self, recipient_keypair: &KeyPair<RecipientPublicKey, RecipientSecretKey>, ) -> Result<Vec<u8>, Error>

Available on crate feature alloc only.

Decrypts this box with recipient_keypair into a Vec. Provided for convenience.

§Errors

Returns the same errors as DryocSealedBox::open.

Trait Implementations§

Source§

impl<EncapsulatedKey: Clone + ByteArray<CRYPTO_KEM_XWING_CIPHERTEXTBYTES> + Zeroize, Mac: Clone + ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES> + Zeroize, Data: Clone + Bytes + Zeroize> Clone for DryocSealedBox<EncapsulatedKey, Mac, Data>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<EncapsulatedKey: Debug + ByteArray<CRYPTO_KEM_XWING_CIPHERTEXTBYTES> + Zeroize, Mac: Debug + ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES> + Zeroize, Data: Debug + Bytes + Zeroize> Debug for DryocSealedBox<EncapsulatedKey, Mac, Data>

Source§

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

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

impl<'de, EncapsulatedKey, Mac, Data> Deserialize<'de> for DryocSealedBox<EncapsulatedKey, Mac, Data>
where EncapsulatedKey: Deserialize<'de> + ByteArray<CRYPTO_KEM_XWING_CIPHERTEXTBYTES> + Zeroize, Mac: Deserialize<'de> + ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES> + Zeroize, Data: Deserialize<'de> + Bytes + Zeroize,

Available on crate feature serde only.
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<EncapsulatedKey, Mac, Data> Serialize for DryocSealedBox<EncapsulatedKey, Mac, Data>
where EncapsulatedKey: Serialize + ByteArray<CRYPTO_KEM_XWING_CIPHERTEXTBYTES> + Zeroize, Mac: Serialize + ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES> + Zeroize, Data: Serialize + Bytes + Zeroize,

Available on crate feature serde only.
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<EncapsulatedKey, Mac, Data> Zeroize for DryocSealedBox<EncapsulatedKey, Mac, Data>
where EncapsulatedKey: Zeroize + ByteArray<CRYPTO_KEM_XWING_CIPHERTEXTBYTES>, Mac: Zeroize + ByteArray<CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES>, 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<EncapsulatedKey, Mac, Data> Freeze for DryocSealedBox<EncapsulatedKey, Mac, Data>
where EncapsulatedKey: Freeze, Mac: Freeze, Data: Freeze,

§

impl<EncapsulatedKey, Mac, Data> RefUnwindSafe for DryocSealedBox<EncapsulatedKey, Mac, Data>
where EncapsulatedKey: RefUnwindSafe, Mac: RefUnwindSafe, Data: RefUnwindSafe,

§

impl<EncapsulatedKey, Mac, Data> Send for DryocSealedBox<EncapsulatedKey, Mac, Data>
where EncapsulatedKey: Send, Mac: Send, Data: Send,

§

impl<EncapsulatedKey, Mac, Data> Sync for DryocSealedBox<EncapsulatedKey, Mac, Data>
where EncapsulatedKey: Sync, Mac: Sync, Data: Sync,

§

impl<EncapsulatedKey, Mac, Data> Unpin for DryocSealedBox<EncapsulatedKey, Mac, Data>
where EncapsulatedKey: Unpin, Mac: Unpin, Data: Unpin,

§

impl<EncapsulatedKey, Mac, Data> UnsafeUnpin for DryocSealedBox<EncapsulatedKey, Mac, Data>
where EncapsulatedKey: UnsafeUnpin, Mac: UnsafeUnpin, Data: UnsafeUnpin,

§

impl<EncapsulatedKey, Mac, Data> UnwindSafe for DryocSealedBox<EncapsulatedKey, Mac, Data>
where EncapsulatedKey: UnwindSafe, Mac: UnwindSafe, Data: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

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

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.