Fixed warnings related to libtomcrypt's byte definition
This commit is contained in:
parent
5cace54457
commit
0898fda3db
|
@ -71,6 +71,7 @@ set(SOURCE_FILES
|
|||
src/misc/time.cpp
|
||||
src/misc/memtracker.cpp
|
||||
src/misc/base64.cpp
|
||||
src/misc/digest.cpp
|
||||
|
||||
#Logger
|
||||
src/log/LogUtils.cpp
|
||||
|
|
|
@ -81,4 +81,5 @@ namespace ts {
|
|||
return ((class(*)(const std::string&)) ts::converter<size_type>::from_string)(val); \
|
||||
}; \
|
||||
}; \
|
||||
}
|
||||
}
|
||||
/* DO NOT REMOVE ME (NL warning) */
|
|
@ -1,4 +1,26 @@
|
|||
//
|
||||
// Created by wolverindev on 02.07.19.
|
||||
//
|
||||
#include "./base64.h"
|
||||
#include <tomcrypt.h>
|
||||
|
||||
|
||||
std::string base64::decode(const char* input, size_t size) {
|
||||
auto out = new unsigned char[size];
|
||||
if(base64_strict_decode((unsigned char*) input, size, out, (unsigned long*) &size) != CRYPT_OK){
|
||||
std::cerr << "Invalid base 64 string '" << input << "'" << std::endl;
|
||||
return "";
|
||||
}
|
||||
std::string ret((char*) out, size);
|
||||
delete[] out;
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string base64::encode(const char* input, const unsigned long inputSize) {
|
||||
auto outlen = static_cast<unsigned long>(inputSize + (inputSize / 3.0) + 16);
|
||||
auto outbuf = new unsigned char[outlen]; //Reserve output memory
|
||||
if(base64_encode((unsigned char*) input, inputSize, outbuf, &outlen) != CRYPT_OK){
|
||||
std::cerr << "Invalid input '" << input << "'" << std::endl;
|
||||
return "";
|
||||
}
|
||||
std::string ret((char*) outbuf, outlen);
|
||||
delete[] outbuf;
|
||||
return ret;
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <tomcrypt.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace base64 {
|
||||
|
@ -11,17 +10,7 @@ namespace base64 {
|
|||
* @param inputSize The size of the input to decode
|
||||
* @return A Base64-encoded version of the encoded string
|
||||
*/
|
||||
inline std::string encode(const char* input, const unsigned long inputSize) {
|
||||
auto outlen = static_cast<unsigned long>(inputSize + (inputSize / 3.0) + 16);
|
||||
auto outbuf = new unsigned char[outlen]; //Reserve output memory
|
||||
if(base64_encode((unsigned char*) input, inputSize, outbuf, &outlen) != CRYPT_OK){
|
||||
std::cerr << "Invalid input '" << input << "'" << std::endl;
|
||||
return "";
|
||||
}
|
||||
std::string ret((char*) outbuf, outlen);
|
||||
delete[] outbuf;
|
||||
return ret;
|
||||
}
|
||||
extern std::string encode(const char* input, const unsigned long inputSize);
|
||||
|
||||
/**
|
||||
* Encodes a given string in Base64
|
||||
|
@ -36,16 +25,7 @@ namespace base64 {
|
|||
* @param input The input string to decode
|
||||
* @return A string (binary) that represents the Base64-decoded data of the input
|
||||
*/
|
||||
inline std::string decode(const char* input, size_t size) {
|
||||
auto out = new unsigned char[size];
|
||||
if(base64_strict_decode((unsigned char*) input, size, out, (unsigned long*) &size) != CRYPT_OK){
|
||||
std::cerr << "Invalid base 64 string '" << input << "'" << std::endl;
|
||||
return "";
|
||||
}
|
||||
std::string ret((char*) out, size);
|
||||
delete[] out;
|
||||
return ret;
|
||||
}
|
||||
extern std::string decode(const char* input, size_t size);
|
||||
|
||||
/**
|
||||
* Decodes a Base64-encoded string.
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
#include "./digest.h"
|
||||
#ifdef NO_OPEN_SSL
|
||||
#include <tomcrypt.h>
|
||||
|
||||
#define DECLARE_DIGEST(name, _unused_, digestLength) \
|
||||
std::string digest::tomcrypt::name(const std::string& input) { \
|
||||
hash_state hash{}; \
|
||||
\
|
||||
uint8_t buffer[digestLength]; \
|
||||
\
|
||||
name ##_init(&hash); \
|
||||
name ##_process(&hash, (uint8_t*) input.data(), input.length()); \
|
||||
name ##_done(&hash, buffer); \
|
||||
\
|
||||
return std::string((const char*) buffer, digestLength); \
|
||||
}
|
||||
|
||||
DECLARE_DIGEST(sha1, SHA1, SHA_DIGEST_LENGTH)
|
||||
DECLARE_DIGEST(sha256, SHA256, SHA256_DIGEST_LENGTH)
|
||||
DECLARE_DIGEST(sha512, SHA512, SHA512_DIGEST_LENGTH)
|
||||
#endif
|
|
@ -4,24 +4,18 @@
|
|||
#include <string_view>
|
||||
#include <cstring>
|
||||
|
||||
#define NO_OPEN_SSL
|
||||
#ifdef NO_OPEN_SSL
|
||||
#include <tomcrypt.h>
|
||||
|
||||
#define SHA_DIGEST_LENGTH 20
|
||||
#define SHA256_DIGEST_LENGTH 32
|
||||
#define SHA512_DIGEST_LENGTH 64
|
||||
|
||||
#define DECLARE_DIGEST(name, _unused_, digestLength) \
|
||||
namespace tomcrypt { \
|
||||
extern std::string name(const std::string&); \
|
||||
} \
|
||||
inline std::string name(const std::string& input) { \
|
||||
hash_state hash{}; \
|
||||
\
|
||||
uint8_t buffer[digestLength]; \
|
||||
\
|
||||
name ##_init(&hash); \
|
||||
name ##_process(&hash, (uint8_t*) input.data(), input.length()); \
|
||||
name ##_done(&hash, buffer); \
|
||||
\
|
||||
return std::string((const char*) buffer, digestLength); \
|
||||
return tomcrypt::name(input); \
|
||||
} \
|
||||
\
|
||||
inline std::string name(const char* input, int64_t length = -1) { \
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <tomcrypt.h>
|
||||
#include "Packet.h"
|
||||
#include <tomcrypt.h>
|
||||
#undef byte /* the macro byte gets defined by tomcrypt_macros. We have to undefine it */
|
||||
|
||||
namespace ts {
|
||||
namespace connection {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef byte
|
||||
#define byte asdd
|
||||
#ifndef WIN32
|
||||
#warning The byte macro is already defined! Undefining it!
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue