surtur
03578f9016
All checks were successful
continuous-integration/drone/push Build is passing
* add event_scheduler_impl.h and properly override its base class * add urandom_entropy_src.cpp, move there logic from header * add urandom_entropy_src.cpp to CMakeLists.txt * add unique_ptr per impl: one for both EventSchedulerImpl and EventAdderImpl each * wrap a call in reinterpret_cast and reformat code * add missing includes (best effort)
44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
#ifndef FORTUNA_URANDOM_ENTROPY_SRC_CPP
|
|
#define FORTUNA_URANDOM_ENTROPY_SRC_CPP
|
|
|
|
#include "urandom_entropy_src.h"
|
|
|
|
namespace fortuna {
|
|
namespace accumulator {
|
|
|
|
std::vector<char> UrandomEntropySrc::bytes{};
|
|
|
|
auto UrandomEntropySrc::schedule(accumulator::EventSchedulerImpl scheduler)
|
|
-> void {
|
|
scheduler.schedule(std::chrono::milliseconds(100));
|
|
}
|
|
|
|
auto UrandomEntropySrc::event(accumulator::EventAdderImpl adder) -> void {
|
|
std::ifstream file;
|
|
file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
|
|
|
try {
|
|
std::ifstream urandom("/dev/urandom", std::ios::in | std::ios::binary);
|
|
// check if stream is open
|
|
if (urandom) {
|
|
urandom.read(
|
|
reinterpret_cast<char*>(&UrandomEntropySrc::bytes),
|
|
reinterpret_cast<uint64_t>(UrandomEntropySrc::bytes.size()));
|
|
urandom.close();
|
|
}
|
|
else {
|
|
// open failed
|
|
fmt::print(stderr, "Failed to open /dev/urandom\n");
|
|
}
|
|
}
|
|
catch (std::ifstream::failure& e) {
|
|
fmt::print("io exception caugth: {}\n", e.what());
|
|
}
|
|
}
|
|
|
|
|
|
} // namespace accumulator
|
|
} // namespace fortuna
|
|
|
|
#endif // FORTUNA_URANDOM_ENTROPY_SRC_CPP
|