pub struct EncryptedFile { /* private fields */ }Expand description
Represents a complete encrypted file with header and content
Implementations§
Source§impl EncryptedFile
impl EncryptedFile
pub fn new(header: FileHeader, ciphertext: Vec<u8>) -> Self
Sourcepub fn seal(
plaintext_file: &PlaintextFile,
key: &SecureKey,
kdf_params: KeyDerivationParams,
salt: [u8; 16],
content_nonce: [u8; 24],
filename_nonce: [u8; 24],
) -> Result<Self, FileError>
pub fn seal( plaintext_file: &PlaintextFile, key: &SecureKey, kdf_params: KeyDerivationParams, salt: [u8; 16], content_nonce: [u8; 24], filename_nonce: [u8; 24], ) -> Result<Self, 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<Self, HeaderError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, 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.