mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-13 08:29:32 -05:00
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:
parent
3e88b54ae3
commit
5800069acf
@ -1182,22 +1182,29 @@ 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)
|
||||||
|
{
|
||||||
|
if(res)
|
||||||
{
|
{
|
||||||
memcpy(encrypted_data,ops_memory_get_data(buf),tlen) ;
|
memcpy(encrypted_data,ops_memory_get_data(buf),tlen) ;
|
||||||
*encrypted_data_len = tlen ;
|
*encrypted_data_len = tlen ;
|
||||||
res = true ;
|
res = true ;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "Not enough room to fit encrypted data. Size given=" << *encrypted_data_len << ", required=" << tlen << std::endl;
|
std::cerr << "Not enough room to fit encrypted data. Size given=" << *encrypted_data_len << ", required=" << tlen << std::endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user