fortuna,generator({fmt}) print with colours

This commit is contained in:
surtur 2022-02-03 04:52:19 +01:00
parent ffca8a8d37
commit 1ec70d1161
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 13 additions and 4 deletions

View File

@ -10,6 +10,7 @@
#include <cryptopp/cryptlib.h>
#include <fmt/chrono.h>
#include <fmt/color.h>
#include <cassert>
#include <chrono>
@ -93,7 +94,11 @@ auto Fortuna::random_data(const uint64_t n_bytes) -> void {
s.clear();
}
fmt::print(stderr, "[i] fortuna: reseed ctr {}\n", get_reseed_ctr());
fmt::print(stderr, "[i] fortuna: reseed ctr ");
fmt::print(stderr,
fmt::emphasis::bold | bg(fmt::color::hot_pink),
"{}\n",
get_reseed_ctr());
if (get_reseed_ctr() == 0) {
fmt::print(stderr,
"[!] ERROR: reseed ctr is 0, PRNG not seeded!\n");
@ -112,7 +117,9 @@ auto Fortuna::random_data(const uint64_t n_bytes) -> void {
const auto end{std::chrono::system_clock::now()};
const std::chrono::duration<float> diff = end - start;
fmt::print(stderr, "random_data done - {}\n", end);
fmt::print(stderr, "getting random data took {:.{}f}s\n", diff.count(), 12);
fmt::print(stderr, "getting random data ");
fmt::print(
stderr, bg(fmt::color::dark_cyan), "took {:.{}f}s\n", diff.count(), 12);
} // random_data
auto Fortuna::moar_random_data(const uint64_t& n_bytes) -> void {

View File

@ -7,6 +7,7 @@
#include <cryptopp/filters.h>
#include <cryptopp/hex.h>
#include <cryptopp/secblock.h>
#include <fmt/color.h>
#include <fmt/core.h>
#include <algorithm>
@ -76,10 +77,11 @@ auto Generator::reseed(const std::string& s) -> void {
std::string a{fortuna::Util::do_sha(da_key + s)};
std::memmove(G.k, fortuna::Util::de_hex(a).c_str(), G.k_length);
Generator::ctr_inc();
fmt::print(stderr, "[i] generator: reseeded\n");
fmt::print(stderr, "[i] generator: ");
fmt::print(stderr, bg(fmt::color::rebecca_purple), "reseeded\n");
}
catch (std::exception& e) {
fmt::print(stderr, "{}\n", e.what());
fmt::print(stderr, bg(fmt::color::red), "{}\n", e.what());
throw;
}
}