updated build system
Some checks reported errors
BlockStorage/repertory/pipeline/head Something is wrong with the build of this commit
Some checks reported errors
BlockStorage/repertory/pipeline/head Something is wrong with the build of this commit
This commit is contained in:
@ -92,7 +92,11 @@ template <typename val_t>
|
||||
}
|
||||
|
||||
if (fmt_val.empty()) {
|
||||
throw std::runtime_error("hex string is invalid|" + std::string{str});
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"hex string is invalid",
|
||||
str,
|
||||
});
|
||||
}
|
||||
|
||||
if (fmt_val.length() % 2U) {
|
||||
@ -107,9 +111,13 @@ template <typename val_t>
|
||||
});
|
||||
if (iter != fmt_val.end()) {
|
||||
auto invalid_idx{std::distance(fmt_val.begin(), iter)};
|
||||
throw std::range_error(
|
||||
"invalid character in hex string|" + std::to_string(invalid_idx) +
|
||||
'|' + std::string(1U, str.at(invalid_idx)) + '|' + std::string{str});
|
||||
throw std::range_error(utils::error::create_error_message({
|
||||
function_name,
|
||||
"invalid character in hex string",
|
||||
std::to_string(invalid_idx),
|
||||
std::string(1U, str.at(invalid_idx)),
|
||||
str,
|
||||
}));
|
||||
}
|
||||
|
||||
val.resize(fmt_val.length() / 2U);
|
||||
|
@ -25,6 +25,8 @@
|
||||
|
||||
#include "utils/config.hpp"
|
||||
|
||||
#include "utils/error.hpp"
|
||||
|
||||
namespace repertory::utils::db::sqlite {
|
||||
using db_types_t = std::variant<std::int64_t, std::string>;
|
||||
|
||||
@ -44,6 +46,10 @@ struct sqlite3_statement_deleter final {
|
||||
|
||||
using db3_stmt_t = std::unique_ptr<sqlite3_stmt, sqlite3_statement_deleter>;
|
||||
|
||||
[[nodiscard]] auto
|
||||
create_db(std::string db_path,
|
||||
const std::map<std::string, std::string> &sql_create_tables) -> db3_t;
|
||||
|
||||
[[nodiscard]] auto execute_sql(sqlite3 &db3, const std::string &sql,
|
||||
std::string &err) -> bool;
|
||||
|
||||
@ -89,11 +95,16 @@ public:
|
||||
|
||||
template <typename data_type>
|
||||
[[nodiscard]] auto get_value() const -> data_type {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
return std::visit(
|
||||
overloaded{
|
||||
[](const data_type &value) -> data_type { return value; },
|
||||
[](auto &&) -> data_type {
|
||||
throw std::runtime_error("data type not supported");
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"data type not supported",
|
||||
});
|
||||
},
|
||||
},
|
||||
value_);
|
||||
@ -107,6 +118,8 @@ public:
|
||||
template <typename ctx_t> class db_row final {
|
||||
public:
|
||||
db_row(std::shared_ptr<ctx_t> ctx) {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
auto column_count = sqlite3_column_count(ctx->stmt.get());
|
||||
for (std::int32_t col = 0; col < column_count; col++) {
|
||||
std::string name{sqlite3_column_name(ctx->stmt.get(), col)};
|
||||
@ -125,8 +138,11 @@ public:
|
||||
} break;
|
||||
|
||||
default:
|
||||
throw std::runtime_error("column type not implemented|" + name + '|' +
|
||||
std::to_string(column_type));
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"column type not implemented",
|
||||
std::to_string(column_type),
|
||||
});
|
||||
}
|
||||
|
||||
columns_[name] = db_column{col, name, value};
|
||||
|
@ -157,8 +157,8 @@ template <typename ctx_t, typename op_t> struct db_where_t final {
|
||||
|
||||
using action_t = std::variant<db_comp_data_t, n_t, db_where_t>;
|
||||
|
||||
[[nodiscard]] static auto dump(std::int32_t &idx, auto &&actions)
|
||||
-> std::string {
|
||||
[[nodiscard]] static auto dump(std::int32_t &idx,
|
||||
auto &&actions) -> std::string {
|
||||
std::stringstream stream;
|
||||
|
||||
for (auto &&action : actions) {
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include "utils/config.hpp"
|
||||
|
||||
#include "utils/error.hpp"
|
||||
#include "utils/hash.hpp"
|
||||
|
||||
namespace repertory::utils::encryption {
|
||||
@ -108,6 +109,8 @@ encrypt_data(const std::array<unsigned char,
|
||||
const std::array<arr_t, arr_size> &key,
|
||||
const unsigned char *buffer, std::size_t buffer_size,
|
||||
result_t &res) {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
std::array<unsigned char, crypto_aead_xchacha20poly1305_IETF_ABYTES> mac{};
|
||||
|
||||
const std::uint32_t size = boost::endian::native_to_big(
|
||||
@ -121,7 +124,10 @@ encrypt_data(const std::array<unsigned char,
|
||||
mac.data(), &mac_length, buffer, buffer_size,
|
||||
reinterpret_cast<const unsigned char *>(&size), sizeof(size), nullptr,
|
||||
iv.data(), key.data()) != 0) {
|
||||
throw std::runtime_error("encryption failed");
|
||||
throw repertory::utils::error::create_exception({
|
||||
function_name,
|
||||
"encryption failed",
|
||||
});
|
||||
}
|
||||
|
||||
std::memcpy(res.data(), iv.data(), iv.size());
|
||||
|
@ -25,6 +25,12 @@
|
||||
#include "utils/config.hpp"
|
||||
|
||||
namespace repertory::utils::error {
|
||||
[[nodiscard]] auto
|
||||
create_error_message(std::vector<std::string_view> items) -> std::string;
|
||||
|
||||
[[nodiscard]] auto
|
||||
create_exception(std::vector<std::string_view> items) -> std::runtime_error;
|
||||
|
||||
struct i_exception_handler {
|
||||
virtual ~i_exception_handler() {}
|
||||
|
||||
@ -48,17 +54,30 @@ protected:
|
||||
struct iostream_exception_handler final : i_exception_handler {
|
||||
void handle_error(std::string_view function_name,
|
||||
std::string_view msg) const override {
|
||||
std::cerr << function_name << '|' << msg << std::endl;
|
||||
std::cerr << create_error_message({
|
||||
function_name,
|
||||
msg,
|
||||
})
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
void handle_exception(std::string_view function_name) const override {
|
||||
std::cerr << function_name << "|exception|unknown" << std::endl;
|
||||
std::cerr << create_error_message({
|
||||
function_name,
|
||||
"exception",
|
||||
"unknown",
|
||||
})
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
void handle_exception(std::string_view function_name,
|
||||
const std::exception &ex) const override {
|
||||
std::cerr << function_name << "|exception|"
|
||||
<< (ex.what() == nullptr ? "unknown" : ex.what()) << std::endl;
|
||||
std::cerr << create_error_message({
|
||||
function_name,
|
||||
"exception",
|
||||
(ex.what() == nullptr ? "unknown" : ex.what()),
|
||||
})
|
||||
<< std::endl;
|
||||
}
|
||||
};
|
||||
inline const iostream_exception_handler default_exception_handler{};
|
||||
@ -66,15 +85,12 @@ inline const iostream_exception_handler default_exception_handler{};
|
||||
extern std::atomic<const i_exception_handler *> exception_handler;
|
||||
|
||||
#if defined(PROJECT_ENABLE_TESTING)
|
||||
[[nodiscard]] inline auto get_exception_handler()
|
||||
-> const i_exception_handler * {
|
||||
[[nodiscard]] inline auto
|
||||
get_exception_handler() -> const i_exception_handler * {
|
||||
return exception_handler;
|
||||
}
|
||||
#endif // defined(PROJECT_ENABLE_TESTING)
|
||||
|
||||
[[nodiscard]] auto create_error_message(std::vector<std::string_view> items)
|
||||
-> std::string;
|
||||
|
||||
void handle_error(std::string_view function_name, std::string_view msg);
|
||||
|
||||
void handle_exception(std::string_view function_name);
|
||||
|
@ -25,6 +25,8 @@
|
||||
|
||||
#include "utils/config.hpp"
|
||||
|
||||
#include "utils/error.hpp"
|
||||
|
||||
namespace repertory::utils::encryption {
|
||||
using hash_256_t = std::array<unsigned char, 32U>;
|
||||
using hash_384_t = std::array<unsigned char, 48U>;
|
||||
@ -83,28 +85,39 @@ template <typename hash_t>
|
||||
template <typename hash_t>
|
||||
auto create_hash_blake2b_t(const unsigned char *data,
|
||||
std::size_t data_size) -> hash_t {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
hash_t hash{};
|
||||
|
||||
crypto_generichash_blake2b_state state{};
|
||||
auto res = crypto_generichash_blake2b_init(&state, nullptr, 0U, hash.size());
|
||||
if (res != 0) {
|
||||
throw std::runtime_error("failed to initialize blake2b-" +
|
||||
std::to_string(hash.size() * 8U) + "|" +
|
||||
std::to_string(res));
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to initialize blake2b",
|
||||
std::to_string(hash.size() * 8U),
|
||||
std::to_string(res),
|
||||
});
|
||||
}
|
||||
|
||||
res = crypto_generichash_blake2b_update(&state, data, data_size);
|
||||
if (res != 0) {
|
||||
throw std::runtime_error("failed to update blake2b-" +
|
||||
std::to_string(hash.size() * 8U) + "|" +
|
||||
std::to_string(res));
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to update blake2b",
|
||||
std::to_string(hash.size() * 8U),
|
||||
std::to_string(res),
|
||||
});
|
||||
}
|
||||
|
||||
res = crypto_generichash_blake2b_final(&state, hash.data(), hash.size());
|
||||
if (res != 0) {
|
||||
throw std::runtime_error("failed to finalize blake2b-" +
|
||||
std::to_string(hash.size() * 8U) + "|" +
|
||||
std::to_string(res));
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"failed to finalize blake2b",
|
||||
std::to_string(hash.size() * 8U),
|
||||
std::to_string(res),
|
||||
});
|
||||
}
|
||||
|
||||
return hash;
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include "utils/config.hpp"
|
||||
|
||||
#include "utils/error.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
||||
namespace repertory::utils::file {
|
||||
@ -41,6 +42,8 @@ struct file_times final {
|
||||
std::uint64_t written{};
|
||||
|
||||
[[nodiscard]] auto get(time_type type) const -> std::uint64_t {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
switch (type) {
|
||||
case time_type::accessed:
|
||||
return accessed;
|
||||
@ -52,7 +55,10 @@ struct file_times final {
|
||||
return written;
|
||||
}
|
||||
|
||||
throw std::runtime_error("type_type not supported");
|
||||
throw utils::error::create_exception({
|
||||
function_name,
|
||||
"type_type not supported",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user