pub struct EncryptedFile {
header: FileHeader,
ciphertext: Vec<u8>,
}Expand description
Represents a complete encrypted file with header and content
Fields§
§header: FileHeader§ciphertext: Vec<u8>Implementations§
Source§impl EncryptedFile
impl EncryptedFile
pub fn new(header: FileHeader, ciphertext: Vec<u8>) -> EncryptedFile
Sourcepub fn seal(
plaintext_file: &PlaintextFile,
key: &SecureKey,
kdf_params: KeyDerivationParams,
salt: [u8; 16],
content_nonce: [u8; 24],
filename_nonce: [u8; 24],
) -> Result<EncryptedFile, FileError>
pub fn seal( plaintext_file: &PlaintextFile, key: &SecureKey, kdf_params: KeyDerivationParams, salt: [u8; 16], content_nonce: [u8; 24], filename_nonce: [u8; 24], ) -> Result<EncryptedFile, FileError>
Encrypts a plaintext file into a complete v2 encrypted file.
This owns the v2 AEAD choreography: the fixed header fields are bound as associated data to both ciphertexts, with distinct domains for filename and content, so neither the header nor the pairing of the two ciphertexts can be tampered with undetected.
The caller supplies the key (derived from kdf_params and salt) and
fresh random salt/nonces, keeping this function deterministic.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<EncryptedFile, HeaderError>
pub fn from_bytes(bytes: &[u8]) -> Result<EncryptedFile, HeaderError>
Parses a serialized v2 file into its header and content ciphertext.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Serializes the complete file (header followed by content ciphertext).
Sourcepub fn decrypt(&self, key: &SecureKey) -> Result<PlaintextFile, FileError>
pub fn decrypt(&self, key: &SecureKey) -> Result<PlaintextFile, FileError>
Decrypts the filename and content, verifying the header binding under
each ciphertext’s own domain. The inverse of EncryptedFile::seal.
pub fn header(&self) -> &FileHeader
pub fn ciphertext(&self) -> &[u8] ⓘ
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EncryptedFile
impl RefUnwindSafe for EncryptedFile
impl Send for EncryptedFile
impl Sync for EncryptedFile
impl Unpin for EncryptedFile
impl UnsafeUnpin for EncryptedFile
impl UnwindSafe for EncryptedFile
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> 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