#ifndef FORTUNA_URANDOM_ENTROPY_SRC_CPP #define FORTUNA_URANDOM_ENTROPY_SRC_CPP #include "urandom_entropy_src.h" namespace fortuna { namespace accumulator { std::vector 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(&UrandomEntropySrc::bytes), reinterpret_cast(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