pub struct TokenOpenStream { /* private fields */ }Expand description
token_open_in_place for a token landing in contiguous spans: absorb_to authenticates and decrypts each span in place as it grows, and finalize verifies the MAC in constant time before inspecting any padding, then names the plaintext.
The final ciphertext block waits for that verdict too, so nothing padding-shaped is ever examined ahead of authentication. Callers must not release a decrypted byte before finalize.
Implementations§
Source§impl TokenOpenStream
impl TokenOpenStream
Sourcepub fn begin(
key: &TokenKey<'_>,
iv: &[u8; 16],
token_len: usize,
) -> Result<TokenOpenStream, TokenOpenError>
pub fn begin( key: &TokenKey<'_>, iv: &[u8; 16], token_len: usize, ) -> Result<TokenOpenStream, TokenOpenError>
token_len is the whole token’s length; the shapes refused are exactly token_open_in_place’s Malformed.
Sourcepub fn pending_span(&self, contiguous_byte_len: usize) -> Range<usize> ⓘ
pub fn pending_span(&self, contiguous_byte_len: usize) -> Range<usize> ⓘ
The whole-block span absorb_to would process next, in token coordinates: everything past earlier calls up to contiguous_byte_len, minus the held-back final block.
Empty when nothing is absorbable yet.
Sourcepub fn fully_absorbed(&self) -> bool
pub fn fully_absorbed(&self) -> bool
Whether every span before the held-back final block has been absorbed — all that finalize requires.
Sourcepub fn absorb_to<'t>(
&mut self,
token: &'t mut [u8],
contiguous_byte_len: usize,
) -> &'t [u8] ⓘ
pub fn absorb_to<'t>( &mut self, token: &'t mut [u8], contiguous_byte_len: usize, ) -> &'t [u8] ⓘ
Authenticate then decrypt the token’s contiguous prefix past what earlier calls covered, whole blocks at a time, returning the bytes decrypted by this call. token is the same buffer every call, filled at least to contiguous_byte_len.
Sourcepub fn absorb_span(&mut self, span: &mut [u8])
pub fn absorb_span(&mut self, span: &mut [u8])
absorb_to for a span carried away from its token — exactly the bytes pending_span named, handed as their own slice and decrypted in place there.
The offloading caller owns copying them back where they came from.
Sourcepub fn finalize(self, token: &mut [u8]) -> Result<&[u8], TokenOpenError>
pub fn finalize(self, token: &mut [u8]) -> Result<&[u8], TokenOpenError>
The MAC is verified in constant time before the held-back final block is decrypted and its padding inspected, preserving token_open_in_place’s refusal order.