Skip to main content

TlvSet

Struct TlvSet 

Source
pub struct TlvSet { /* private fields */ }
Expand description

TLV 区的集合。保留原始顺序,以便重写文件时保持字节稳定。

Implementations§

Source§

impl TlvSet

Source

pub const fn new() -> Self

空集合。

Source

pub fn push(&mut self, e: TlvEntry) -> &mut Self

追加条目。

Source

pub fn entries(&self) -> &[TlvEntry]

全部条目。

Source

pub fn len(&self) -> usize

条目数量。

Source

pub fn is_empty(&self) -> bool

是否为空。

Source

pub fn find(&self, tlv_type: u16) -> Option<&TlvEntry>

按类型查找第一个条目。

Source

pub fn encoded_len(&self) -> usize

编码后的总字节数。

Source

pub fn parse(data: &[u8]) -> Result<Self>

解析 TLV 区。

只做结构解析,不检查未知 CRITICAL 类型——那需要在 MAC 验证通过之后再做, 见 TlvSet::check_critical。

条目数受 parse_limits::MAX_TLV_ENTRIES 限制,防止大量零长度条目耗尽内存。

§Errors
Source

pub fn check_critical(&self) -> Result<()>

检查是否存在未知且 CRITICAL 的条目。

规范 §9 步骤 7 要求此时拒绝打开文件。私有区间(≥ 0x8000)的未知类型即使标记 CRITICAL 也应忽略,因为那是第三方实现的自用字段。

§Errors

存在未知 CRITICAL 条目时返回 Error::UnknownCriticalTlv。

Source

pub fn to_bytes(&self) -> Vec<u8> ⓘ

序列化。

Source

pub fn decrypt_value( &self, tlv_type: u16, fek: &Fek, cipher: CipherId, ) -> Result<Vec<u8>>

解密某个加密条目的 value。

§Errors

Trait Implementations§

Source§

impl Clone for TlvSet

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TlvSet

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for TlvSet

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for TlvSet

Source§

impl PartialEq for TlvSet

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TlvSet

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.