Skip to main content

PushState

Struct PushState 

Source
pub struct PushState { /* private fields */ }
Expand description

Encrypting half of a crypto_secretstream session - produced by PushState::init, driven one chunk at a time by PushState::push.

Implementations§

Source§

impl PushState

Source

pub fn init(key: &Key) -> Result<(Self, [u8; 32]), SecretstreamError>

Starts a new stream under key, drawing a fresh random header from the OS CSPRNG. The returned header must be transmitted/stored alongside the chunks - PullState::init needs it to re-derive the same initial subkey.

§Errors

Returns SecretstreamError::Random if the OS CSPRNG fails.

Source

pub fn is_finalized(&self) -> bool

Source

pub fn push( &mut self, tag: Tag, plaintext: &[u8], ciphertext_out: &mut [u8], ) -> Result<[u8; 16], SecretstreamError>

Encrypts plaintext into ciphertext_out (same length) and returns the 16-byte authentication tag for this chunk. tag becomes part of this chunk’s AAD (see the module doc) - the caller must transmit both the ciphertext, the returned tag, and tag.to_byte() for PullState::pull to recover the plaintext.

§Errors

Returns SecretstreamError::InvalidLength if ciphertext_out.len() != plaintext.len(), or SecretstreamError::StreamFinalized if a previous chunk already used Tag::Final.

Trait Implementations§

Source§

impl Drop for PushState

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

Auto Trait Implementations§

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

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.