#ifndef FORTUNA_URANDOM_ENTROPY_SRC_H #define FORTUNA_URANDOM_ENTROPY_SRC_H #include "entropy_src.h" #include #include namespace fortuna { namespace accumulator { class UrandomEntropySrc : public EntropySrc { public: static constexpr const std::size_t max_event_length{32}; auto schedule(accumulator::EventScheduler scheduler) -> void { scheduler.schedule(std::chrono::milliseconds(100)); } auto event(accumulator::EventAdder 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(&bytes), bytes.length()); 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()); } } private: static std::vector bytes[max_event_length]; }; } //namespace accumulator } //namespace fortuna #endif//FORTUNA_URANDOM_ENTROPY_SRC_H