From eed18331cde8358a65bb90fe59bb123285b7b71a Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 1 Mar 2018 02:53:27 -0800 Subject: [PATCH] ircd::ed25519: Fix fs::read regression from fs:: exception changes. --- ircd/sodium.cc | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/ircd/sodium.cc b/ircd/sodium.cc index f2b18a1cb..8afa52d7e 100644 --- a/ircd/sodium.cc +++ b/ircd/sodium.cc @@ -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(::sodium_malloc(crypto_sign_ed25519_SECRETKEYBYTES)), @@ -119,16 +120,8 @@ ircd::ed25519::sk::sk(const std::string &filename, reinterpret_cast(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)