From 5800069acf2582fbb0558a8cc8de47812ca157f3 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 10 Dec 2013 10:08:41 +0000 Subject: [PATCH] error handling in pgphandler.cc git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6938 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pgp/pgphandler.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/libretroshare/src/pgp/pgphandler.cc b/libretroshare/src/pgp/pgphandler.cc index 48d71323d..9e8f5af84 100644 --- a/libretroshare/src/pgp/pgphandler.cc +++ b/libretroshare/src/pgp/pgphandler.cc @@ -1182,21 +1182,28 @@ bool PGPHandler::encryptDataBin(const PGPIdType& key_id,const void *data, const ops_create_info_t *info; ops_memory_t *buf = NULL ; 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_writer_close(info); ops_create_info_delete(info); int tlen = ops_memory_get_length(buf) ; - bool res ; if( (int)*encrypted_data_len >= tlen) { - memcpy(encrypted_data,ops_memory_get_data(buf),tlen) ; - *encrypted_data_len = tlen ; - res = true ; + if(res) + { + memcpy(encrypted_data,ops_memory_get_data(buf),tlen) ; + *encrypted_data_len = tlen ; + res = true ; + } } else {