Struct aesstream::AesWriter [] [src]

pub struct AesWriter<E: BlockEncryptor, W: Write> { /* fields omitted */ }

Wraps a Write implementation with CBC based on given BlockEncryptor

Examples

Write encrypted to a file.

let key: [u8; 16] = OsRng::new()?.gen();
let file = File::create("...")?;
let encryptor = AesSafe128Encryptor::new(&key);
let mut writer = AesWriter::new(file, encryptor)?;
writer.write_all("Hello World!".as_bytes())?;

Encrypt in-memory.

let key: [u8; 16] = OsRng::new()?.gen();
let encryptor = AesSafe128Encryptor::new(&key);
let mut encrypted = Vec::new();
{
    let mut writer = AesWriter::new(&mut encrypted, encryptor)?;
    writer.write_all("Hello World!".as_bytes())?;
}

Methods

impl<E: BlockEncryptor, W: Write> AesWriter<E, W>
[src]

Creates a new AesWriter with a random IV.

The IV will be written as first block of the file.

Parameters

  • writer: Writer to write encrypted data into
  • enc: BlockEncryptor to use for encyrption

Examples

let key: [u8; 16] = OsRng::new()?.gen();
let encryptor = AesSafe128Encryptor::new(&key);
let file = File::create("...")?;
let mut writer = AesWriter::new(file, encryptor)?;

Trait Implementations

impl<E: BlockEncryptor, W: Write> Write for AesWriter<E, W>
[src]

Encrypts the passed buffer and writes the result to the underlying writer.

Due to the blocksize of CBC not all data will be written instantaneously. For example if 17 bytes are passed, the first 16 will be encrypted as one block and written the underlying writer, but the last byte won't be encrypted and written yet.

If flush has been called, this method will always return an error.

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

Warning: When this method is called, the encryption will finish and insert final padding. After calling flush, this writer cannot be written to anymore and will always return an error.

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

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

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

impl<E: BlockEncryptor, W: Write> Drop for AesWriter<E, W>
[src]

Drops this AesWriter trying to finish encryption and to write everything to the underlying writer.