pub struct Simulator {
pub(crate) _priv: (),
}
Expand description
A libtpm2-based TPM simulator.
At most one simulator may exist per process because libtpm2 uses a static global response buffer.
Examples
let mut simulator = tpm2::Simulator::singleton_in_current_directory();
let command = &[ /* ... */ ];
let response = simulator.execute_command(command);
println!("{:?}", response);
Fields§
§_priv: ()
Implementations§
source§impl Simulator
impl Simulator
sourcepub fn singleton_in_current_directory() -> Self
pub fn singleton_in_current_directory() -> Self
Initializes a TPM simulator in the current working directory.
Panics
Panics if a TPM simulator has already been initialized by this process.
sourcepub fn execute_command<'a>(&'a mut self, command: &[u8]) -> &'a [u8] ⓘ
pub fn execute_command<'a>(&'a mut self, command: &[u8]) -> &'a [u8] ⓘ
Sends a TPM command to the TPM simulator, waits for the work to be performed, and receives back the TPM response.
Executing a command requires exclusive access to the TPM simulator because it mutates libtpm2 static state.
The returned response buffer remains valid until the next TPM command is executed.