Skip to main content

Module stream

Module stream 

Source
Expand description

Attachment AES-256-GCM over a file, a chunk at a time: the cipher of super::decrypt_data (16-byte nonce, 16-byte tag appended) without the file ever sitting whole in memory.

GCM is CTR encryption plus a GHASH over the ciphertext, and both run incrementally. The catch is that the tag only speaks at the end, so plaintext is written to a file the caller keeps out of sight until this returns Ok.

Structs§

StreamedFile
What one pass over a downloaded file learned.

Constants§

CANCELLED
What a pass stopped by its caller returns.

Functions§

decrypt_file
Decrypt src (ciphertext || tag) into dst, hashing both sides on the way. dst holds unauthenticated plaintext until this returns: on any error it is removed, and a tag mismatch is reported as a decryption failure.
decrypt_file_with_progress
decrypt_file, telling progress each new whole percentage of the file opened. progress answering false stops the pass, as for encrypt_file_with_progress.
encrypt_file
Encrypt src into dst (ciphertext || tag), the counterpart of decrypt_file. Returns the SHA-256 and length of what was written: the blob a server will hold.
encrypt_file_with_progress
encrypt_file, telling progress each new whole percentage of the file sealed. progress answering false stops the pass: nothing is written and the error says it was cancelled.
hash_file
SHA-256 of a file, read a chunk at a time.
place_download
Put a verified download into the download directory under name: an identical file already there (same name, size and hash) is reused and src dropped; otherwise src moves to a free spelling of the name. Returns where it landed.