pub struct FileHeader {
salt: [u8; 16],
kdf_params: KeyDerivationParams,
content_nonce: [u8; 24],
filename_nonce: [u8; 24],
filename_ciphertext: Vec<u8>,
}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 |
Fields§
§salt: [u8; 16]§kdf_params: KeyDerivationParams§content_nonce: [u8; 24]§filename_nonce: [u8; 24]§filename_ciphertext: Vec<u8>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<FileHeader, HeaderError>
pub fn new( salt: [u8; 16], kdf_params: KeyDerivationParams, content_nonce: [u8; 24], filename_nonce: [u8; 24], filename_ciphertext: Vec<u8>, ) -> Result<FileHeader, 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 moreAuto Trait Implementations§
impl Freeze for FileHeader
impl RefUnwindSafe for FileHeader
impl Send for FileHeader
impl Sync for FileHeader
impl Unpin for FileHeader
impl UnsafeUnpin for FileHeader
impl UnwindSafe for FileHeader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more