pub fn recv_data<T,U,R,V>(&mut self,
                              in_buf: T,
                              mut out_buf: R) -> Result<(usize, usize), OssuaryError>
    where T: std::ops::DerefMut<Target = U>,
          U: std::io::Read,
          R: std::ops::DerefMut<Target = V>,
          V: std::io::Write {
        let mut bytes_read: usize = 0;
        match self.state {
            ConnectionState::Failed(_) => { return Ok((0,0)); }
            ConnectionState::Encrypted => {},
            _ => {
                return Err(OssuaryError::InvalidPacket(
                    "Encrypted channel not established.".into()));
            }
        }

        let (pkt, bytes) = match read_packet(self, in_buf) {
            Ok(t) => { t },
            Err(e @ OssuaryError::WouldBlock(_)) => {
                return Err(e);
            }
            Err(e) => {
                self.reset_state(Some(e.clone()));
                return Err(e);
            }
        };
        bytes_read += bytes;
        self.remote_msg_id = self.next_msg_id(&pkt)?;

        let result: Result<usize, OssuaryError> = match pkt.kind() {
            PacketType::Reset => {
                 // return on error, since this resets the state in a special way
                Ok(self.handle_reset_packet(bytes_read)?)
            },
            PacketType::Disconnect => { self.handle_disconnect_packet(&pkt) },
            PacketType::EncryptedData => { self.recv_encrypted_data(&pkt, out_buf.deref_mut()) },
            _ => {
                Err(OssuaryError::InvalidPacket(
                    "Received non-encrypted data on encrypted channel.".into()))
            },
        };

        match result {
            Ok(bytes_written) => Ok((bytes_read, bytes_written)),
            Err(e) => {
                self.reset_state(None);
                // bytes_read not returned on error, but will be consumed again
                // when the handshake restarts.
                Err(e)
            }
        }
    }
/// Decrypts data from a packet received from a remote host
///
/// The caller provides encrypted data from a remote host in the `in_buf`
/// buffer.  `recv_data()` decrypts it and writes the plaintext result into
/// `out_buf`.
///
/// This is the core function for data transmission via ossuary.  All data
/// received over an Ossuary connection should pass through this function.
///
/// Returns the number of bytes written to `out_buf`, or an error.
///
/// You must handle [`OssuaryError::WouldBlock`], which is a recoverable
/// error, but indicates that some bytes were read from `in_buf`.  This
/// indicates that an incomplete packet was received.
Decrypts data from a packet received from a remote host
The caller provides encrypted data from a remote host in the `in_buf`
buffer.  `recv_data()` decrypts it and writes the plaintext result into
`out_buf`.

This is the core function for data transmission via ossuary.  All data
received over an Ossuary connection should pass through this function.

Returns the number of bytes written to `out_buf`, or an error.

You must handle [`OssuaryError::WouldBlock`], which is a recoverable
error, but indicates that some bytes were read from `in_buf`.  This
indicates that an incomplete packet was received.
Decrypts data from a packet received from a remote host The caller provides encrypted data from a remote host in the ` in_buf ` buffer . ` recv_data () ` decrypts it and writes the plaintext result into ` out_buf ` . This is the core function for data transmission via ossuary . All data received over an Ossuary connection should pass through this function . Returns the number of bytes written to ` out_buf ` or an error . You must handle [ ` OssuaryError :: WouldBlock ` ] which is a recoverable error but indicates that some bytes were read from ` in_buf ` . This indicates that an incomplete packet was received .
pub fn recv_data<T,U,R,V>(&mut self,
                              in_buf: T,
                              mut out_buf: R) -> Result<(usize, usize), OssuaryError>
    where T: std::ops::DerefMut<Target = U>,
          U: std::io::Read,
          R: std::ops::DerefMut<Target = V>,
          V: std::io::Write {
        let mut bytes_read: usize = 0;
        match self.state {
            ConnectionState::Failed(_) => { return Ok((0,0)); }
            ConnectionState::Encrypted => {},
            _ => {
                return Err(OssuaryError::InvalidPacket(
                    "Encrypted channel not established.".into()));
            }
        }
        let (pkt, bytes) = match read_packet(self, in_buf) {
            Ok(t) => { t },
            Err(e @ OssuaryError::WouldBlock(_)) => {
                return Err(e);
            }
            Err(e) => {
                self.reset_state(Some(e.clone()));
                return Err(e);
            }
        };
        bytes_read += bytes;
        self.remote_msg_id = self.next_msg_id(&pkt)?;
        let result: Result<usize, OssuaryError> = match pkt.kind() {
            PacketType::Reset => {
                 // return on error, since this resets the state in a special way
                Ok(self.handle_reset_packet(bytes_read)?)
            },
            PacketType::Disconnect => { self.handle_disconnect_packet(&pkt) },
            PacketType::EncryptedData => { self.recv_encrypted_data(&pkt, out_buf.deref_mut()) },
            _ => {
                Err(OssuaryError::InvalidPacket(
                    "Received non-encrypted data on encrypted channel.".into()))
            },
        };
        match result {
            Ok(bytes_written) => Ok((bytes_read, bytes_written)),
            Err(e) => {
                self.reset_state(None);
                // bytes_read not returned on error, but will be consumed again
                // when the handshake restarts.
                Err(e)
            }
        }
    }
pub fn recv_data < T , U , R , V > ( & mut self , in_buf : T , mut out_buf : R ) -> Result < ( usize , usize ) , OssuaryError > where T : std :: ops :: DerefMut < Target = U > , U : std :: io :: Read , R : std :: ops :: DerefMut < Target = V > , V : std :: io :: Write { let mut bytes_read : usize = 0 ; match self . state { ConnectionState :: Failed ( _ ) => { return Ok ( ( 0 , 0 ) ) ; } ConnectionState :: Encrypted => { } , _ => { return Err ( OssuaryError :: InvalidPacket ( " " . into ( ) ) ) ; } } let ( pkt , bytes ) = match read_packet ( self , in_buf ) { Ok ( t ) => { t } , Err ( e @ OssuaryError :: WouldBlock ( _ ) ) => { return Err ( e ) ; } Err ( e ) => { self . reset_state ( Some ( e . clone ( ) ) ) ; return Err ( e ) ; } } ; bytes_read += bytes ; self . remote_msg_id = self . next_msg_id ( & pkt ) ? ; let result : Result < usize , OssuaryError > = match pkt . kind ( ) { PacketType :: Reset => { // return on error, since this resets the state in a special way Ok ( self . handle_reset_packet ( bytes_read ) ? ) } , PacketType :: Disconnect => { self . handle_disconnect_packet ( & pkt ) } , PacketType :: EncryptedData => { self . recv_encrypted_data ( & pkt , out_buf . deref_mut ( ) ) } , _ => { Err ( OssuaryError :: InvalidPacket ( " " . into ( ) ) ) } , } ; match result { Ok ( bytes_written ) => Ok ( ( bytes_read , bytes_written ) ) , Err ( e ) => { self . reset_state ( None ) ; // bytes_read not returned on error, but will be consumed again // when the handshake restarts. Err ( e ) } } }
Decrypts data from a packet received from a remote host
The caller provides encrypted data from a remote host in the `in_buf`
buffer.
Decrypts data from a packet received from a remote host The caller provides encrypted data from a remote host in the ` in_buf ` buffer .
&mut self
in_buf
T
out_buf
R
&mut self
in_buf
T
out_buf
R