core: don't crash on errors

fixes #19
This commit is contained in:
Vaxry
2025-04-20 23:41:54 +01:00
parent 9d3922d1d3
commit c60abae9bb
7 changed files with 35 additions and 11 deletions

View File

@@ -17,11 +17,12 @@
constexpr const char* KEY_FILENAME = "privateKey.key";
CCrypto::CCrypto() {
if (!std::filesystem::exists(NFsUtils::dataDir() + "/" + KEY_FILENAME)) {
std::error_code ec;
if (!std::filesystem::exists(NFsUtils::dataDir() + "/" + KEY_FILENAME, ec) || ec) {
Debug::log(LOG, "No private key, generating one.");
if (!genKey()) {
Debug::log(CRIT, "Couldn't generate a key.");
throw std::runtime_error("Keygen failed");
Debug::die("Keygen failed");
}
} else {
auto f = fopen((NFsUtils::dataDir() + "/" + KEY_FILENAME).c_str(), "r");
@@ -31,7 +32,7 @@ CCrypto::CCrypto() {
if (!m_evpPkey) {
Debug::log(CRIT, "Couldn't read the key.");
throw std::runtime_error("Key read openssl failed");
Debug::die("Key reading from openssl failed");
}
Debug::log(LOG, "Read private key");