forked from ak-fortuna/fortuna
accumulator: use a Generator pointer
This commit is contained in:
parent
01c402300c
commit
234b87ff1f
|
@ -6,6 +6,11 @@
|
|||
namespace fortuna {
|
||||
namespace accumulator {
|
||||
|
||||
Accumulator::Accumulator() {
|
||||
this->Gen = nullptr;
|
||||
}
|
||||
Accumulator::~Accumulator() noexcept {};
|
||||
|
||||
} //namespace accumulator
|
||||
} //namespace fortuna
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue