Struct ffsend_api::reader::EncryptedFileWriter [] [src]

pub struct EncryptedFileWriter { /* fields omitted */ }

A lazy file writer, that decrypt the file with the given cipher and verifies it with the tag appended to the end of the input data.

This writer is lazy because the input data is decrypted and written to the specified file on the fly, instead of buffering all the data first. This greatly reduces memory usage for large files.

The length of the input data (including the appended tag) must be given when this reader is initialized. When all data including the tag is read, the decrypted data is verified with the tag. If the tag doesn't match the decrypted data, a write error is returned on the last write. This writer will never write more bytes than the length initially specified.

This reader encrypts the input data with the given key and input vector.

A failed writing implies that no data could be written, or that the data wasn't successfully decrypted because of an decryption or tag matching error. Such a fail means that the file will be incomplete or corrupted, and should therefore be removed from the disk.

It is highly recommended to invoke the verified() method after writing the file, to ensure the written file is indeed complete and fully verified.

Methods

impl EncryptedFileWriter
[src]

[src]

Construct a new encrypted file writer.

The file to write to must be given to file, which must be open for writing. The total length of the input data in bytes must be given to len, which includes both the file bytes and the appended tag.

For decryption, a cipher, key and iv must also be given.

[src]

Check wheher the complete tag is buffered.

[src]

Check whether the decrypted data is succesfsully verified.

If this method returns true the following is implied:

  • The complete file has been written.
  • The complete file was successfully decrypted.
  • The included tag matches the decrypted file.

It is highly recommended to invoke this method and check the verification after writing the file using this writer.

Trait Implementations

impl ExactLengthReader for EncryptedFileWriter
[src]

[src]

Get the exact length of the reader in bytes.

[src]

Check whehter this extact length reader is emtpy.

impl Write for EncryptedFileWriter
[src]

The writer trait implementation.

[src]

Write a buffer into this object, returning how many bytes were written. Read more

[src]

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more

1.0.0
[src]

Attempts to write an entire buffer into this write. Read more

1.0.0
[src]

Writes a formatted string into this writer, returning any error encountered. Read more

Important traits for &'a mut W
1.0.0
[src]

Creates a "by reference" adaptor for this instance of Write. Read more

Auto Trait Implementations