mirror of
https://github.com/telemt/telemt.git
synced 2026-04-25 14:34:10 +03:00
Add method to retrieve inner reader with pending plaintext
This commit introduces the `into_inner_with_pending_plaintext` method to the `FakeTlsReader` struct. This method allows users to extract the underlying reader along with any pending plaintext data that may have been buffered during the TLS reading process. The method handles the state transition and ensures that any buffered data is returned as a vector, facilitating easier management of plaintext data in TLS streams.
This commit is contained in:
@@ -250,6 +250,14 @@ impl<R> FakeTlsReader<R> {
|
||||
pub fn get_mut(&mut self) -> &mut R { &mut self.upstream }
|
||||
pub fn into_inner(self) -> R { self.upstream }
|
||||
|
||||
pub fn into_inner_with_pending_plaintext(mut self) -> (R, Vec<u8>) {
|
||||
let pending = match std::mem::replace(&mut self.state, TlsReaderState::Idle) {
|
||||
TlsReaderState::Yielding { buffer } => buffer.as_slice().to_vec(),
|
||||
_ => Vec::new(),
|
||||
};
|
||||
(self.upstream, pending)
|
||||
}
|
||||
|
||||
pub fn is_poisoned(&self) -> bool { self.state.is_poisoned() }
|
||||
pub fn state_name(&self) -> &'static str { self.state.state_name() }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user