Skip to content

Commit 6db6552

Browse files
committed
refactor: Reduce number of SanityChecks return values
1 parent b3e7de7 commit 6db6552

File tree

3 files changed

+10
-26
lines changed

3 files changed

+10
-26
lines changed

src/init.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,21 +1096,8 @@ static bool LockDataDirectory(bool probeOnly)
10961096
bool AppInitSanityChecks(const kernel::Context& kernel)
10971097
{
10981098
// ********************************************************* Step 4: sanity checks
1099-
auto maybe_error = kernel::SanityChecks(kernel);
1100-
1101-
if (maybe_error.has_value()) {
1102-
switch (maybe_error.value()) {
1103-
case kernel::SanityCheckError::ERROR_ECC:
1104-
InitError(Untranslated("Elliptic curve cryptography sanity check failure. Aborting."));
1105-
break;
1106-
case kernel::SanityCheckError::ERROR_RANDOM:
1107-
InitError(Untranslated("OS cryptographic RNG sanity check failure. Aborting."));
1108-
break;
1109-
case kernel::SanityCheckError::ERROR_CHRONO:
1110-
InitError(Untranslated("Clock epoch mismatch. Aborting."));
1111-
break;
1112-
} // no default case, so the compiler can warn about missing cases
1113-
1099+
if (auto error = kernel::SanityChecks(kernel)) {
1100+
InitError(*error);
11141101
return InitError(strprintf(_("Initialization sanity check failed. %s is shutting down."), PACKAGE_NAME));
11151102
}
11161103

src/kernel/checks.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@
77
#include <key.h>
88
#include <random.h>
99
#include <util/time.h>
10+
#include <util/translation.h>
1011

1112
namespace kernel {
1213

13-
std::optional<SanityCheckError> SanityChecks(const Context&)
14+
std::optional<bilingual_str> SanityChecks(const Context&)
1415
{
1516
if (!ECC_InitSanityCheck()) {
16-
return SanityCheckError::ERROR_ECC;
17+
return Untranslated("Elliptic curve cryptography sanity check failure. Aborting.");
1718
}
1819

1920
if (!Random_SanityCheck()) {
20-
return SanityCheckError::ERROR_RANDOM;
21+
return Untranslated("OS cryptographic RNG sanity check failure. Aborting.");
2122
}
2223

2324
if (!ChronoSanityCheck()) {
24-
return SanityCheckError::ERROR_CHRONO;
25+
return Untranslated("Clock epoch mismatch. Aborting.");
2526
}
2627

2728
return std::nullopt;

src/kernel/checks.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,16 @@
77

88
#include <optional>
99

10+
struct bilingual_str;
11+
1012
namespace kernel {
1113

1214
struct Context;
1315

14-
enum class SanityCheckError {
15-
ERROR_ECC,
16-
ERROR_RANDOM,
17-
ERROR_CHRONO,
18-
};
19-
2016
/**
2117
* Ensure a usable environment with all necessary library support.
2218
*/
23-
std::optional<SanityCheckError> SanityChecks(const Context&);
19+
std::optional<bilingual_str> SanityChecks(const Context&);
2420

2521
}
2622

0 commit comments

Comments
 (0)