pub struct TpmResponder { /* private fields */ }Expand description
The responder end of a TpmTransport, for serving TPM commands.
Where a TpmDevice sends commands and receives responses, a TpmResponder
receives commands and sends responses. Both ends share the same transport
and frame codec; only the direction of use differs, which makes this crate
usable for the TPM side of an exchange, such as an emulator.
Command decoding and response marshaling are left to the caller (for example
via tpm2_protocol), keeping this type focused on transport and framing.
Implementations§
Source§impl TpmResponder
impl TpmResponder
Sourcepub fn new(transport: Box<dyn TpmTransport>) -> Self
pub fn new(transport: Box<dyn TpmTransport>) -> Self
Creates a TpmResponder serving over the given transport.
Sourcepub fn recv_command(&mut self) -> Result<&[u8], TpmDeviceError>
pub fn recv_command(&mut self) -> Result<&[u8], TpmDeviceError>
Receives the next command frame, returning its raw bytes.
§Errors
Returns UnexpectedEof when the
peer disconnects, or other TpmDeviceError
variants when the transport fails.
Sourcepub fn send_response(&mut self, frame: &[u8]) -> Result<(), TpmDeviceError>
pub fn send_response(&mut self, frame: &[u8]) -> Result<(), TpmDeviceError>
Sends a marshaled response frame.
§Errors
Returns a TpmDeviceError when the transport
fails to send the frame.
Sourcepub fn serve<H>(&mut self, handler: H) -> Result<(), TpmDeviceError>
pub fn serve<H>(&mut self, handler: H) -> Result<(), TpmDeviceError>
Serves commands until the peer disconnects.
Each received command frame is passed to handler, whose returned bytes
are written back as the response frame. Returns Ok(()) once the peer
closes the transport.
§Errors
Returns a TpmDeviceError when receiving a
command or sending a response fails for any reason other than a clean
disconnect.