pub struct FileHeader { /* private fields */ }Expand description
Complete v3 file header.
Differences from v2: the content is encrypted as a sequence of AEAD
chunks (see crate::v3::stream) using a 16-byte nonce prefix stored
here, and the bare filename ciphertext is replaced by an encrypted
metadata envelope carrying the filename plus optional mtime and Unix
mode. All fixed fields are authenticated as associated data via
HeaderBinding, with distinct domains for metadata and content.
The struct holds only the header’s actual information content; the layout artifacts of the serialized form (magic, version byte, length fields) are computed during (de)serialization and never stored.
Serialized layout:
| field | size |
|---|---|
| magic (“SHADOW”) | 6 bytes |
| version (3) | 1 byte |
| header_length | 4 bytes |
| salt | 16 bytes |
| kdf_memory | 4 bytes |
| kdf_iterations | 4 bytes |
| kdf_parallelism | 4 bytes |
| kdf_key_length | 1 byte |
| nonce_prefix | 16 bytes |
| chunk_size | 4 bytes |
| metadata_nonce | 24 bytes |
| metadata_ciphertext_length | 2 bytes |
| metadata_ciphertext | variable |
Implementations§
Source§impl FileHeader
impl FileHeader
Sourcepub fn new(
salt: [u8; 16],
kdf_params: KeyDerivationParams,
nonce_prefix: [u8; 16],
chunk_size: u32,
metadata_nonce: [u8; 24],
metadata_ciphertext: Vec<u8>,
) -> Result<Self, HeaderError>
pub fn new( salt: [u8; 16], kdf_params: KeyDerivationParams, nonce_prefix: [u8; 16], chunk_size: u32, metadata_nonce: [u8; 24], metadata_ciphertext: Vec<u8>, ) -> Result<Self, HeaderError>
Builds a v3 header. Fails with HeaderError::MetadataTooLong if the
metadata ciphertext does not fit the u16 length field, and with
HeaderError::InvalidData for a chunk size outside
1..=MAX_ACCEPTED_CHUNK_SIZE.
Sourcepub fn header_length(&self) -> usize
pub fn header_length(&self) -> usize
Total length of this header’s serialized form.
pub fn serialize(&self) -> Vec<u8> ⓘ
pub fn try_deserialize(bytes: &[u8]) -> Result<FileHeader, HeaderError>
pub fn salt(&self) -> &[u8; 16]
Sourcepub fn kdf_params(&self) -> &KeyDerivationParams
pub fn kdf_params(&self) -> &KeyDerivationParams
The key derivation parameters recorded in this header.
pub fn nonce_prefix(&self) -> &[u8; 16]
pub fn chunk_size(&self) -> u32
pub fn metadata_nonce(&self) -> &[u8; 24]
pub fn metadata_ciphertext(&self) -> &[u8] ⓘ
Sourcepub fn decrypt_metadata(
&self,
key: &SecureKey,
) -> Result<FileMetadata, FileError>
pub fn decrypt_metadata( &self, key: &SecureKey, ) -> Result<FileMetadata, FileError>
Decrypts and parses the metadata envelope stored in this header, verifying the header binding under the metadata domain.
Sourcepub fn binding(&self) -> HeaderBinding<'_>
pub fn binding(&self) -> HeaderBinding<'_>
The header binding used as associated data for this header’s AEAD operations.
Trait Implementations§
Source§impl Clone for FileHeader
impl Clone for FileHeader
Source§fn clone(&self) -> FileHeader
fn clone(&self) -> FileHeader
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more