0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-15 14:31:11 +01:00

ircd::ed25519: Fix fs::read regression from fs:: exception changes.

This commit is contained in:
Jason Volk 2018-03-01 02:53:27 -08:00
parent 5a744debe2
commit eed18331cd

View file

@ -98,6 +98,7 @@ ircd::ed25519::sk::sk(pk *const &pk_arg,
ircd::ed25519::sk::sk(const std::string &filename,
pk *const &pk_arg)
try
:key
{
reinterpret_cast<uint8_t *>(::sodium_malloc(crypto_sign_ed25519_SECRETKEYBYTES)),
@ -119,16 +120,8 @@ ircd::ed25519::sk::sk(const std::string &filename,
reinterpret_cast<char *>(key.get()), SK_SZ
};
const auto existing
if(!fs::exists(filename))
{
fs::read(filename, key_data)
};
if(!existing)
{
if(fs::exists(filename))
throw error("Failed to read existing ed25519 secret key in: %s", filename);
throw_on_error
{
::crypto_sign_ed25519_keypair(pk_data, key.get())
@ -136,12 +129,22 @@ ircd::ed25519::sk::sk(const std::string &filename,
fs::write(filename, key_data);
}
else fs::read(filename, key_data);
throw_on_error
{
::crypto_sign_ed25519_sk_to_pk(pk_data, key.get())
};
}
catch(const fs::error &e)
{
throw error
{
"Failed to read existing ed25519 secret key in: %s :%s",
filename,
e.what()
};
}
ircd::ed25519::sig
ircd::ed25519::sk::sign(const const_buffer &msg)