Skip to main content

FixedHeader

Struct FixedHeader 

Source
pub struct FixedHeader {
Show 18 fields pub version_major: u16, pub version_minor: u16, pub header_len: u32, pub file_uuid: [u8; 16], pub vault_salt: [u8; 16], pub flags: u32, pub cipher_id: CipherId, pub kdf_id: u8, pub compress_id: u8, pub slot_count: u8, pub argon2_m_kib: u32, pub argon2_t: u32, pub argon2_p: u32, pub chunk_size: u32, pub plaintext_size: u64, pub base_nonce: [u8; 7], pub chunk_version: u8, pub tlv_len: u32,
}
Expand description

Fixed Header(96 字节)。

Fields§

§version_major: u16

格式主版本。

§version_minor: u16

格式次版本。

§header_len: u32

从文件起始到载荷起始的总字节数。

§file_uuid: [u8; 16]

文件唯一标识,用于 nonce 派生、AAD 绑定、分片归属。

§vault_salt: [u8; 16]

Argon2id 盐,同一 vault 内所有文件相同。

§flags: u32

位标志,见 flags。

§cipher_id: CipherId

AEAD 算法。

§kdf_id: u8

KDF 算法,当前仅 Argon2id。

§compress_id: u8

压缩算法。

§slot_count: u8

key slot 数量,固定为 8。

§argon2_m_kib: u32

Argon2 内存成本(KiB)。

§argon2_t: u32

Argon2 迭代次数。

§argon2_p: u32

Argon2 并行度。

§chunk_size: u32

明文分块大小。

§plaintext_size: u64

原始明文总长度。

§base_nonce: [u8; 7]

随机 nonce 前缀,与块序号组合成完整 nonce。

§chunk_version: u8

保留给未来的就地编辑功能,当前必须为 0。

§tlv_len: u32

TLV 区总字节数。

Implementations§

Source§

impl FixedHeader

Source

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

解析 Fixed Header。

按规范 §9 步骤 1–3 的顺序校验:先 magic,再版本,最后字段一致性。 版本检查必须在字段解析之前完成——否则可能按错误的布局解读未来版本的头部。

§Errors
Source

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

校验字段自洽性与解析上界。

上界校验在分配任何内存之前完成,这样恶意头部无法通过声明巨大长度 触发大额分配(见 docs/research/07-platform-and-sidechannels.md §8.3)。

§Errors

任一字段非法、超出解析上界,或字段间矛盾时返回 Error::MalformedHeader。

Source

pub fn to_bytes(&self) -> Result<[u8; 96]>

序列化为 96 字节。

§Errors

字段非法时返回 Error::MalformedHeader。

Source

pub const fn n_chunks(&self) -> u64

载荷块总数。空文件也有 1 块。

Source

pub const fn has_flag(&self, flag: u32) -> bool

是否置位了指定 flag。

Source

pub const fn argon2_params(&self) -> Argon2Params

头部记录的 Argon2 参数。

解密时必须用文件里记录的参数派生 KEK,不能用当前的默认档位—— 文件可能是用别的档位加密的,用错参数会得到完全不同的 KEK。

Source

pub fn chunk_ct_range(&self, index: u64) -> Result<(u64, u64)>

未压缩载荷中第 index 块密文的 (偏移, 长度)。

这是视频任意 seek 的数学基础:无需索引表,O(1) 定位。

ct_offset(i) = header_len + i × (chunk_size + 16)
ct_len(i)    = min(chunk_size, plaintext_size - i × chunk_size) + 16
§Errors
Source

pub const fn chunk_index_of(&self, plain_offset: u64) -> u64

明文偏移所属的块序号。

chunk_size 为 0 时返回 0。正常文件不会出现该值(Self::validate 已拒绝), 这里只是避免除零 panic。

Trait Implementations§

Source§

impl Clone for FixedHeader

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 FixedHeader

Source§

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

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

impl Eq for FixedHeader

Source§

impl PartialEq for FixedHeader

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 FixedHeader

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.