mirror of
https://github.com/diamante0018/master-tool.git
synced 2025-04-22 04:15:43 +00:00
maint: downgrade to c++14 to expand portability
This commit is contained in:
parent
3ce730df44
commit
7c2870bbee
@ -57,11 +57,11 @@ filter "platforms:arm64"
|
||||
filter {}
|
||||
|
||||
filter {"language:C++", "toolset:not msc*"}
|
||||
buildoptions "-std=c++17"
|
||||
buildoptions "-std=c++14"
|
||||
filter {}
|
||||
|
||||
filter "toolset:msc*"
|
||||
buildoptions "/std:c++17"
|
||||
buildoptions "/std:c++14"
|
||||
filter {}
|
||||
|
||||
filter {"system:windows"}
|
||||
|
@ -11,15 +11,15 @@ namespace network
|
||||
|
||||
void set_ipv4(in_addr addr);
|
||||
void set_port(unsigned short port);
|
||||
[[nodiscard]] unsigned short get_port() const;
|
||||
GSL_NODISCARD unsigned short get_port() const;
|
||||
|
||||
[[nodiscard]] sockaddr& get_addr();
|
||||
[[nodiscard]] const sockaddr& get_addr() const;
|
||||
[[nodiscard]] sockaddr_in& get_in_addr();
|
||||
[[nodiscard]] const sockaddr_in& get_in_addr() const;
|
||||
GSL_NODISCARD sockaddr& get_addr();
|
||||
GSL_NODISCARD const sockaddr& get_addr() const;
|
||||
GSL_NODISCARD sockaddr_in& get_in_addr();
|
||||
GSL_NODISCARD const sockaddr_in& get_in_addr() const;
|
||||
|
||||
[[nodiscard]] bool is_local() const;
|
||||
[[nodiscard]] std::string to_string(bool with_port = true) const;
|
||||
GSL_NODISCARD bool is_local() const;
|
||||
GSL_NODISCARD std::string to_string(bool with_port = true) const;
|
||||
|
||||
bool operator==(const address& obj) const;
|
||||
|
||||
|
@ -7,8 +7,10 @@ using namespace std::literals;
|
||||
|
||||
/// http://www.opensource.apple.com/source/CommonCrypto/CommonCrypto-55010/Source/libtomcrypt/doc/libTomCryptDoc.pdf
|
||||
|
||||
namespace utils::cryptography
|
||||
namespace utils
|
||||
{
|
||||
namespace cryptography
|
||||
{
|
||||
namespace
|
||||
{
|
||||
struct __
|
||||
@ -30,27 +32,27 @@ namespace utils::cryptography
|
||||
}
|
||||
} ___;
|
||||
|
||||
[[maybe_unused]] const char* cs(const std::uint8_t* data)
|
||||
GSL_NODISCARD const char* cs(const std::uint8_t* data)
|
||||
{
|
||||
return reinterpret_cast<const char*>(data);
|
||||
}
|
||||
|
||||
[[maybe_unused]] char* cs(std::uint8_t* data)
|
||||
GSL_NODISCARD char* cs(std::uint8_t* data)
|
||||
{
|
||||
return reinterpret_cast<char*>(data);
|
||||
}
|
||||
|
||||
[[maybe_unused]] const std::uint8_t* cs(const char* data)
|
||||
GSL_NODISCARD const std::uint8_t* cs(const char* data)
|
||||
{
|
||||
return reinterpret_cast<const std::uint8_t*>(data);
|
||||
}
|
||||
|
||||
[[maybe_unused]] std::uint8_t* cs(char* data)
|
||||
GSL_NODISCARD std::uint8_t* cs(char* data)
|
||||
{
|
||||
return reinterpret_cast<std::uint8_t*>(data);
|
||||
}
|
||||
|
||||
[[maybe_unused]] unsigned long ul(const std::size_t value)
|
||||
GSL_NODISCARD unsigned long ul(const std::size_t value)
|
||||
{
|
||||
return static_cast<unsigned long>(value);
|
||||
}
|
||||
@ -312,7 +314,7 @@ namespace utils::cryptography
|
||||
auto out_len = ul(out_data.size());
|
||||
auto crypt = [&]()
|
||||
{
|
||||
return ecc_encrypt_key(cs(data.data()), ul(data.size()), cs(out_data.data()), &out_len,
|
||||
return ecc_encrypt_key(cs(data.data()), ul(data.size()), const_cast<std::uint8_t*>(cs(out_data.data())), &out_len,
|
||||
prng_.get_state(), prng_.get_id(), find_hash("sha512"), &key.get());
|
||||
};
|
||||
|
||||
@ -342,7 +344,7 @@ namespace utils::cryptography
|
||||
auto out_len = ul(out_data.size());
|
||||
auto crypt = [&]()
|
||||
{
|
||||
return ecc_decrypt_key(cs(data.data()), ul(data.size()), cs(out_data.data()), &out_len, &key.get());
|
||||
return ecc_decrypt_key(cs(data.data()), ul(data.size()), const_cast<std::uint8_t*>(cs(out_data.data())), &out_len, &key.get());
|
||||
};
|
||||
|
||||
auto res = crypt();
|
||||
@ -379,7 +381,7 @@ namespace utils::cryptography
|
||||
auto out_len = ul(out_data.size());
|
||||
auto crypt = [&]()
|
||||
{
|
||||
return rsa_encrypt_key(cs(data.data()), ul(data.size()), cs(out_data.data()), &out_len, cs(hash.data()),
|
||||
return rsa_encrypt_key(cs(data.data()), ul(data.size()), const_cast<std::uint8_t*>(cs(out_data.data())), &out_len, cs(hash.data()),
|
||||
ul(hash.size()), prng_.get_state(), prng_.get_id(), find_hash("sha512"), &new_key);
|
||||
};
|
||||
|
||||
@ -409,7 +411,7 @@ namespace utils::cryptography
|
||||
const auto des3 = find_cipher("3des");
|
||||
|
||||
cbc_start(des3, cs(iv.data()), cs(key.data()), static_cast<int>(key.size()), 0, &cbc);
|
||||
cbc_encrypt(cs(data.data()), cs(enc_data.data()), ul(data.size()), &cbc);
|
||||
cbc_encrypt(cs(data.data()), const_cast<std::uint8_t*>(cs(enc_data.data())), ul(data.size()), &cbc);
|
||||
cbc_done(&cbc);
|
||||
|
||||
return enc_data;
|
||||
@ -424,7 +426,7 @@ namespace utils::cryptography
|
||||
const auto des3 = find_cipher("3des");
|
||||
|
||||
cbc_start(des3, cs(iv.data()), cs(key.data()), static_cast<int>(key.size()), 0, &cbc);
|
||||
cbc_decrypt(cs(data.data()), cs(dec_data.data()), ul(data.size()), &cbc);
|
||||
cbc_decrypt(cs(data.data()), const_cast<std::uint8_t*>(cs(dec_data.data())), ul(data.size()), &cbc);
|
||||
cbc_done(&cbc);
|
||||
|
||||
return dec_data;
|
||||
@ -458,11 +460,8 @@ namespace utils::cryptography
|
||||
symmetric_CBC cbc;
|
||||
const auto aes = find_cipher("aes");
|
||||
|
||||
cbc_start(aes, cs(iv.data()), cs(key.data()),
|
||||
static_cast<int>(key.size()), 0, &cbc);
|
||||
cbc_encrypt(cs(data.data()),
|
||||
cs(enc_data.data()),
|
||||
ul(data.size()), &cbc);
|
||||
cbc_start(aes, cs(iv.data()), cs(key.data()), static_cast<int>(key.size()), 0, &cbc);
|
||||
cbc_encrypt(cs(data.data()), const_cast<std::uint8_t*>(cs(enc_data.data())), ul(data.size()), &cbc);
|
||||
cbc_done(&cbc);
|
||||
|
||||
return enc_data;
|
||||
@ -476,11 +475,8 @@ namespace utils::cryptography
|
||||
symmetric_CBC cbc;
|
||||
const auto aes = find_cipher("aes");
|
||||
|
||||
cbc_start(aes, cs(iv.data()), cs(key.data()),
|
||||
static_cast<int>(key.size()), 0, &cbc);
|
||||
cbc_decrypt(cs(data.data()),
|
||||
cs(dec_data.data()),
|
||||
ul(data.size()), &cbc);
|
||||
cbc_start(aes, cs(iv.data()), cs(key.data()), static_cast<int>(key.size()), 0, &cbc);
|
||||
cbc_decrypt(cs(data.data()), const_cast<std::uint8_t*>(cs(dec_data.data())), ul(data.size()), &cbc);
|
||||
cbc_done(&cbc);
|
||||
|
||||
return dec_data;
|
||||
@ -496,7 +492,7 @@ namespace utils::cryptography
|
||||
hmac_process(&state, cs(data.data()), static_cast<int>(data.size()));
|
||||
|
||||
auto out_len = ul(buffer.size());
|
||||
hmac_done(&state, cs(buffer.data()), &out_len);
|
||||
hmac_done(&state, const_cast<std::uint8_t*>(cs(buffer.data())), &out_len);
|
||||
|
||||
buffer.resize(out_len);
|
||||
return buffer;
|
||||
@ -568,7 +564,7 @@ namespace utils::cryptography
|
||||
result.resize((len + 2) * 2);
|
||||
|
||||
auto out_len = ul(result.size());
|
||||
if (base64_encode(data, ul(len), result.data(), &out_len) != CRYPT_OK)
|
||||
if (base64_encode(data, ul(len), const_cast<char*>(result.data()), &out_len) != CRYPT_OK)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
@ -588,7 +584,7 @@ namespace utils::cryptography
|
||||
result.resize((data.size() + 2) * 2);
|
||||
|
||||
auto out_len = ul(result.size());
|
||||
if (base64_decode(data.data(), ul(data.size()), cs(result.data()), &out_len) != CRYPT_OK)
|
||||
if (base64_decode(data.data(), ul(data.size()), const_cast<std::uint8_t*>(cs(result.data())), &out_len) != CRYPT_OK)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
@ -628,7 +624,7 @@ namespace utils::cryptography
|
||||
{
|
||||
std::string result;
|
||||
result.resize(sizeof(std::uint32_t));
|
||||
get_data(result.data(), result.size());
|
||||
get_data(const_cast<char*>(result.data()), result.size());
|
||||
return string::dump_hex(result, "");
|
||||
}
|
||||
|
||||
@ -636,4 +632,5 @@ namespace utils::cryptography
|
||||
{
|
||||
prng_.read(data, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,10 @@
|
||||
#include <string>
|
||||
#include <tomcrypt.h>
|
||||
|
||||
namespace utils::cryptography
|
||||
namespace utils
|
||||
{
|
||||
namespace cryptography
|
||||
{
|
||||
namespace ecc
|
||||
{
|
||||
class key final
|
||||
@ -18,24 +20,24 @@ namespace utils::cryptography
|
||||
key& operator=(key&& obj) noexcept;
|
||||
key& operator=(const key& obj);
|
||||
|
||||
[[nodiscard]] bool is_valid() const;
|
||||
GSL_NODISCARD bool is_valid() const;
|
||||
|
||||
ecc_key& get();
|
||||
[[nodiscard]] const ecc_key& get() const;
|
||||
GSL_NODISCARD const ecc_key& get() const;
|
||||
|
||||
[[nodiscard]] std::string get_public_key() const;
|
||||
GSL_NODISCARD std::string get_public_key() const;
|
||||
|
||||
void set(const std::string& pub_key_buffer);
|
||||
|
||||
void deserialize(const std::string& key);
|
||||
|
||||
[[nodiscard]] std::string serialize(int type = PK_PRIVATE) const;
|
||||
GSL_NODISCARD std::string serialize(int type = PK_PRIVATE) const;
|
||||
|
||||
void free();
|
||||
|
||||
bool operator==(key& key) const;
|
||||
|
||||
[[nodiscard]] std::uint64_t get_hash() const;
|
||||
GSL_NODISCARD std::uint64_t get_hash() const;
|
||||
|
||||
private:
|
||||
ecc_key key_storage_{};
|
||||
@ -115,4 +117,5 @@ namespace utils::cryptography
|
||||
std::string get_challenge();
|
||||
void get_data(void* data, std::size_t size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
#include <std_include.hpp>
|
||||
#include "io.hpp"
|
||||
|
||||
namespace utils::io
|
||||
namespace utils
|
||||
{
|
||||
namespace io
|
||||
{
|
||||
bool remove_file(const std::string& file)
|
||||
{
|
||||
return remove(file.data()) == 0;
|
||||
@ -20,12 +22,6 @@ namespace utils::io
|
||||
|
||||
bool write_file(const std::string& file, const std::string& data, const bool append)
|
||||
{
|
||||
const auto pos = file.find_last_of("/\\");
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
create_directory(file.substr(0, pos));
|
||||
}
|
||||
|
||||
auto mode = std::ios::binary | std::ofstream::out;
|
||||
if (append)
|
||||
{
|
||||
@ -92,37 +88,5 @@ namespace utils::io
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool create_directory(const std::string& directory)
|
||||
{
|
||||
return std::filesystem::create_directories(directory);
|
||||
}
|
||||
|
||||
bool directory_exists(const std::string& directory)
|
||||
{
|
||||
return std::filesystem::is_directory(directory);
|
||||
}
|
||||
|
||||
bool directory_is_empty(const std::string& directory)
|
||||
{
|
||||
return std::filesystem::is_empty(directory);
|
||||
}
|
||||
|
||||
std::vector<std::string> list_files(const std::string& directory)
|
||||
{
|
||||
std::vector<std::string> files;
|
||||
|
||||
for (auto& file : std::filesystem::directory_iterator(directory))
|
||||
{
|
||||
files.push_back(file.path().generic_string());
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
void copy_folder(const std::filesystem::path& src, const std::filesystem::path& target)
|
||||
{
|
||||
std::filesystem::copy(src, target, std::filesystem::copy_options::overwrite_existing |
|
||||
std::filesystem::copy_options::recursive);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace utils::io
|
||||
namespace utils
|
||||
{
|
||||
namespace io
|
||||
{
|
||||
bool remove_file(const std::string& file);
|
||||
bool move_file(const std::string& src, const std::string& target);
|
||||
bool file_exists(const std::string& file);
|
||||
@ -12,9 +13,5 @@ namespace utils::io
|
||||
bool read_file(const std::string& file, std::string* data);
|
||||
std::string read_file(const std::string& file);
|
||||
std::size_t file_size(const std::string& file);
|
||||
bool create_directory(const std::string& directory);
|
||||
bool directory_exists(const std::string& directory);
|
||||
bool directory_is_empty(const std::string& directory);
|
||||
std::vector<std::string> list_files(const std::string& directory);
|
||||
void copy_folder(const std::filesystem::path& src, const std::filesystem::path& target);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace utils
|
||||
|
||||
void memory::allocator::clear()
|
||||
{
|
||||
std::lock_guard _(this->mutex_);
|
||||
std::lock_guard<std::mutex> _(this->mutex_);
|
||||
|
||||
for (auto& data : this->pool_)
|
||||
{
|
||||
@ -25,7 +25,7 @@ namespace utils
|
||||
|
||||
void memory::allocator::free(void* data)
|
||||
{
|
||||
std::lock_guard _(this->mutex_);
|
||||
std::lock_guard<std::mutex> _(this->mutex_);
|
||||
|
||||
const auto j = std::find(this->pool_.begin(), this->pool_.end(), data);
|
||||
if (j != this->pool_.end())
|
||||
@ -42,7 +42,7 @@ namespace utils
|
||||
|
||||
void* memory::allocator::allocate(const size_t length)
|
||||
{
|
||||
std::lock_guard _(this->mutex_);
|
||||
std::lock_guard<std::mutex> _(this->mutex_);
|
||||
|
||||
const auto data = memory::allocate(length);
|
||||
this->pool_.push_back(data);
|
||||
@ -56,7 +56,7 @@ namespace utils
|
||||
|
||||
char* memory::allocator::duplicate_string(const std::string& string)
|
||||
{
|
||||
std::lock_guard _(this->mutex_);
|
||||
std::lock_guard<std::mutex> _(this->mutex_);
|
||||
|
||||
const auto data = memory::duplicate_string(string);
|
||||
this->pool_.push_back(data);
|
||||
|
@ -22,13 +22,13 @@ namespace utils
|
||||
void* allocate(size_t length);
|
||||
|
||||
template <typename T>
|
||||
inline T* allocate()
|
||||
T* allocate()
|
||||
{
|
||||
return this->allocate_array<T>(1);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T* allocate_array(const size_t count = 1)
|
||||
T* allocate_array(const size_t count = 1)
|
||||
{
|
||||
return static_cast<T*>(this->allocate(count * sizeof(T)));
|
||||
}
|
||||
@ -45,13 +45,13 @@ namespace utils
|
||||
static void* allocate(size_t length);
|
||||
|
||||
template <typename T>
|
||||
static inline T* allocate()
|
||||
static T* allocate()
|
||||
{
|
||||
return allocate_array<T>(1);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static inline T* allocate_array(const size_t count = 1)
|
||||
static T* allocate_array(const size_t count = 1)
|
||||
{
|
||||
return static_cast<T*>(allocate(count * sizeof(T)));
|
||||
}
|
||||
|
@ -5,8 +5,10 @@
|
||||
#include <cstdarg>
|
||||
#include <algorithm>
|
||||
|
||||
namespace utils::string
|
||||
namespace utils
|
||||
{
|
||||
namespace string
|
||||
{
|
||||
const char* va(const char* fmt, ...)
|
||||
{
|
||||
static thread_local va_provider<8, 256> provider;
|
||||
@ -99,4 +101,5 @@ namespace utils::string
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,14 @@
|
||||
#include "memory.hpp"
|
||||
|
||||
#ifndef ARRAYSIZE
|
||||
template <class Type, size_t n>
|
||||
size_t ARRAYSIZE(Type (&)[n]) { return n; }
|
||||
template <class Type, std::size_t n>
|
||||
std::size_t ARRAYSIZE(Type (&)[n]) { return n; }
|
||||
#endif
|
||||
|
||||
namespace utils::string
|
||||
namespace utils
|
||||
{
|
||||
namespace string
|
||||
{
|
||||
template <std::size_t Buffers, std::size_t MinBufferSize>
|
||||
class va_provider final
|
||||
{
|
||||
@ -94,4 +96,5 @@ namespace utils::string
|
||||
std::string replace(std::string str, const std::string& from, const std::string& to);
|
||||
|
||||
std::string dump_hex(const std::string& data, const std::string& separator = " ");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user