0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-11 06:28:55 +02:00

ircd::ed25519: Add non-throwing failure state for instances; bool operators.

This commit is contained in:
Jason Volk 2020-09-10 22:44:09 -07:00
parent 7493ec4f0e
commit cbeedf2cf7
2 changed files with 15 additions and 1 deletions

View file

@ -32,6 +32,9 @@ class ircd::ed25519::sk
std::unique_ptr<uint8_t[], void (*)(void *)> key;
public:
operator bool() const { return bool(key); }
bool operator!() const { return !key; }
sig sign(const const_buffer &msg) const;
sk(const string_view &filename, pk *const & = nullptr);

View file

@ -126,7 +126,12 @@ try
reinterpret_cast<char *>(key.get()), SK_SZ
};
if(!fs::exists(filename) && !ircd::write_avoid)
const bool exists
{
filename && fs::exists(filename)
};
if(!exists && !ircd::write_avoid)
{
nacl::throw_on_error
{
@ -135,6 +140,12 @@ try
fs::write(filename, key_data);
}
else if(!exists)
{
zero(pk);
key.reset();
return;
}
else fs::read(filename, key_data);
nacl::throw_on_error