chore: consolidate,add try blocks, throw more
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-01-20 04:00:24 +01:00
parent 44a2f4148e
commit 7972a851a0
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
3 changed files with 26 additions and 16 deletions

View File

@ -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;
}
}

View File

@ -7,6 +7,7 @@
#include <fmt/core.h>
#include <cstdint>
#include <exception>
#include <memory>
#include <stdexcept>
@ -39,16 +40,21 @@ public:
}
void add(const std::vector<char>& 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;
}
};

View File

@ -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;
}
}