Remove redundant stringification for decrypt().

This commit is contained in:
John Hood
2016-03-24 00:21:08 -04:00
parent 6075209038
commit 7af87d85cc
3 changed files with 8 additions and 7 deletions
+3 -5
View File
@@ -250,15 +250,13 @@ const string Session::encrypt( const Message & plaintext )
return plaintext.nonce.cc_str() + text;
}
const Message Session::decrypt( const string & ciphertext )
const Message Session::decrypt( const char *str, size_t len )
{
if ( ciphertext.size() < 24 ) {
if ( len < 24 ) {
throw CryptoException( "Ciphertext must contain nonce and tag." );
}
const char *str = ciphertext.data();
int body_len = ciphertext.size() - 8;
int body_len = len - 8;
int pt_len = body_len - 16;
if ( pt_len < 0 ) { /* super-assertion that pt_len does not equal AE_INVALID */
+4 -1
View File
@@ -151,7 +151,10 @@ namespace Crypto {
~Session();
const string encrypt( const Message & plaintext );
const Message decrypt( const string & ciphertext );
const Message decrypt( const char *str, size_t len );
const Message decrypt( const string & ciphertext ) {
return decrypt( ciphertext.data(), ciphertext.size() );
}
Session( const Session & );
Session & operator=( const Session & );
+1 -1
View File
@@ -513,7 +513,7 @@ string Connection::recv_one( int sock_to_recv, bool nonblocking )
}
}
Packet p( session.decrypt( string( msg_payload, received_len ) ) );
Packet p( session.decrypt( msg_payload, received_len ) );
dos_assert( p.direction == (server ? TO_SERVER : TO_CLIENT) ); /* prevent malicious playback to sender */