fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
        if !self.enc_buf.is_empty() {
            if !try!(self.flush_enc_buf()) {
                return Ok(0);
            }
        }

        if buf.is_empty() {
            return Ok(0);
        }

        let mut written: usize = 0;

        if !self.buf.is_empty() {
            let remaining = 8 - self.buf.len();
            if buf.len() < remaining {
                self.buf.push_all(buf);
                return Ok(buf.len());
            }

            self.buf.push_all(&buf[..remaining]);
            written += remaining;

            self.enc_buf.push_all(encrypt_chunk(&self.key, &mut self.prev, &self.buf));
            self.buf.truncate(0);

            if !try!(self.flush_enc_buf()) {
                return Ok(written);
            }
        }

        for chunk in buf[written..].chunks(8) {
            if chunk.len() < 8 {
                self.buf.push_all(chunk);
                written += chunk.len();
                break;
            }

            self.enc_buf.push_all(encrypt_chunk(&self.key, &mut self.prev, chunk));
            written += 8;

            if !try!(self.flush_enc_buf()) {
                return Ok(written);
            }
        }

        Ok(written)
    }
/// Encrypts the bytes in `buf` and passes them through to the
/// underlying `std::io::Write`.  If there are not an exact
/// multiple of 8 bytes available, the remaining ones will be
/// cached until more data is written or the `Writer` is closed.
Encrypts the bytes in `buf` and passes them through to the
underlying `std::io::Write`.  If there are not an exact
multiple of 8 bytes available, the remaining ones will be
cached until more data is written or the `Writer` is closed.
Encrypts the bytes in ` buf ` and passes them through to the underlying ` std :: io :: Write ` . If there are not an exact multiple of 8 bytes available the remaining ones will be cached until more data is written or the ` Writer ` is closed .
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
        if !self.enc_buf.is_empty() {
            if !try!(self.flush_enc_buf()) {
                return Ok(0);
            }
        }
        if buf.is_empty() {
            return Ok(0);
        }
        let mut written: usize = 0;
        if !self.buf.is_empty() {
            let remaining = 8 - self.buf.len();
            if buf.len() < remaining {
                self.buf.push_all(buf);
                return Ok(buf.len());
            }
            self.buf.push_all(&buf[..remaining]);
            written += remaining;
            self.enc_buf.push_all(encrypt_chunk(&self.key, &mut self.prev, &self.buf));
            self.buf.truncate(0);
            if !try!(self.flush_enc_buf()) {
                return Ok(written);
            }
        }
        for chunk in buf[written..].chunks(8) {
            if chunk.len() < 8 {
                self.buf.push_all(chunk);
                written += chunk.len();
                break;
            }
            self.enc_buf.push_all(encrypt_chunk(&self.key, &mut self.prev, chunk));
            written += 8;
            if !try!(self.flush_enc_buf()) {
                return Ok(written);
            }
        }
        Ok(written)
    }
fn write ( & mut self , buf : & [ u8 ] ) -> io :: Result < usize > { if ! self . enc_buf . is_empty ( ) { if ! try ! ( self flush_enc_buf ( ) ) { return Ok ( 0 ) ; } } if buf . is_empty ( ) { return Ok ( 0 ) ; } let mut written : usize = 0 ; if ! self . buf . is_empty ( ) { let remaining = 8 - self . buf . len ( ) ; if buf . len ( ) < remaining { self . buf . push_all ( buf ) ; return Ok ( buf . len ( ) ) ; } self . buf . push_all ( & buf [ .. remaining ] ) ; written += remaining ; self . enc_buf . push_all ( encrypt_chunk ( & self . key , & mut self . prev , & self . buf ) ) ; self . buf . truncate ( 0 ) ; if ! try ! ( self flush_enc_buf ( ) ) { return Ok ( written ) ; } } for chunk in buf [ written .. ] . chunks ( 8 ) { if chunk . len ( ) < 8 { self . buf . push_all ( chunk ) ; written += chunk . len ( ) ; break ; } self . enc_buf . push_all ( encrypt_chunk ( & self . key , & mut self . prev , chunk ) ) ; written += 8 ; if ! try ! ( self flush_enc_buf ( ) ) { return Ok ( written ) ; } } Ok ( written ) }
Encrypts the bytes in `buf` and passes them through to the
underlying `std::io::Write`.
Encrypts the bytes in ` buf ` and passes them through to the underlying ` std :: io :: Write ` .
&mut self
buf
&[u8]
&mut self
buf
&[u8]