diff --git a/CMakeLists.txt b/CMakeLists.txt index 159236e40..8ae3307d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -470,7 +470,7 @@ else() find_package(CURL REQUIRED) include_directories(${CURL_INCLUDE_DIRS}) - find_path(NETTLE_INCLUDE_DIRS nettle/gcm.h nettle/sha.h nettle/base64.h nettle/yarrow.h) + find_path(NETTLE_INCLUDE_DIRS nettle/gcm.h nettle/sha.h nettle/base64.h nettle/version.h nettle/yarrow.h) find_library(NETTLE_LIBRARY NAMES nettle libnettle) if (NOT NETTLE_INCLUDE_DIRS OR NOT NETTLE_LIBRARY OR USE_CRYPTO_OPENSSL) diff --git a/src/network/crypto_nettle.cpp b/src/network/crypto_nettle.cpp index 4b072d8bc..e2a1d5356 100644 --- a/src/network/crypto_nettle.cpp +++ b/src/network/crypto_nettle.cpp @@ -23,6 +23,16 @@ #include "network/network_string.hpp" #include +#include + +#if NETTLE_VERSION_MAJOR > 3 || + (NETTLE_VERSION_MAJOR == 3 && NETTLE_VERSION_MINOR > 3) +typedef const char* NETTLE_CONST_CHAR; +typedef char* NETTLE_CHAR; +#else +typedef const uint8_t* NETTLE_CONST_CHAR; +typedef uint8_t* NETTLE_CHAR; +#endif // ============================================================================ std::string Crypto::base64(const std::vector& input) @@ -30,7 +40,7 @@ std::string Crypto::base64(const std::vector& input) std::string result; const size_t char_size = ((input.size() + 3 - 1) / 3) * 4; result.resize(char_size, (char)0); - base64_encode_raw(&result[0], input.size(), input.data()); + base64_encode_raw((NETTLE_CHAR)&result[0], input.size(), input.data()); return result; } // base64 @@ -44,14 +54,14 @@ std::vector Crypto::decode64(std::string input) size_t decode_len_by_nettle; #ifdef DEBUG int ret = base64_decode_update(&ctx, &decode_len_by_nettle, result.data(), - input.size(), input.c_str()); + input.size(), (NETTLE_CONST_CHAR)input.c_str()); assert(ret == 1); ret = base64_decode_final(&ctx); assert(ret == 1); assert(decode_len_by_nettle == decode_len); #else base64_decode_update(&ctx, &decode_len_by_nettle, result.data(), - input.size(), input.c_str()); + input.size(), (NETTLE_CONST_CHAR)input.c_str()); base64_decode_final(&ctx); #endif return result;