pub struct FileHeader { /* private fields */ }Expand description
Fixed-size file header stored at the beginning of every encrypted file.
The layout is #[repr(C)] with all fields being u8 or [u8; N], so:
- Alignment = 1 (same as
u8) - Size = exactly
HEADER_LEN(64 bytes) - No padding — the compiler cannot insert any between
u8-aligned fields
This makes zero-copy casting to/from [u8; HEADER_LEN] sound, verified by
the compile-time assertions below.
Implementations§
Source§impl FileHeader
impl FileHeader
Sourcepub const fn new(compressed: bool, salt: [u8; 16], file_id: [u8; 16]) -> Self
pub const fn new(compressed: bool, salt: [u8; 16], file_id: [u8; 16]) -> Self
Construct a header with explicit file_id. Callers are responsible for
generating (or looking up the cached) file_id so that re-encryption is
deterministic.
Sourcepub fn generate_file_id() -> [u8; 16]
pub fn generate_file_id() -> [u8; 16]
Generate a fresh random file_id using the system RNG.
Sourcepub fn from_bytes(bytes: &[u8; 64]) -> Result<&Self>
pub fn from_bytes(bytes: &[u8; 64]) -> Result<&Self>
Zero-copy: validate and cast &[u8; 64] → &FileHeader.
The returned reference borrows from bytes — no allocation or copying.
Sourcepub fn read_from<R: Read>(reader: &mut R) -> Result<Self>
pub fn read_from<R: Read>(reader: &mut R) -> Result<Self>
Read 64 bytes from reader, validate, and return an owned header.
This is a convenience wrapper around from_bytes
for callers that already have a Read impl (e.g. integration tests).
Sourcepub fn write_to<W: Write>(&self, writer: &mut W) -> Result<()>
pub fn write_to<W: Write>(&self, writer: &mut W) -> Result<()>
Write the header bytes to writer (zero-copy via [as_bytes]).
Sourcepub const fn as_bytes(&self) -> &[u8; 64]
pub const fn as_bytes(&self) -> &[u8; 64]
Zero-copy: view the header as a fixed-size byte slice.
The returned &[u8; HEADER_LEN] borrows from self.
pub const fn is_compressed(&self) -> bool
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 moreimpl Copy for FileHeader
Source§impl Debug for FileHeader
impl Debug for FileHeader
impl Eq for FileHeader
Source§impl PartialEq for FileHeader
impl PartialEq for FileHeader
Source§fn eq(&self, other: &FileHeader) -> bool
fn eq(&self, other: &FileHeader) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for FileHeader
Auto 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> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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 moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.