Skip to main content

Tpm2b

Struct Tpm2b 

Source
pub struct Tpm2b<const CAPACITY: usize>(/* private fields */);
Expand description

A zero-copy TPM2B wire view over caller-owned bytes.

Implementations§

Source§

impl<const CAPACITY: usize> Tpm2b<CAPACITY>

Source

pub fn cast(buf: &[u8]) -> TpmResult<&Self>

Casts a byte slice into a TPM2B wire view.

§Errors

Returns UnexpectedEnd when buf is shorter than the TPM2B header or declared payload size. Returns TrailingData when buf contains bytes after the declared payload. Returns TooManyBytes when the declared payload exceeds CAPACITY.

Source

pub fn cast_prefix(buf: &[u8]) -> TpmResult<(&Self, &[u8])>

Casts the first TPM2B value in a byte slice into a wire view.

§Errors

Returns Err(TpmError) when the first TPM2B value is malformed.

Source

pub unsafe fn cast_unchecked(buf: &[u8]) -> &Self

Casts a byte slice into a TPM2B wire view without validation.

§Safety

The caller must ensure that buf contains exactly one complete TPM2B value and that its declared payload length does not exceed CAPACITY.

Source

pub fn cast_mut(buf: &mut [u8]) -> TpmResult<&mut Self>

Casts a mutable byte slice into a mutable TPM2B wire view.

§Errors

Returns UnexpectedEnd when buf is shorter than the TPM2B header or declared payload size. Returns TrailingData when buf contains bytes after the declared payload. Returns TooManyBytes when the declared payload exceeds CAPACITY.

Source

pub fn cast_prefix_mut(buf: &mut [u8]) -> TpmResult<(&mut Self, &mut [u8])>

Casts the first mutable TPM2B value in a byte slice into a wire view.

§Errors

Returns Err(TpmError) when the first TPM2B value is malformed.

Source

pub unsafe fn cast_mut_unchecked(buf: &mut [u8]) -> &mut Self

Casts a mutable byte slice into a mutable TPM2B wire view without validation.

§Safety

The caller must ensure that buf contains exactly one complete TPM2B value and that its declared payload length does not exceed CAPACITY. The returned reference inherits the exclusive access represented by buf.

Source

pub const fn as_bytes(&self) -> &[u8]

Returns the complete TPM2B byte representation.

Source

pub fn as_bytes_mut(&mut self) -> &mut [u8]

Returns the complete mutable TPM2B byte representation.

Source

pub fn size(&self) -> usize

Returns the declared payload size.

Source

pub fn data(&self) -> &[u8]

Returns the payload bytes.

Source

pub fn payload(&self) -> &[u8]

Returns the payload bytes, as an alias for Self::data.

Source

pub fn data_mut(&mut self) -> &mut [u8]

Returns the mutable payload bytes.

Source

pub fn payload_mut(&mut self) -> &mut [u8]

Returns the mutable payload bytes, as an alias for Self::data_mut.

Source

pub const fn len(&self) -> usize

Returns the complete TPM2B wire length.

Source

pub fn is_empty(&self) -> bool

Returns true when the TPM2B payload is empty.

Source

pub fn validate(buf: &[u8]) -> TpmResult<()>

Validates an exact TPM2B wire value.

§Errors

Returns Err(TpmError) when the TPM2B value is malformed or has trailing data.

Source

pub fn validate_prefix(buf: &[u8]) -> TpmResult<usize>

Validates the first TPM2B wire value and returns its wire length.

§Errors

Returns Err(TpmError) when the first TPM2B value is malformed.

Trait Implementations§

Source§

impl<const CAPACITY: usize> AsMut<[u8]> for Tpm2b<CAPACITY>

Source§

fn as_mut(&mut self) -> &mut [u8]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<const CAPACITY: usize> AsRef<[u8]> for Tpm2b<CAPACITY>

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<const CAPACITY: usize> TpmCast for Tpm2b<CAPACITY>

Source§

fn cast(buf: &[u8]) -> TpmResult<&Self>

Casts buf into Self after validating the wire-view invariants. Read more
Source§

fn cast_prefix(buf: &[u8]) -> TpmResult<(&Self, &[u8])>

Casts the first wire value in buf into Self and returns the remainder. Read more
Source§

unsafe fn cast_unchecked(buf: &[u8]) -> &Self

Casts buf into Self without validating the wire-view invariants. Read more
Source§

impl<const CAPACITY: usize> TpmCastMut for Tpm2b<CAPACITY>

Source§

fn cast_mut(buf: &mut [u8]) -> TpmResult<&mut Self>

Casts buf into mutable Self after validating the wire-view invariants. Read more
Source§

fn cast_prefix_mut(buf: &mut [u8]) -> TpmResult<(&mut Self, &mut [u8])>

Casts the first mutable wire value in buf into Self and returns the remainder. Read more
Source§

unsafe fn cast_mut_unchecked(buf: &mut [u8]) -> &mut Self

Casts buf into mutable Self without validating the wire-view invariants. Read more

Auto Trait Implementations§

§

impl<const CAPACITY: usize> !Sized for Tpm2b<CAPACITY>

§

impl<const CAPACITY: usize> Freeze for Tpm2b<CAPACITY>

§

impl<const CAPACITY: usize> RefUnwindSafe for Tpm2b<CAPACITY>

§

impl<const CAPACITY: usize> Send for Tpm2b<CAPACITY>

§

impl<const CAPACITY: usize> Sync for Tpm2b<CAPACITY>

§

impl<const CAPACITY: usize> Unpin for Tpm2b<CAPACITY>

§

impl<const CAPACITY: usize> UnsafeUnpin for Tpm2b<CAPACITY>

§

impl<const CAPACITY: usize> UnwindSafe for Tpm2b<CAPACITY>

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<'a, T> TpmField<'a> for T
where T: TpmCast + 'a + ?Sized,

Source§

type View = &'a T

Source§

fn cast_prefix_field( buf: &'a [u8], ) -> Result<(<T as TpmField<'a>>::View, &'a [u8]), TpmError>

Reads the first field from buf and returns the remaining bytes. Read more