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
impl PushState
Sourcepub fn init(key: &Key) -> Result<(Self, [u8; 32]), SecretstreamError>
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.
pub fn is_finalized(&self) -> bool
Sourcepub fn push(
&mut self,
tag: Tag,
plaintext: &[u8],
ciphertext_out: &mut [u8],
) -> Result<[u8; 16], SecretstreamError>
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.