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: TlvSetTLV 集合(value 仍为原始形态,加密条目未解密)。
kek_index: usize命中的 KEK 在候选列表中的下标。
slot_index: u16命中的 slot 序号。
Implementations§
Source§impl OpenedFile
impl OpenedFile
Sourcepub const fn payload_key(&self) -> &SecretKey
pub const fn payload_key(&self) -> &SecretKey
载荷密钥。
Sourcepub fn plain_extension(&self) -> Option<String>
pub fn plain_extension(&self) -> Option<String>
明文后缀(若存在)。
Sourcepub fn moov_cache(&self) -> Result<Vec<u8>>
pub fn moov_cache(&self) -> Result<Vec<u8>>
解密 MP4 的 moov box 副本。
起播时优先用它,可省掉「seek 到文件尾部读 moov」的额外往返。
§Errors
条目不存在或解密失败时返回错误。缺失是正常情况(非 MP4 文件、 或加密时未启用该优化),调用方应把错误当作「无缓存」而非故障。
Sourcepub fn has_moov_cache(&self) -> bool
pub fn has_moov_cache(&self) -> bool
是否带有 moov 缓存。
与 Self::moov_cache 不同,这里只看条目存在性,不做解密,
因此可用于列表页的快速判断。
Sourcepub fn has_media_meta(&self) -> bool
pub fn has_media_meta(&self) -> bool
是否带有媒体元信息。
Sourcepub fn has_thumbnail(&self) -> bool
pub fn has_thumbnail(&self) -> bool
是否带有缩略图。
只看条目存在性,不做解密。判断「有没有」不能靠解密是否成功: 解密失败也可能是文件损坏,那样会把损坏静默当成「没有缩略图」。
Sourcepub fn stored_content_hash(&self) -> Result<[u8; 32]>
pub fn stored_content_hash(&self) -> Result<[u8; 32]>
Sourcepub fn compression_index(&self) -> Result<Vec<CompressionIndexEntry>>
pub fn compression_index(&self) -> Result<Vec<CompressionIndexEntry>>
Sourcepub fn folder_index(&self) -> Result<ContainerIndex>
pub fn folder_index(&self) -> Result<ContainerIndex>
目录容器索引(仅容器文件存在)。
解析时会校验路径安全与载荷区间自洽——见
ContainerIndex::parse。
§Errors
非容器文件返回 Error::MissingTlv;索引内容非法时返回解析错误。
Sourcepub const fn is_container(&self) -> bool
pub const fn is_container(&self) -> bool
是否为目录容器。
Sourcepub const fn is_slot_managed(&self) -> bool
pub const fn is_slot_managed(&self) -> bool
是否为槽位可管理模式(规范 §3.5)。
Sourcepub fn slot_directory(&self) -> Result<SlotDirectory>
pub fn slot_directory(&self) -> Result<SlotDirectory>
解出槽位目录。
只有可管理模式的文件有。可否认模式下槽位设计上就不可枚举,
那不是缺功能——见 crate::slotdir 模块文档。
§Errors
可否认模式的文件返回 Error::MissingTlv;目录长度不对时返回
Error::MalformedTlv。
Sourcepub fn raw_slot_directory(&self) -> Result<Vec<u8>>
pub fn raw_slot_directory(&self) -> Result<Vec<u8>>
槽位目录的原始字节,用于原样搬运。
与 Self::slot_directory 的区别同 raw_folder_index:改写 slot 区
时要把目录带过去,走 decode → encode 往返只会引入编码差异的风险。
§Errors
可否认模式的文件返回 Error::MissingTlv。
Sourcepub fn raw_folder_index(&self) -> Result<Vec<u8>>
pub fn raw_folder_index(&self) -> Result<Vec<u8>>
解密后的容器索引原始字节。
与 Self::folder_index 的区别:那个返回解析后的结构,用于读取内容;
这个返回未解析的字节,用于原样搬运(重新加密时)。走
parse → encode 往返会把索引重新序列化一遍,任何编码差异都会变成
「轮换后容器打不开」——而这种缺陷只在带容器的文件上出现,极难定位。
§Errors
非容器文件返回 Error::MissingTlv;解密失败时返回相应错误。
Sourcepub fn decrypt_all(&self, file_bytes: &[u8]) -> Result<Vec<u8>>
pub fn decrypt_all(&self, file_bytes: &[u8]) -> Result<Vec<u8>>
解密全部载荷。
若文件写有内容哈希,会自动校验;不匹配返回 Error::ContentHashMismatch。
§Errors
Error::ChunkAuthFailed:某块认证失败Error::ContentHashMismatch:内容哈希校验失败