simplify some exception classes
Signed-off-by: Double Sine <xiao_ai_yu@live.cn>
This commit is contained in:
parent
73ff67d4a5
commit
b3046b43f0
|
|
@ -4,9 +4,7 @@
|
||||||
namespace nkg::exceptions {
|
namespace nkg::exceptions {
|
||||||
|
|
||||||
class index_exception : public ::nkg::exception {
|
class index_exception : public ::nkg::exception {
|
||||||
public:
|
using ::nkg::exception::exception;
|
||||||
index_exception(std::string_view file, int line, std::string_view message) noexcept :
|
|
||||||
::nkg::exception(file, line, message) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,7 @@
|
||||||
namespace nkg::exceptions {
|
namespace nkg::exceptions {
|
||||||
|
|
||||||
class key_exception : public ::nkg::exception {
|
class key_exception : public ::nkg::exception {
|
||||||
public:
|
using ::nkg::exception::exception;
|
||||||
key_exception(std::string_view file, int line, std::string_view message) noexcept :
|
|
||||||
::nkg::exception(file, line, message) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,7 @@
|
||||||
namespace nkg::exceptions {
|
namespace nkg::exceptions {
|
||||||
|
|
||||||
class operation_canceled_exception : public ::nkg::exception {
|
class operation_canceled_exception : public ::nkg::exception {
|
||||||
public:
|
using ::nkg::exception::exception;
|
||||||
operation_canceled_exception(std::string_view file, int line, std::string_view message) noexcept :
|
|
||||||
::nkg::exception(file, line, message) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,42 +17,8 @@ namespace nkg {
|
||||||
|
|
||||||
class rsa_cipher {
|
class rsa_cipher {
|
||||||
public:
|
public:
|
||||||
class no_key_assigned_error : public ::nkg::exception {
|
class backend_error;
|
||||||
public:
|
class no_key_assigned_error;
|
||||||
no_key_assigned_error(std::string_view file, int line, std::string_view message) noexcept :
|
|
||||||
::nkg::exception(file, line, message) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
class backend_error : public ::nkg::exception {
|
|
||||||
public:
|
|
||||||
using error_code_t = decltype(ERR_get_error());
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::optional<error_code_t> m_error_code;
|
|
||||||
std::string m_error_string;
|
|
||||||
|
|
||||||
public:
|
|
||||||
backend_error(std::string_view file, int line, std::string_view message) noexcept :
|
|
||||||
::nkg::exception(file, line, message) {}
|
|
||||||
|
|
||||||
backend_error(std::string_view file, int line, error_code_t openssl_errno, std::string_view message) noexcept :
|
|
||||||
::nkg::exception(file, line, message), m_error_code(openssl_errno) {}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
virtual bool error_code_exists() const noexcept override {
|
|
||||||
return m_error_code.has_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
virtual intptr_t error_code() const noexcept override {
|
|
||||||
if (error_code_exists()) { return m_error_code.value(); } else { trap_then_terminate(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
virtual const std::string& error_string() const noexcept override {
|
|
||||||
if (error_code_exists()) { return m_error_string; } else { trap_then_terminate(); }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
resource_wrapper<resource_traits::openssl::rsa> m_rsa;
|
resource_wrapper<resource_traits::openssl::rsa> m_rsa;
|
||||||
|
|
@ -73,7 +39,6 @@ namespace nkg {
|
||||||
static void _write_public_key_pkcs1_to_bio(RSA* p_rsa, BIO* p_bio);
|
static void _write_public_key_pkcs1_to_bio(RSA* p_rsa, BIO* p_bio);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
rsa_cipher();
|
rsa_cipher();
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
|
|
@ -117,6 +82,41 @@ namespace nkg {
|
||||||
size_t private_decrypt(const void* ciphertext, size_t ciphertext_size, void* plaintext, int padding) const;
|
size_t private_decrypt(const void* ciphertext, size_t ciphertext_size, void* plaintext, int padding) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class rsa_cipher::backend_error : public ::nkg::exception {
|
||||||
|
public:
|
||||||
|
using error_code_t = decltype(ERR_get_error());
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::optional<error_code_t> m_error_code;
|
||||||
|
std::string m_error_string;
|
||||||
|
|
||||||
|
public:
|
||||||
|
backend_error(std::string_view file, int line, std::string_view message) noexcept :
|
||||||
|
::nkg::exception(file, line, message) {}
|
||||||
|
|
||||||
|
backend_error(std::string_view file, int line, error_code_t openssl_errno, std::string_view message) noexcept :
|
||||||
|
::nkg::exception(file, line, message), m_error_code(openssl_errno) {}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
virtual bool error_code_exists() const noexcept override {
|
||||||
|
return m_error_code.has_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
virtual intptr_t error_code() const noexcept override {
|
||||||
|
if (error_code_exists()) { return m_error_code.value(); } else { trap_then_terminate(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
virtual const std::string& error_string() const noexcept override {
|
||||||
|
if (error_code_exists()) { return m_error_string; } else { trap_then_terminate(); }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class rsa_cipher::no_key_assigned_error : public ::nkg::exception {
|
||||||
|
using ::nkg::exception::exception;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef NKG_CURRENT_SOURCE_FILE
|
#undef NKG_CURRENT_SOURCE_FILE
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,7 @@ namespace nkg {
|
||||||
static constexpr const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
static constexpr const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
||||||
static constexpr const char padding_character = '=';
|
static constexpr const char padding_character = '=';
|
||||||
|
|
||||||
class decoding_error : public ::nkg::exception {
|
class decoding_error;
|
||||||
public:
|
|
||||||
decoding_error(std::string_view file, int line, std::string_view message) noexcept :
|
|
||||||
::nkg::exception(file, line, message) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
static char symbol(alphabet_index_t idx);
|
static char symbol(alphabet_index_t idx);
|
||||||
|
|
||||||
|
|
@ -28,4 +24,8 @@ namespace nkg {
|
||||||
static std::vector<uint8_t> decode(std::string_view b32_string);
|
static std::vector<uint8_t> decode(std::string_view b32_string);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class base32_rfc4648::decoding_error : public ::nkg::exception {
|
||||||
|
using ::nkg::exception::exception;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,15 +6,15 @@
|
||||||
namespace nkg {
|
namespace nkg {
|
||||||
|
|
||||||
struct base64_rfc4648 {
|
struct base64_rfc4648 {
|
||||||
class backend_error : public ::nkg::exception {
|
class backend_error;
|
||||||
public:
|
|
||||||
backend_error(std::string_view file, int line, std::string_view message) noexcept :
|
|
||||||
::nkg::exception(file, line, message) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
static std::string encode(const std::vector<std::uint8_t>& data);
|
static std::string encode(const std::vector<std::uint8_t>& data);
|
||||||
|
|
||||||
static std::vector<uint8_t> decode(std::string_view str_b64);
|
static std::vector<uint8_t> decode(std::string_view str_b64);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class base64_rfc4648::backend_error : public ::nkg::exception {
|
||||||
|
using ::nkg::exception::exception;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,11 +35,7 @@ namespace nkg {
|
||||||
|
|
||||||
class navicat_serial_generator {
|
class navicat_serial_generator {
|
||||||
public:
|
public:
|
||||||
class version_error : public ::nkg::exception {
|
class version_error;
|
||||||
public:
|
|
||||||
version_error(std::string_view file, int line, std::string_view message) noexcept :
|
|
||||||
::nkg::exception(file, line, message) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static inline const DES_cblock s_des_key0 = { 0x64, 0xAD, 0xF3, 0x2F, 0xAE, 0xF2, 0x1A, 0x27 };
|
static inline const DES_cblock s_des_key0 = { 0x64, 0xAD, 0xF3, 0x2F, 0xAE, 0xF2, 0x1A, 0x27 };
|
||||||
|
|
@ -72,4 +68,8 @@ namespace nkg {
|
||||||
const std::string& serial_number_formatted() const noexcept;
|
const std::string& serial_number_formatted() const noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class navicat_serial_generator::version_error : public ::nkg::exception {
|
||||||
|
using ::nkg::exception::exception;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,23 +18,9 @@ namespace nkg {
|
||||||
using rva_t = uintptr_t;
|
using rva_t = uintptr_t;
|
||||||
using va_t = uintptr_t;
|
using va_t = uintptr_t;
|
||||||
|
|
||||||
class parse_error : public ::nkg::exception {
|
class parse_error;
|
||||||
public:
|
class bad_fo_exception;
|
||||||
parse_error(std::string_view file, int line, std::string_view message) noexcept :
|
class bad_va_exception;
|
||||||
::nkg::exception(file, line, message) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
class bad_fo_exception : public ::nkg::exception {
|
|
||||||
public:
|
|
||||||
bad_fo_exception(std::string_view file, int line, std::string_view message) noexcept :
|
|
||||||
::nkg::exception(file, line, message) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
class bad_va_exception : public ::nkg::exception {
|
|
||||||
public:
|
|
||||||
bad_va_exception(std::string_view file, int line, std::string_view message) noexcept :
|
|
||||||
::nkg::exception(file, line, message) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t m_elf_size;
|
size_t m_elf_size;
|
||||||
|
|
@ -236,4 +222,16 @@ namespace nkg {
|
||||||
const std::map<va_t, size_t>& relocation_distribute() const;
|
const std::map<va_t, size_t>& relocation_distribute() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class elf64_interpreter::parse_error : public ::nkg::exception {
|
||||||
|
using ::nkg::exception::exception;
|
||||||
|
};
|
||||||
|
|
||||||
|
class elf64_interpreter::bad_fo_exception : public ::nkg::exception {
|
||||||
|
using ::nkg::exception::exception;
|
||||||
|
};
|
||||||
|
|
||||||
|
class elf64_interpreter::bad_va_exception : public ::nkg::exception {
|
||||||
|
using ::nkg::exception::exception;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,33 +12,7 @@ namespace nkg {
|
||||||
|
|
||||||
class keystone_assembler {
|
class keystone_assembler {
|
||||||
public:
|
public:
|
||||||
class backend_error : public ::nkg::exception {
|
class backend_error;
|
||||||
public:
|
|
||||||
using error_code_t = ks_err;
|
|
||||||
|
|
||||||
private:
|
|
||||||
error_code_t m_error_code;
|
|
||||||
std::string m_error_string;
|
|
||||||
|
|
||||||
public:
|
|
||||||
backend_error(std::string_view file, int line, error_code_t keystone_err, std::string_view message) noexcept :
|
|
||||||
::nkg::exception(file, line, message), m_error_code(keystone_err), m_error_string(ks_strerror(keystone_err)) {}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
virtual bool error_code_exists() const noexcept override {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
virtual intptr_t error_code() const noexcept override {
|
|
||||||
return m_error_code;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
virtual const std::string& error_string() const noexcept override {
|
|
||||||
return m_error_string;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
resource_wrapper<resource_traits::keystone::keystone_handle> m_keystone_engine;
|
resource_wrapper<resource_traits::keystone::keystone_handle> m_keystone_engine;
|
||||||
|
|
@ -52,4 +26,32 @@ namespace nkg {
|
||||||
std::vector<uint8_t> assemble(std::string_view asm_string, uint64_t asm_address = 0) const;
|
std::vector<uint8_t> assemble(std::string_view asm_string, uint64_t asm_address = 0) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class keystone_assembler::backend_error : public ::nkg::exception {
|
||||||
|
public:
|
||||||
|
using error_code_t = ks_err;
|
||||||
|
|
||||||
|
private:
|
||||||
|
error_code_t m_error_code;
|
||||||
|
std::string m_error_string;
|
||||||
|
|
||||||
|
public:
|
||||||
|
backend_error(std::string_view file, int line, error_code_t keystone_err, std::string_view message) noexcept :
|
||||||
|
::nkg::exception(file, line, message), m_error_code(keystone_err), m_error_string(ks_strerror(keystone_err)) {}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
virtual bool error_code_exists() const noexcept override {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
virtual intptr_t error_code() const noexcept override {
|
||||||
|
return m_error_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
virtual const std::string& error_string() const noexcept override {
|
||||||
|
return m_error_string;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user