TpmDevice

Struct TpmDevice 

Source
pub struct TpmDevice { /* private fields */ }

Implementations§

Source§

impl TpmDevice

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Trait Implementations§

Source§

impl Debug for TpmDevice

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more