Fixed compilation with older nettle versions
This commit is contained in:
parent
8e29c189c4
commit
9cf42302a6
@ -470,7 +470,7 @@ else()
|
|||||||
find_package(CURL REQUIRED)
|
find_package(CURL REQUIRED)
|
||||||
include_directories(${CURL_INCLUDE_DIRS})
|
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)
|
find_library(NETTLE_LIBRARY NAMES nettle libnettle)
|
||||||
|
|
||||||
if (NOT NETTLE_INCLUDE_DIRS OR NOT NETTLE_LIBRARY OR USE_CRYPTO_OPENSSL)
|
if (NOT NETTLE_INCLUDE_DIRS OR NOT NETTLE_LIBRARY OR USE_CRYPTO_OPENSSL)
|
||||||
|
@ -23,6 +23,16 @@
|
|||||||
#include "network/network_string.hpp"
|
#include "network/network_string.hpp"
|
||||||
|
|
||||||
#include <nettle/base64.h>
|
#include <nettle/base64.h>
|
||||||
|
#include <nettle/version.h>
|
||||||
|
|
||||||
|
#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<uint8_t>& input)
|
std::string Crypto::base64(const std::vector<uint8_t>& input)
|
||||||
@ -30,7 +40,7 @@ std::string Crypto::base64(const std::vector<uint8_t>& input)
|
|||||||
std::string result;
|
std::string result;
|
||||||
const size_t char_size = ((input.size() + 3 - 1) / 3) * 4;
|
const size_t char_size = ((input.size() + 3 - 1) / 3) * 4;
|
||||||
result.resize(char_size, (char)0);
|
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;
|
return result;
|
||||||
} // base64
|
} // base64
|
||||||
|
|
||||||
@ -44,14 +54,14 @@ std::vector<uint8_t> Crypto::decode64(std::string input)
|
|||||||
size_t decode_len_by_nettle;
|
size_t decode_len_by_nettle;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
int ret = base64_decode_update(&ctx, &decode_len_by_nettle, result.data(),
|
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);
|
assert(ret == 1);
|
||||||
ret = base64_decode_final(&ctx);
|
ret = base64_decode_final(&ctx);
|
||||||
assert(ret == 1);
|
assert(ret == 1);
|
||||||
assert(decode_len_by_nettle == decode_len);
|
assert(decode_len_by_nettle == decode_len);
|
||||||
#else
|
#else
|
||||||
base64_decode_update(&ctx, &decode_len_by_nettle, result.data(),
|
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);
|
base64_decode_final(&ctx);
|
||||||
#endif
|
#endif
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user