Skip to main content

DryocStream

Struct DryocStream 

Source
pub struct DryocStream<M> { /* private fields */ }
Expand description

Secret-key authenticated encrypted streams

Implementations§

Source§

impl<M> DryocStream<M>

Source

pub fn rekey(&mut self)

Rekeys the stream immediately. The sender and receiver must rekey at the same position.

Manual rekeying is unnecessary when the sender uses Tag::Rekey or Tag::Final, because those tags rekey after the message. The stream also rekeys if its internal counter wraps. See the libsodium documentation for details.

Source§

impl DryocStream<Push>

Source

pub fn init_push<Header: NewByteArray<CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_HEADERBYTES>, Key: ByteArray<CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_KEYBYTES>>( key: &Key, ) -> (Self, Header)

Returns a new push stream, initialized from key.

Source

pub fn push<Output: NewBytes + ResizableBytes, Input: Bytes + ?Sized>( &mut self, message: &Input, associated_data: Option<&[u8]>, tag: Tag, ) -> Result<Output, Error>

Encrypts message for this stream with associated_data and tag, returning the ciphertext.

§Errors

Returns an error if the message exceeds the stream’s maximum message length, or the output storage does not resize to exactly the required ciphertext length.

Source

pub fn push_to_vec<Input: Bytes + ?Sized>( &mut self, message: &Input, associated_data: Option<&[u8]>, tag: Tag, ) -> Result<Vec<u8>, Error>

Available on crate feature alloc only.

Encrypts message for this stream with associated_data and tag, returning the ciphertext.

§Errors

Returns an error if the message exceeds the stream’s maximum message length.

Source§

impl DryocStream<Pull>

Source

pub fn init_pull<Key: ByteArray<CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_KEYBYTES>, Header: ByteArray<CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_HEADERBYTES>>( key: &Key, header: &Header, ) -> Self

Returns a new pull stream, initialized from key and header.

Source

pub fn pull<Output: NewBytes + ResizableBytes, Input: Bytes + ?Sized>( &mut self, ciphertext: &Input, associated_data: Option<&[u8]>, ) -> Result<(Output, Tag), Error>

Decrypts ciphertext for this stream with associated_data, returning the decrypted message and tag.

§Errors

Returns an error if the ciphertext is too short or too long, the output storage cannot hold the plaintext, or authentication fails. Authentication fails for a wrong key or header, mismatched associated data, modified ciphertext, or messages processed out of order. An authenticated tag byte that is not one of the four Tag values is also rejected without advancing the stream.

Source

pub fn pull_to_vec<Input: Bytes + ?Sized>( &mut self, ciphertext: &Input, associated_data: Option<&[u8]>, ) -> Result<(Vec<u8>, Tag), Error>

Available on crate feature alloc only.

Decrypts ciphertext for this stream with associated_data, returning the decrypted message and tag into a Vec.

§Errors

Returns an error if the ciphertext is too short or too long, or authentication fails because the key, header, associated data, stream position, or ciphertext does not match. An authenticated tag byte that is not one of the four Tag values is also rejected without advancing the stream.

Trait Implementations§

Source§

impl<M: Clone> Clone for DryocStream<M>

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<M> Drop for DryocStream<M>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<M: Eq> Eq for DryocStream<M>

Source§

impl<M: PartialEq> PartialEq for DryocStream<M>

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<M: PartialEq> StructuralPartialEq for DryocStream<M>

Source§

impl<M> Zeroize for DryocStream<M>

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<M> Freeze for DryocStream<M>
where PhantomData<M>: Freeze,

§

impl<M> RefUnwindSafe for DryocStream<M>

§

impl<M> Send for DryocStream<M>
where PhantomData<M>: Send,

§

impl<M> Sync for DryocStream<M>
where PhantomData<M>: Sync,

§

impl<M> Unpin for DryocStream<M>
where PhantomData<M>: Unpin,

§

impl<M> UnsafeUnpin for DryocStream<M>

§

impl<M> UnwindSafe for DryocStream<M>

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