From 7972a851a09177f59d4bdc2749aa3a0c621c0224 Mon Sep 17 00:00:00 2001 From: surtur Date: Thu, 20 Jan 2022 04:00:24 +0100 Subject: [PATCH] chore: consolidate,add try blocks, throw more --- accumulator.cpp | 6 ++++-- event_adder_impl.h | 24 +++++++++++++++--------- urandom_entropy_src.cpp | 12 +++++++----- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/accumulator.cpp b/accumulator.cpp index 4cc0e21..92d3e96 100644 --- a/accumulator.cpp +++ b/accumulator.cpp @@ -76,7 +76,8 @@ auto Accumulator::get_random_data(const unsigned int& n_bytes) -> std::string { data = this->Gen->generate_random_data(n_bytes); } catch (std::exception& e) { - fmt::print("{}", e.what()); + // FIXME: handle the exception + throw; } return data; } @@ -86,7 +87,8 @@ auto Accumulator::call_reseed(const std::string& seed) -> void { this->Gen->reseed(seed); } catch (std::exception& e) { - fmt::print("{}", e.what()); + // FIXME: handle the exception + throw; } } diff --git a/event_adder_impl.h b/event_adder_impl.h index e563e40..483a691 100644 --- a/event_adder_impl.h +++ b/event_adder_impl.h @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -39,16 +40,21 @@ public: } void add(const std::vector& event) override { - this->pool_id = (this->where_to) % 32; - fmt::print("[i] add to pool {}\n", this->pool_id); - int ret{this->_pools->at(this->pool_id) - .add_entropy(this->_source_id, event)}; - if (ret == 1) { - throw std::runtime_error( - "\t[!] event_adder: error adding event!\n"); + try { + this->pool_id = (this->where_to) % 32; + fmt::print("[i] add to pool {}\n", this->pool_id); + int ret{this->_pools->at(this->pool_id) + .add_entropy(this->_source_id, event)}; + if (ret == 1) { + throw std::runtime_error( + "\t[!] event_adder: error adding event!\n"); + } + // FIXME: this WILL overflow, too + ++where_to; + } + catch (std::exception& e) { + throw; } - // FIXME: this WILL overflow, too - ++where_to; } }; diff --git a/urandom_entropy_src.cpp b/urandom_entropy_src.cpp index 349c632..9618e9e 100644 --- a/urandom_entropy_src.cpp +++ b/urandom_entropy_src.cpp @@ -46,17 +46,19 @@ auto UrandomEntropySrc::event(accumulator::EventAdderImpl& adder) -> void { fmt::print(stderr, "{}", msg); throw std::runtime_error(msg); } - } - catch (std::ifstream::failure& e) { - fmt::print("io exception caugth: {}\n", e.what()); - } - try { adder.add(this->bytes); std::memset(this->bytes.data(), 0x00, this->bytes.size()); // clear out } + catch (std::ifstream::failure& e) { + // FIXME: handle the exception + fmt::print("io exception caugth: {}\n", e.what()); + throw; + } catch (std::exception& e) { + // FIXME: handle the exception fmt::print("[!] ues: exception caugth: {}\n", e.what()); + throw; } }