pub struct TpmDevice { /* private fields */ }Implementations§
Source§impl TpmDevice
impl TpmDevice
Sourcepub fn open(
path: &Path,
interrupt_check: Box<dyn Fn() -> bool>,
) -> Result<Self, TpmDeviceError>
pub fn open( path: &Path, interrupt_check: Box<dyn Fn() -> bool>, ) -> Result<Self, TpmDeviceError>
Opens the TPM device file and sets it to non-blocking mode.
§Errors
Returns TpmDeviceError::Io if the device file cannot be opened and
TpmDeviceError::Nix if configuring the file descriptor flags fails.
Sourcepub fn transmit<C: TpmCommandObject>(
&mut self,
command: &C,
sessions: &[TpmsAuthCommand],
) -> Result<(TpmResponse, TpmAuthResponses), TpmDeviceError>
pub fn transmit<C: TpmCommandObject>( &mut self, command: &C, sessions: &[TpmsAuthCommand], ) -> Result<(TpmResponse, TpmAuthResponses), TpmDeviceError>
Performs the whole TPM command transmission process.
§Errors
Returns TpmDeviceError::Interrupted when the interrupt callback
requests cancellation.
Returns TpmDeviceError::Timeout when the TPM does not respond within
the configured timeout.
Returns TpmDeviceError::Io when a write, flush, or read operation on
the device file fails.
Returns TpmDeviceError::Nix when polling the device file descriptor
fails.
Returns TpmDeviceError::InvalidResponse or
TpmDeviceError::UnexpectedEof when the TPM reply is malformed,
truncated, or longer than the announced size.
Returns TpmDeviceError::Marshal or TpmDeviceError::Unmarshal
when encoding the command or decoding the response fails.
Returns TpmDeviceError::TpmRc when the TPM returns an error code.
Sourcepub fn get_capability<T, F, N>(
&mut self,
cap: TpmCap,
property_start: u32,
count: u32,
extract: F,
next_prop: N,
) -> Result<Vec<T>, TpmDeviceError>where
T: Copy,
F: for<'a> FnMut(&'a TpmuCapabilities) -> Result<&'a [T], TpmDeviceError>,
N: Fn(&T) -> u32,
pub fn get_capability<T, F, N>(
&mut self,
cap: TpmCap,
property_start: u32,
count: u32,
extract: F,
next_prop: N,
) -> Result<Vec<T>, TpmDeviceError>where
T: Copy,
F: for<'a> FnMut(&'a TpmuCapabilities) -> Result<&'a [T], TpmDeviceError>,
N: Fn(&T) -> u32,
Fetches a complete list of capabilities from the TPM, handling pagination.
§Errors
Propagates any TpmDeviceError returned by
TpmDevice::get_capability_page or by the extract closure.
Sourcepub fn fetch_algorithm_properties(
&mut self,
) -> Result<Vec<TpmsAlgProperty>, TpmDeviceError>
pub fn fetch_algorithm_properties( &mut self, ) -> Result<Vec<TpmsAlgProperty>, TpmDeviceError>
Retrieves all algorithm properties supported by the TPM.
§Errors
Returns TpmDeviceError::IntDecode if the handle count cannot be
represented as u32. Propagates any TpmDeviceError from
TpmDevice::get_capability, including
TpmDeviceError::CapabilityMissing when the TPM does not report
algorithm properties.
Sourcepub fn fetch_handles(
&mut self,
class: u32,
) -> Result<Vec<TpmHandleRef>, TpmDeviceError>
pub fn fetch_handles( &mut self, class: u32, ) -> Result<Vec<TpmHandleRef>, TpmDeviceError>
Retrieves all handles of a specific type from the TPM.
§Errors
Returns TpmDeviceError::IntDecode if the handle count cannot be
represented as u32. Propagates any TpmDeviceError from
TpmDevice::get_capability, including
TpmDeviceError::CapabilityMissing when the TPM does not report
handles of the requested class.
Sourcepub fn get_capability_page(
&mut self,
cap: TpmCap,
property: u32,
count: u32,
) -> Result<(bool, TpmsCapabilityData), TpmDeviceError>
pub fn get_capability_page( &mut self, cap: TpmCap, property: u32, count: u32, ) -> Result<(bool, TpmsCapabilityData), TpmDeviceError>
Fetches and returns one page of capabilities of a certain type from the TPM.
§Errors
Propagates any TpmDeviceError from TpmDevice::transmit. Returns
TpmDeviceError::ResponseMismatch when the TPM response does not
contain TPM2_GetCapability data.
Sourcepub fn get_tpm_property(
&mut self,
property: TpmPt,
) -> Result<u32, TpmDeviceError>
pub fn get_tpm_property( &mut self, property: TpmPt, ) -> Result<u32, TpmDeviceError>
Reads a specific TPM property.
§Errors
Returns TpmDeviceError::CapabilityMissing if the TPM does not report
the requested property. Propagates any TpmDeviceError from
TpmDevice::get_capability_page.
Sourcepub fn read_public(
&mut self,
handle: TpmHandle,
) -> Result<(TpmtPublic, Tpm2bName), TpmDeviceError>
pub fn read_public( &mut self, handle: TpmHandle, ) -> Result<(TpmtPublic, Tpm2bName), TpmDeviceError>
Reads the public area of a TPM object.
§Errors
Propagates any TpmDeviceError from TpmDevice::transmit. Returns
TpmDeviceError::ResponseMismatch when the TPM response does not
contain TPM2_ReadPublic data.
Sourcepub fn find_persistent(
&mut self,
target: &TpmtPublic,
) -> Result<Option<(TpmHandle, Tpm2bName)>, TpmDeviceError>
pub fn find_persistent( &mut self, target: &TpmtPublic, ) -> Result<Option<(TpmHandle, Tpm2bName)>, TpmDeviceError>
Finds a persistent handle by its public area.
§Errors
Propagates any TpmDeviceError from TpmDevice::fetch_handles and
TpmDevice::read_public, except for TPM reference and handle errors
with base TpmRcBase::ReferenceH0 or TpmRcBase::Handle, which are
treated as invalid handles and skipped.
Sourcepub fn find_persistent_by_name(
&mut self,
target_name: &Tpm2bName,
) -> Result<Option<TpmHandle>, TpmDeviceError>
pub fn find_persistent_by_name( &mut self, target_name: &Tpm2bName, ) -> Result<Option<TpmHandle>, TpmDeviceError>
Finds a persistent handle by its Tpm2bName.
§Errors
Propagates any TpmDeviceError from TpmDevice::fetch_handles and
TpmDevice::read_public, except for TPM reference and handle errors
with base TpmRcBase::ReferenceH0 or TpmRcBase::Handle, which are
treated as invalid handles and skipped. Returns
TpmDeviceError::InvalidCrypto when computing the calculated name
with tpm_make_name fails.
Sourcepub fn save_context(
&mut self,
save_handle: TpmHandle,
) -> Result<TpmsContext, TpmDeviceError>
pub fn save_context( &mut self, save_handle: TpmHandle, ) -> Result<TpmsContext, TpmDeviceError>
Saves the context of a transient object or session.
§Errors
Propagates any TpmDeviceError from TpmDevice::transmit. Returns
TpmDeviceError::ResponseMismatch when the TPM response does not
contain TPM2_ContextSave data.
Sourcepub fn load_context(
&mut self,
context: TpmsContext,
) -> Result<TpmHandle, TpmDeviceError>
pub fn load_context( &mut self, context: TpmsContext, ) -> Result<TpmHandle, TpmDeviceError>
Loads a TPM context and returns the handle.
§Errors
Propagates any TpmDeviceError from TpmDevice::transmit. Returns
TpmDeviceError::ResponseMismatch when the TPM response does not
contain TPM2_ContextLoad data.
Sourcepub fn flush_context(&mut self, handle: TpmHandle) -> Result<(), TpmDeviceError>
pub fn flush_context(&mut self, handle: TpmHandle) -> Result<(), TpmDeviceError>
Flushes a transient object or session from the TPM and removes it from the cache.
§Errors
Propagates any TpmDeviceError from TpmDevice::transmit.
Sourcepub fn flush_session(
&mut self,
context: TpmsContext,
) -> Result<(), TpmDeviceError>
pub fn flush_session( &mut self, context: TpmsContext, ) -> Result<(), TpmDeviceError>
Loads a session context and then flushes the resulting handle.
§Errors
Propagates any TpmDeviceError from TpmDevice::load_context or
TpmDevice::flush_context except for TPM reference errors with base
TpmRcBase::ReferenceH0 or TpmRcBase::Handle, which are treated
as a successful no-op.
Sourcepub fn evict_control(
&mut self,
auth: TpmHandle,
object_handle: TpmHandle,
persistent_handle: TpmHandle,
sessions: &[TpmsAuthCommand],
) -> Result<(), TpmDeviceError>
pub fn evict_control( &mut self, auth: TpmHandle, object_handle: TpmHandle, persistent_handle: TpmHandle, sessions: &[TpmsAuthCommand], ) -> Result<(), TpmDeviceError>
Evicts a persistent object or makes a transient object persistent.
§Errors
Propagates any TpmDeviceError from TpmDevice::transmit. Returns
TpmDeviceError::ResponseMismatch when the TPM response does not
contain TPM2_EvictControl data.
Sourcepub fn refresh_key(
&mut self,
context: TpmsContext,
) -> Result<bool, TpmDeviceError>
pub fn refresh_key( &mut self, context: TpmsContext, ) -> Result<bool, TpmDeviceError>
Refreshes a key context. Returns true if the context is still valid,
and false if it is stale.
§Errors
Propagates any TpmDeviceError from TpmDevice::load_context or
TpmDevice::flush_context except for TPM reference errors with base
TpmRcBase::ReferenceH0, which are treated as a stale context and
reported as Ok(false).