mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
key manager should throw on failures
This commit is contained in:
parent
3e5dcb34cf
commit
bf1a692005
2 changed files with 7 additions and 16 deletions
|
@ -175,32 +175,23 @@ namespace llarp
|
|||
|
||||
bool
|
||||
KeyManager::loadOrCreateKey(
|
||||
const fs::path& filepath,
|
||||
fs::path path,
|
||||
llarp::SecretKey& key,
|
||||
std::function<void(llarp::SecretKey& key)> keygen)
|
||||
{
|
||||
fs::path path(filepath);
|
||||
std::error_code ec;
|
||||
if (!fs::exists(path, ec))
|
||||
if (not fs::exists(path))
|
||||
{
|
||||
if (ec)
|
||||
{
|
||||
LogError("Error checking key", filepath, ec.message());
|
||||
return false;
|
||||
}
|
||||
|
||||
LogInfo("Generating new key", filepath);
|
||||
LogInfo("Generating new key", path);
|
||||
keygen(key);
|
||||
|
||||
if (!key.SaveToFile(filepath))
|
||||
if (!key.SaveToFile(path))
|
||||
{
|
||||
LogError("Failed to save new key");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
LogDebug("Loading key from file ", filepath);
|
||||
return key.LoadFromFile(filepath);
|
||||
LogDebug("Loading key from file ", path);
|
||||
return key.LoadFromFile(path);
|
||||
}
|
||||
|
||||
} // namespace llarp
|
||||
|
|
|
@ -82,7 +82,7 @@ namespace llarp
|
|||
/// @param keygen is a function that will generate the key if needed
|
||||
static bool
|
||||
loadOrCreateKey(
|
||||
const fs::path& filepath,
|
||||
fs::path filepath,
|
||||
llarp::SecretKey& key,
|
||||
std::function<void(llarp::SecretKey& key)> keygen);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue