pub struct FileHeader { /* private fields */ }Expand description
Complete v2 file header.
The serialized layout matches v1 byte for byte, but the version byte is 2
and the fixed fields are authenticated: they are bound as associated data
to both AEAD operations via HeaderBinding.
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 (2) | 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 |
| content_nonce | 24 bytes |
| filename_nonce | 24 bytes |
| filename_ciphertext_length | 2 bytes |
| filename_ciphertext | variable |
Implementations§
Source§impl FileHeader
impl FileHeader
Sourcepub fn new(
salt: [u8; 16],
kdf_params: KeyDerivationParams,
content_nonce: [u8; 24],
filename_nonce: [u8; 24],
filename_ciphertext: Vec<u8>,
) -> Result<Self, HeaderError>
pub fn new( salt: [u8; 16], kdf_params: KeyDerivationParams, content_nonce: [u8; 24], filename_nonce: [u8; 24], filename_ciphertext: Vec<u8>, ) -> Result<Self, HeaderError>
Builds a v2 header. Fails with HeaderError::FilenameTooLong if the
filename ciphertext does not fit the u16 length field, instead of
silently truncating.
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 content_nonce(&self) -> &[u8; 24]
pub fn filename_nonce(&self) -> &[u8; 24]
pub fn filename_ciphertext(&self) -> &[u8] ⓘ
Sourcepub fn decrypt_content(
&self,
ciphertext: &[u8],
key: &SecureKey,
) -> Result<SecureBytes, FileError>
pub fn decrypt_content( &self, ciphertext: &[u8], key: &SecureKey, ) -> Result<SecureBytes, FileError>
Decrypts a content ciphertext under this header’s content nonce, verifying the header binding under the content domain.
Sourcepub fn decrypt_filename(
&self,
key: &SecureKey,
) -> Result<SecureString, FileError>
pub fn decrypt_filename( &self, key: &SecureKey, ) -> Result<SecureString, FileError>
Decrypts the original filename stored in this header, verifying the header binding under the filename 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