Skip to main content

OpenedFile

Struct OpenedFile 

Source
pub struct OpenedFile {
    pub header: FixedHeader,
    pub tlvs: TlvSet,
    pub kek_index: usize,
    pub slot_index: u16,
    /* private fields */
}
Expand description

已打开的加密文件:头部已验证,FEK 已解包。

持有 FEK 与载荷密钥,可按需解密 TLV 与载荷块。析构时密钥自动擦除。

Fields§

§header: FixedHeader

固定头。

§tlvs: TlvSet

TLV 集合(value 仍为原始形态,加密条目未解密)。

§kek_index: usize

命中的 KEK 在候选列表中的下标。

§slot_index: u16

命中的 slot 序号。

Implementations§

Source§

impl OpenedFile

Source

pub const fn payload_key(&self) -> &SecretKey

载荷密钥。

Source

pub const fn fek(&self) -> &Fek

文件加密密钥。

Source

pub fn filename(&self) -> Result<String>

解密并还原原始文件名。

§Errors
Source

pub fn plain_extension(&self) -> Option<String>

明文后缀(若存在)。

Source

pub fn thumbnail(&self) -> Result<Vec<u8>>

解密缩略图。

§Errors

条目不存在或解密失败时返回错误。

Source

pub fn media_meta(&self) -> Result<Vec<u8>>

解密媒体元信息。

§Errors

条目不存在或解密失败时返回错误。

Source

pub fn moov_cache(&self) -> Result<Vec<u8>>

解密 MP4 的 moov box 副本。

起播时优先用它,可省掉「seek 到文件尾部读 moov」的额外往返。

§Errors

条目不存在或解密失败时返回错误。缺失是正常情况(非 MP4 文件、 或加密时未启用该优化),调用方应把错误当作「无缓存」而非故障。

Source

pub fn has_moov_cache(&self) -> bool

是否带有 moov 缓存。

与 Self::moov_cache 不同,这里只看条目存在性,不做解密, 因此可用于列表页的快速判断。

Source

pub fn has_media_meta(&self) -> bool

是否带有媒体元信息。

Source

pub fn has_thumbnail(&self) -> bool

是否带有缩略图。

只看条目存在性,不做解密。判断「有没有」不能靠解密是否成功: 解密失败也可能是文件损坏,那样会把损坏静默当成「没有缩略图」。

Source

pub fn stored_content_hash(&self) -> Result<[u8; 32]>

记录在 TLV 中的原始明文哈希。

§Errors

条目不存在、解密失败或长度不是 32 字节时返回错误。

Source

pub fn compression_index(&self) -> Result<Vec<CompressionIndexEntry>>

压缩索引表(仅压缩文件存在)。

§Errors

压缩文件缺少索引,或索引内容非法时返回错误。

Source

pub fn folder_index(&self) -> Result<ContainerIndex>

目录容器索引(仅容器文件存在)。

解析时会校验路径安全与载荷区间自洽——见 ContainerIndex::parse。

§Errors

非容器文件返回 Error::MissingTlv;索引内容非法时返回解析错误。

Source

pub const fn is_container(&self) -> bool

是否为目录容器。

Source

pub const fn is_slot_managed(&self) -> bool

是否为槽位可管理模式(规范 §3.5)。

Source

pub fn slot_directory(&self) -> Result<SlotDirectory>

解出槽位目录。

只有可管理模式的文件有。可否认模式下槽位设计上就不可枚举, 那不是缺功能——见 crate::slotdir 模块文档。

§Errors

可否认模式的文件返回 Error::MissingTlv;目录长度不对时返回 Error::MalformedTlv。

Source

pub fn raw_slot_directory(&self) -> Result<Vec<u8>>

槽位目录的原始字节,用于原样搬运。

与 Self::slot_directory 的区别同 raw_folder_index:改写 slot 区 时要把目录带过去,走 decode → encode 往返只会引入编码差异的风险。

§Errors

可否认模式的文件返回 Error::MissingTlv。

Source

pub fn raw_folder_index(&self) -> Result<Vec<u8>>

解密后的容器索引原始字节。

与 Self::folder_index 的区别:那个返回解析后的结构,用于读取内容; 这个返回未解析的字节,用于原样搬运(重新加密时)。走 parse → encode 往返会把索引重新序列化一遍,任何编码差异都会变成 「轮换后容器打不开」——而这种缺陷只在带容器的文件上出现,极难定位。

§Errors

非容器文件返回 Error::MissingTlv;解密失败时返回相应错误。

Source

pub fn decrypt_all(&self, file_bytes: &[u8]) -> Result<Vec<u8>>

解密全部载荷。

若文件写有内容哈希,会自动校验;不匹配返回 Error::ContentHashMismatch。

§Errors
Source

pub fn decrypt_all_with_progress( &self, file_bytes: &[u8], progress: Option<ProgressFn<'_>>, ) -> Result<Vec<u8>>

与 Self::decrypt_all 相同,但分块过程中回报进度。

§Errors

与 Self::decrypt_all 一致。

Trait Implementations§

Source§

impl Debug for OpenedFile

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