pub fn send_handshake<T,U>(&mut self, mut buf: T) -> Result<usize, OssuaryError>
    where T: std::ops::DerefMut<Target = U>,
          U: std::io::Write {
        // Try to send any unsent buffered data
        match write_stored_packet(self, buf.deref_mut()) {
            Ok(w) if w == 0 => {},
            Ok(w) => return Err(OssuaryError::WouldBlock(w)),
            Err(e) => return Err(e),
        }

        let result: Result<(usize, ConnectionState), OssuaryError> = match self.state {
            // No-op states
            ConnectionState::Failed(_) |
            ConnectionState::ResetWait |
            ConnectionState::Encrypted |
            ConnectionState::ClientRaiseUntrustedServer |
            ConnectionState::ClientWaitServerApproval => {
                return Ok(0);
            },
            // Timeout wait states
            ConnectionState::ServerWaitHandshake(t) |
            ConnectionState::ServerWaitAuthentication(t) |
            ConnectionState::ClientWaitHandshake(t)  => {
                // Wait for response, with timeout
                self.check_timeout(t);
                Ok((0, self.state.clone()))
            },
            // Handshake transmission states
            ConnectionState::ClientSendHandshake => { self.send_client_handshake(buf) },
            ConnectionState::ServerSendHandshake => { self.send_server_handshake(buf) },
            ConnectionState::ClientSendAuthentication => { self.send_client_authentication(buf) },
            // Error states
            ConnectionState::Failing(ref e) => {
                let e = e.clone(); // cure borrow-checker woes
                self.send_disconnect(e, buf)
            },
            ConnectionState::Resetting(initial) => { self.send_reset(initial, buf) }
        };

        match result {
            Ok((written, state)) => {
                self.state = state;
                Ok(written)
            }
            Err(e) => {
                self.reset_state(None);
                Err(e)
            },
        }
    }
/// Write the next handshake packet into the given buffer
///
/// If a handshake packet is ready to be sent, this function writes the
/// encrypted packet into the provided buffer.
///
/// This is a critical part of the handshaking stage, when a connection to
/// a remote host is securely established.  Each side of the connection must
/// call send_handshake() continuously, and any data that is written to the
/// data buffer must be sent to the remote host.  This should be done until
/// [`OssuaryConnection::handshake_done()`] returns true.
///
/// Note that Ossuary does not perform network operations itself.  It is the
/// caller's responsibility to put the written data on the wire.  However,
/// you may pass a 'buf' that does this automatically, such as a TcpStream.
///
/// Returns the number of bytes written into `buf`, or an error.  You must
/// handle [`OssuaryError::WouldBlock`], which is a recoverable error, but
/// indicates that some bytes were written to the buffer.
Write the next handshake packet into the given buffer
If a handshake packet is ready to be sent, this function writes the
encrypted packet into the provided buffer.

This is a critical part of the handshaking stage, when a connection to
a remote host is securely established.  Each side of the connection must
call send_handshake() continuously, and any data that is written to the
data buffer must be sent to the remote host.  This should be done until
[`OssuaryConnection::handshake_done()`] returns true.

Note that Ossuary does not perform network operations itself.  It is the
caller's responsibility to put the written data on the wire.  However,
you may pass a 'buf' that does this automatically, such as a TcpStream.

