error handling in pgphandler.cc

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6938 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-12-10 10:08:41 +00:00
parent 3e88b54ae3
commit 5800069acf

View File

@ -1182,21 +1182,28 @@ bool PGPHandler::encryptDataBin(const PGPIdType& key_id,const void *data, const
ops_create_info_t *info; ops_create_info_t *info;
ops_memory_t *buf = NULL ; ops_memory_t *buf = NULL ;
ops_setup_memory_write(&info, &buf, 0); ops_setup_memory_write(&info, &buf, 0);
bool res = true;
ops_encrypt_stream(info, public_key, NULL, ops_false, ops_false); if(!ops_encrypt_stream(info, public_key, NULL, ops_false, ops_false))
{
std::cerr << "Encryption failed." << std::endl;
res = false ;
}
ops_write(data,len,info); ops_write(data,len,info);
ops_writer_close(info); ops_writer_close(info);
ops_create_info_delete(info); ops_create_info_delete(info);
int tlen = ops_memory_get_length(buf) ; int tlen = ops_memory_get_length(buf) ;
bool res ;
if( (int)*encrypted_data_len >= tlen) if( (int)*encrypted_data_len >= tlen)
{ {
memcpy(encrypted_data,ops_memory_get_data(buf),tlen) ; if(res)
*encrypted_data_len = tlen ; {
res = true ; memcpy(encrypted_data,ops_memory_get_data(buf),tlen) ;
*encrypted_data_len = tlen ;
res = true ;
}
} }
else else
{ {