diff --git a/src/crypto/crypto.cc b/src/crypto/crypto.cc index 6bcb7c7..c1f002a 100644 --- a/src/crypto/crypto.cc +++ b/src/crypto/crypto.cc @@ -201,17 +201,6 @@ Nonce::Nonce( const char *s_bytes, size_t len ) memcpy( bytes + 4, s_bytes, 8 ); } -Message::Message( const char *nonce_bytes, size_t nonce_len, - const char *text_bytes, size_t text_len ) - : nonce( nonce_bytes, nonce_len ), - text( text_bytes, text_len ) -{} - -Message::Message( const Nonce & s_nonce, const string & s_text ) - : nonce( s_nonce ), - text( s_text ) -{} - const string Session::encrypt( const Message & plaintext ) { const size_t pt_len = plaintext.text.size(); diff --git a/src/crypto/crypto.h b/src/crypto/crypto.h index ae51155..736b43d 100644 --- a/src/crypto/crypto.h +++ b/src/crypto/crypto.h @@ -122,8 +122,13 @@ namespace Crypto { const string text; Message( const char *nonce_bytes, size_t nonce_len, - const char *text_bytes, size_t text_len ); - Message( const Nonce & s_nonce, const string & s_text ); + const char *text_bytes, size_t text_len ) + : nonce( nonce_bytes, nonce_len ), + text( text_bytes, text_len ) {} + + Message( const Nonce & s_nonce, const string & s_text ) + : nonce( s_nonce ), + text( s_text ) {} }; class Session { diff --git a/src/network/network.cc b/src/network/network.cc index 347bde4..9441131 100644 --- a/src/network/network.cc +++ b/src/network/network.cc @@ -66,7 +66,7 @@ using namespace Crypto; const uint64_t DIRECTION_MASK = uint64_t(1) << 63; const uint64_t SEQUENCE_MASK = uint64_t(-1) ^ DIRECTION_MASK; -/* Read in packet from coded string */ +/* Read in packet */ Packet::Packet( const Message & message ) : seq( message.nonce.val() & SEQUENCE_MASK ), direction( (message.nonce.val() & DIRECTION_MASK) ? TO_CLIENT : TO_SERVER ), @@ -83,8 +83,8 @@ Packet::Packet( const Message & message ) payload = string( message.text.begin() + 2 * sizeof( uint16_t ), message.text.end() ); } -/* Output coded string from packet */ -string Packet::tostring( Session *session ) +/* Output from packet */ +Message Packet::toMessage( void ) { uint64_t direction_seq = (uint64_t( direction == TO_CLIENT ) << 63) | (seq & SEQUENCE_MASK); @@ -93,7 +93,7 @@ string Packet::tostring( Session *session ) string timestamps = string( (char *)ts_net, 2 * sizeof( uint16_t ) ); - return session->encrypt( Message( Nonce( direction_seq ), timestamps + payload ) ); + return Message( Nonce( direction_seq ), timestamps + payload ); } Packet Connection::new_packet( const string &s_payload ) @@ -399,7 +399,7 @@ void Connection::send( const string & s ) Packet px = new_packet( s ); - string p = px.tostring( &session ); + string p = session.encrypt( px.toMessage() ); ssize_t bytes_sent = sendto( sock(), p.data(), p.size(), MSG_DONTWAIT, &remote_addr.sa, remote_addr_len ); diff --git a/src/network/network.h b/src/network/network.h index c5f743c..5d14b43 100644 --- a/src/network/network.h +++ b/src/network/network.h @@ -89,7 +89,7 @@ namespace Network { Packet( const Message & message ); - string tostring( Session *session ); + Message toMessage( void ); }; union Addr {