Returns the number of bytes written into `buf`, or an error.  You must
handle [`OssuaryError::WouldBlock`], which is a recoverable error, but
indicates that some bytes were written to the buffer.
Write the next handshake packet into the given buffer If a handshake packet is ready to be sent this function writes the encrypted packet into the provided buffer . This is a critical part of the handshaking stage when a connection to a remote host is securely established . Each side of the connection must call send_handshake () continuously and any data that is written to the data buffer must be sent to the remote host . This should be done until [ ` OssuaryConnection :: handshake_done () ` ] returns true . Note that Ossuary does not perform network operations itself . It is the caller ' s responsibility to put the written data on the wire . However you may pass a ' buf ' that does this automatically such as a TcpStream . Returns the number of bytes written into ` buf ` or an error . You must handle [ ` OssuaryError :: WouldBlock ` ] which is a recoverable error but indicates that some bytes were written to the buffer .
pub fn send_handshake<T,U>(&mut self, mut buf: T) -> Result<usize, OssuaryError>
    where T: std::ops::DerefMut<Target = U>,
          U: std::io::Write {
        // Try to send any unsent buffered data
        match write_stored_packet(self, buf.deref_mut()) {
            Ok(w) if w == 0 => {},
            Ok(w) => return Err(OssuaryError::WouldBlock(w)),
            Err(e) => return Err(e),
        }
        let result: Result<(usize, ConnectionState), OssuaryError> = match self.state {
            // No-op states
            ConnectionState::Failed(_) |
            ConnectionState::ResetWait |
            ConnectionState::Encrypted |
            ConnectionState::ClientRaiseUntrustedServer |
            ConnectionState::ClientWaitServerApproval => {
                return Ok(0);
            },
            // Timeout wait states
            ConnectionState::ServerWaitHandshake(t) |
            ConnectionState::ServerWaitAuthentication(t) |
            ConnectionState::ClientWaitHandshake(t)  => {
                // Wait for response, with timeout
                self.check_timeout(t);
                Ok((0, self.state.clone()))
            },
            // Handshake transmission states
            ConnectionState::ClientSendHandshake => { self.send_client_handshake(buf) },
            ConnectionState::ServerSendHandshake => { self.send_server_handshake(buf) },
            ConnectionState::ClientSendAuthentication => { self.send_client_authentication(buf) },
            // Error states
            ConnectionState::Failing(ref e) => {
                let e = e.clone(); // cure borrow-checker woes
                self.send_disconnect(e, buf)
            },
            ConnectionState::Resetting(initial) => { self.send_reset(initial, buf) }
        };
        match result {
            Ok((written, state)) => {
                self.state = state;
                Ok(written)
            }
            Err(e) => {
                self.reset_state(None);
                Err(e)
            },
        }
    }
pub fn send_handshake < T , U > ( & mut self , mut buf : T ) -> Result < usize , OssuaryError > where T : std :: ops :: DerefMut < Target = U > , U : std :: io :: Write { // Try to send any unsent buffered data match write_stored_packet ( self , buf . deref_mut ( ) ) { Ok ( w ) if w == 0 => { } , Ok ( w ) => return Err ( OssuaryError :: WouldBlock ( w ) ) , Err ( e ) => return Err ( e ) , } let result : Result < ( usize , ConnectionState ) , OssuaryError > = match self . state { // No-op states ConnectionState :: Failed ( _ ) | ConnectionState :: ResetWait | ConnectionState :: Encrypted | ConnectionState :: ClientRaiseUntrustedServer | ConnectionState :: ClientWaitServerApproval => { return Ok ( 0 ) ; } , // Timeout wait states ConnectionState :: ServerWaitHandshake ( t ) | ConnectionState :: ServerWaitAuthentication ( t ) | ConnectionState :: ClientWaitHandshake ( t ) => { // Wait for response, with timeout self . check_timeout ( t ) ; Ok ( ( 0 , self . state . clone ( ) ) ) } , // Handshake transmission states ConnectionState :: ClientSendHandshake => { self . send_client_handshake ( buf ) } , ConnectionState :: ServerSendHandshake => { self . send_server_handshake ( buf ) } , ConnectionState :: ClientSendAuthentication => { self . send_client_authentication ( buf ) } , // Error states ConnectionState :: Failing ( ref e ) => { let e = e . clone ( ) ; // cure borrow-checker woes self . send_disconnect ( e , buf ) } , ConnectionState :: Resetting ( initial ) => { self . send_reset ( initial , buf ) } } ; match result { Ok ( ( written , state ) ) => { self . state = state ; Ok ( written ) } Err ( e ) => { self . reset_state ( None ) ; Err ( e ) } , } }
Write the next handshake packet into the given buffer
If a handshake packet is ready to be sent, this function writes the
encrypted packet into the provided buffer.
Write the next handshake packet into the given buffer If a handshake packet is ready to be sent this function writes the encrypted packet into the provided buffer .
&mut self
buf
T
&mut self
buf
T