accumulator: check entropy sources before adding
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
1181518a77
commit
767da88531
|
@ -3,8 +3,12 @@
|
|||
|
||||
#include "accumulator.h"
|
||||
|
||||
#include <fmt/core.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace fortuna {
|
||||
namespace accumulator {
|
||||
|
@ -19,6 +23,29 @@ Accumulator::Accumulator() noexcept {
|
|||
Accumulator::~Accumulator() noexcept {};
|
||||
|
||||
|
||||
// check if given source id is an id of an already registered entropy source
|
||||
auto Accumulator::src_is_registered(const uint8_t& id) -> bool {
|
||||
bool reg{false};
|
||||
static uint8_t _src_id{};
|
||||
|
||||
for (auto& src_id: this->entropy_sources) {
|
||||
if (src_id == id) {
|
||||
reg = true;
|
||||
_src_id = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (reg) {
|
||||
fmt::print(
|
||||
"[!] acc(add_source): entropy source \"{}\" already registered",
|
||||
_src_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
auto Accumulator::set_gen(fortuna::generator::Generator& gen) -> void {
|
||||
this->Gen = std::move(&gen);
|
||||
}
|
||||
|
|
|
@ -8,13 +8,17 @@
|
|||
#include <fmt/core.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <exception>
|
||||
#include <vector>
|
||||
|
||||
namespace fortuna {
|
||||
namespace accumulator {
|
||||
|
||||
class Accumulator {
|
||||
private:
|
||||
static constexpr const uint8_t MAX_SOURCES{255};
|
||||
std::vector<uint8_t> entropy_sources{};
|
||||
fortuna::generator::Generator* Gen;
|
||||
|
||||
protected:
|
||||
|
@ -25,12 +29,17 @@ public:
|
|||
|
||||
auto add_source() -> void {
|
||||
static uint src_id{this->src_count};
|
||||
++src_count;
|
||||
accumulator::Pool pools[32];
|
||||
EventAdderImpl event_adder(src_id, pools);
|
||||
[[maybe_unused]] bool scheduled;
|
||||
// make really sure we don't and a duplicate src_id
|
||||
if (src_id <= this->MAX_SOURCES && !src_is_registered(src_id)) {
|
||||
++src_count;
|
||||
accumulator::Pool pools[32];
|
||||
EventAdderImpl event_adder(src_id, pools);
|
||||
[[maybe_unused]] bool scheduled;
|
||||
}
|
||||
}
|
||||
|
||||
auto src_is_registered(const uint8_t& id) -> bool;
|
||||
|
||||
auto set_gen(fortuna::generator::Generator& Gen) -> void;
|
||||
|
||||
auto get_random_data(uint n_bytes) -> std::string;
|
||||
|
|
Reference in New Issue