1
1
Fork 0
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:
Jeff Becker 2020-10-30 15:51:22 -04:00
parent 3e5dcb34cf
commit bf1a692005
No known key found for this signature in database
GPG key ID: F357B3B42F6F9B05
2 changed files with 7 additions and 16 deletions

View file

@ -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

View file

@ -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);
};