fix error handling in random.cpp and fix accidental openssl dependency

This commit is contained in:
arvidn 2017-01-16 09:50:56 -05:00 committed by Arvid Norberg
parent 748c6e0da0
commit 5736237a63
4 changed files with 10 additions and 5 deletions

View File

@ -62,7 +62,7 @@ namespace libtorrent { namespace aux {
if (ret != buffer.size()) if (ret != buffer.size())
{ {
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS
throw system_error(error_code(EIO, system_category())); throw system_error(errors::no_entropy);
#else #else
std::terminate(); std::terminate();
#endif #endif

View File

@ -433,6 +433,9 @@ namespace libtorrent
overflow, overflow,
#endif #endif
// random number generation failed
no_entropy = 200,
// the number of error codes // the number of error codes
error_code_max error_code_max
}; };

View File

@ -263,7 +263,11 @@ namespace libtorrent
"bencoded nesting depth exceeded", "bencoded nesting depth exceeded",
"bencoded item count limit exceeded", "bencoded item count limit exceeded",
"integer overflow", "integer overflow",
"",
"",
"",
#endif #endif
"random number generator failed",
}; };
if (ev < 0 || ev >= int(sizeof(msgs)/sizeof(msgs[0]))) if (ev < 0 || ev >= int(sizeof(msgs)/sizeof(msgs[0])))
return "Unknown error"; return "Unknown error";

View File

@ -41,13 +41,12 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/win_crypto_provider.hpp" #include "libtorrent/aux_/win_crypto_provider.hpp"
#elif defined TORRENT_USE_LIBCRYPTO #elif defined TORRENT_USE_LIBCRYPTO
extern "C" { extern "C" {
#include <openssl/rand.h> #include <openssl/rand.h>
#include <openssl/err.h> #include <openssl/err.h>
} }
#include <boost/asio/ssl/error.hpp>
#endif #endif
#include "libtorrent/aux_/disable_warnings_pop.hpp" #include "libtorrent/aux_/disable_warnings_pop.hpp"
@ -98,8 +97,7 @@ namespace libtorrent
if (r != 1) if (r != 1)
{ {
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS
throw system_error(error_code(int(::ERR_get_error()) throw system_error(errors::no_entropy);
, boost::asio::error::get_ssl_category()));
#else #else
std::terminate(); std::terminate();
#endif #endif