Skip to main content

Tpml

Struct Tpml 

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

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

Implementations§

Source§

impl<const CAPACITY: usize> Tpml<CAPACITY>

Source

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

Casts a byte slice into a TPML wire view.

§Errors

Returns UnexpectedEnd when buf is shorter than the TPML count field. Returns TooManyItems when the declared item count exceeds CAPACITY.

Source

pub fn cast_items<T: TpmCast + ?Sized>(buf: &[u8]) -> TpmResult<&Self>

Casts a byte slice into a typed TPML wire view.

§Errors

Returns Err(TpmError) when the TPML header is malformed, the declared count exceeds CAPACITY, or the typed item area is malformed.

Source

pub fn cast_prefix_items<T: TpmCast + ?Sized>( buf: &[u8], ) -> TpmResult<(&Self, &[u8])>

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

§Errors

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

Source

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

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

§Errors

Returns UnexpectedEnd when buf is shorter than the TPML count field. Returns TooManyItems when the declared item count exceeds CAPACITY.

Source

pub fn cast_items_mut<T: TpmCast + ?Sized>( buf: &mut [u8], ) -> TpmResult<&mut Self>

Casts a mutable byte slice into a typed TPML wire view.

§Errors

Returns Err(TpmError) when the TPML header is malformed, the declared count exceeds CAPACITY, or the typed item area is malformed.

Source

pub fn cast_prefix_items_mut<T: TpmCast + ?Sized>( buf: &mut [u8], ) -> TpmResult<(&mut Self, &mut [u8])>

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

§Errors

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

Source

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

Returns the complete TPML byte representation.

Source

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

Returns the complete mutable TPML byte representation.

Source

pub fn count(&self) -> usize

Returns the declared item count.

Source

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

Returns the bytes after the count field.

Source

pub fn items<T: TpmCast + ?Sized>(&self) -> TpmlIter<'_, T>

Returns an iterator over typed borrowed items.

Source

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

Returns the mutable bytes after the count field.

Source

pub const fn len(&self) -> usize

Returns the complete TPML wire length.

Source

pub fn is_empty(&self) -> bool

Returns true when the declared item count is zero.

Source

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

Validates a TPML header and declared count.

§Errors

Returns Err(TpmError) when the count field is missing or exceeds CAPACITY.

Source

pub fn validate_items<T: TpmCast + ?Sized>(buf: &[u8]) -> TpmResult<()>

Validates a typed TPML wire value.

§Errors

Returns Err(TpmError) when the TPML header or typed item area is malformed.

Source

pub fn validate_prefix_items<T: TpmCast + ?Sized>( buf: &[u8], ) -> TpmResult<usize>

Validates the first typed TPML wire value and returns its wire length.

§Errors

Returns Err(TpmError) when the TPML header or typed item area is malformed.

Source§

impl<const CAPACITY: usize> Tpml<CAPACITY>

Source

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

Casts a byte slice into this wire view without validation.

§Safety

The caller must ensure buf satisfies every invariant required by the checked constructors for this view.

Source

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

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

§Safety

The caller must ensure buf satisfies every invariant required by the checked constructors for this view. The returned reference inherits the exclusive access represented by buf.

Trait Implementations§

Source§

impl<const CAPACITY: usize> AsMut<[u8]> for Tpml<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 Tpml<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 Tpml<CAPACITY>

Source§

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

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

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

Casts buf into Self without 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§

impl<const CAPACITY: usize> TpmCastMut for Tpml<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§

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

Casts buf into mutable Self without 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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<const CAPACITY: usize> UnwindSafe for Tpml<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