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:
parent
7493ec4f0e
commit
cbeedf2cf7
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue