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.
CHANGED
What a send says when its file changed between being hashed and being sealed.
TAG_MISMATCH
What opening says when the bytes aren’t the ones sealed under that key.

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_matching
encrypt_file_with_progress for a file the sender may still change: the bytes sealed must be the ones hashed as plain_sha256, or nothing is written and the send says so.
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.
verify_file
What decrypt_file learns about src, with no plaintext written anywhere: the tag verdict, both hashes and the length. For ciphertext that stays ciphertext on disk.
verify_file_with_progress
verify_file, reporting progress as decrypt_file_with_progress does.