modernize
[ghsmtp.git] / Pill.hpp
blob7553f4913311352d8c20fea4935248e634811626
1 #ifndef PILL_DOT_HPP
2 #define PILL_DOT_HPP
4 #include <climits>
5 #include <cstddef>
6 #include <cstring>
7 #include <ostream>
8 #include <string_view>
10 #include "pcg.hpp"
12 // A pill is a unit of entropy.
14 class Pill {
15 public:
16 Pill();
18 bool operator==(Pill const& that) const { return this->s_ == that.s_; }
19 bool operator!=(Pill const& that) const { return !(*this == that); }
21 std::string_view as_string_view() const
23 return std::string_view{b32_str_, b32_ndigits_};
26 private:
27 unsigned long long s_;
29 auto static constexpr b32_ndigits_ = ((sizeof(s_) * CHAR_BIT) + 4) / 5;
30 char b32_str_[b32_ndigits_ + 1];
32 friend std::ostream& operator<<(std::ostream& s, Pill const& p)
34 return s << p.as_string_view();
37 inline static pcg_extras::seed_seq_from<std::random_device> seed_source_;
38 inline static pcg64 rng_{seed_source_};
41 #endif // PILL_DOT_HPP