accumulator: use a Generator pointer

This commit is contained in:
surtur 2021-12-28 06:13:03 +01:00
parent 01c402300c
commit 234b87ff1f
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
3 changed files with 19 additions and 8 deletions

View File

@ -6,6 +6,11 @@
namespace fortuna {
namespace accumulator {
Accumulator::Accumulator() {
this->Gen = nullptr;
}
Accumulator::~Accumulator() noexcept {};
} //namespace accumulator
} //namespace fortuna

View File

@ -3,6 +3,7 @@
#include "generator.h"
#include "pool.h"
#include <algorithm>
#include <exception>
#include <fmt/core.h>
@ -10,35 +11,38 @@ namespace fortuna {
namespace accumulator {
class Accumulator {
private:
fortuna::generator::Generator *Gen;
public:
constexpr static const unsigned int init_pool_num{0};
auto add_source() -> void;
auto set_gen(const fortuna::generator::Generator& _Gen) -> void {
this->Gen = _Gen;
};
auto set_gen(fortuna::generator::Generator& Gen) -> void {
this->Gen = std::move(&Gen);
}
auto get_random_data(uint n_bytes) -> std::string {
std::string data{""};
try {
data = this->Gen.generate_random_data(n_bytes);
data = this->Gen->generate_random_data(n_bytes);
} catch(std::exception& e) {
fmt::print("{}", e.what());
}
return data;
}
auto call_reseed(const std::string& seed) {
auto call_reseed(const std::string& seed) -> void {
try {
this->Gen.reseed(seed);
this->Gen->reseed(seed);
} catch(std::exception& e) {
fmt::print("{}", e.what());
}
}
Accumulator();
~Accumulator() noexcept;
private:
fortuna::generator::Generator Gen;
}; //class Accumulator
} //namespace accumulator

View File

@ -40,6 +40,7 @@ public:
try {
R.initialize_pools();
fmt::print("pools initialized\n");
accumulator.set_gen(R.Gen);
} catch(std::exception& e) {
fmt::print("{}\n", e.what());
}
@ -74,6 +75,7 @@ public:
}; // class R_state
fortuna::Fortuna::R_state R;
fortuna::accumulator::Accumulator accumulator;
}; // class Fortuna