forked from EvergreenCrypto/docker-finance
Merge pull request #217 into master
d83d983container: root: macro: Hash: change output to CSV format (Aaron Fiore)c604ca8container: root: macro: Random: change output to CSV format (Aaron Fiore)
This commit is contained in:
@@ -51,6 +51,7 @@ namespace botan = common::crypto::botan;
|
||||
//! \brief Hash generator macro
|
||||
class Hash final
|
||||
{
|
||||
//! Text description of Hash impl, encoded digest
|
||||
using t_hash = std::map<std::string, std::string>;
|
||||
|
||||
public:
|
||||
@@ -221,25 +222,26 @@ class Hash final
|
||||
}
|
||||
|
||||
public:
|
||||
//! \brief Print t_hash encoded digest of given message
|
||||
//! \brief Print t_hash of given message in CSV format
|
||||
//! \param message Message to encode
|
||||
static void encode(const std::string& message)
|
||||
{
|
||||
auto print = [](const std::string& title, const t_hash& hash) {
|
||||
std::cout << title;
|
||||
std::cout << "\nNOTE: outer quotes (that contain the message) will not be "
|
||||
"digested. Use escapes to digest literal quotes."
|
||||
<< std::endl;
|
||||
|
||||
for (const auto& [label, digest] : hash)
|
||||
auto print = [](const std::string& message, const t_hash& hash) {
|
||||
for (const auto& [impl, digest] : hash)
|
||||
{
|
||||
std::cout << "\n" << label << "\n" << digest << "\n";
|
||||
std::cout << impl << ",\"" << message << "\"," << digest << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
std::cout << "\nMessage:\n\n" << message << "\n";
|
||||
|
||||
print("\nEncoded (Botan):\n", Hash::botan_encode(message));
|
||||
print("\nEncoded (Crypto++):\n", Hash::cryptopp_encode(message));
|
||||
print("\nEncoded (libsodium):\n", Hash::libsodium_encode(message));
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << "\nimpl,message,digest\n";
|
||||
print(message, Hash::botan_encode(message));
|
||||
print(message, Hash::cryptopp_encode(message));
|
||||
print(message, Hash::libsodium_encode(message));
|
||||
std::cout << std::flush;
|
||||
}
|
||||
|
||||
//! \brief Wrapper to encoder
|
||||
|
||||
@@ -51,6 +51,7 @@ namespace botan = common::crypto::botan;
|
||||
//! \brief CSPRNG macro
|
||||
class Random final
|
||||
{
|
||||
//! Text description of number type, random number
|
||||
using t_rng = std::map<std::string, size_t>;
|
||||
|
||||
public:
|
||||
@@ -110,23 +111,21 @@ class Random final
|
||||
}
|
||||
|
||||
public:
|
||||
//! \brief Print t_rng Random map of CSPRNG numbers
|
||||
//! \brief Print t_rng of CSPRNG numbers in CSV format
|
||||
static void generate()
|
||||
{
|
||||
auto print = [](const std::string& title, const t_rng& rng) {
|
||||
std::cout << title << "\n";
|
||||
|
||||
for (const auto& [label, num] : rng)
|
||||
auto print = [](const std::string& impl, const t_rng& rng) {
|
||||
for (const auto& [type, num] : rng)
|
||||
{
|
||||
std::cout << label << ": " << num << "\n";
|
||||
std::cout << impl << "," << type << "," << num << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
print("\nRNG (Botan):\n", Random::botan_generate());
|
||||
print("\nRNG (Crypto++):\n", Random::cryptopp_generate());
|
||||
print("\nRNG (libsodium):\n", Random::libsodium_generate());
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << "\nimpl,type,num\n";
|
||||
print("botan::Random", Random::botan_generate());
|
||||
print("cryptopp::Random", Random::cryptopp_generate());
|
||||
print("libsodium::Random", Random::libsodium_generate());
|
||||
std::cout << std::flush;
|
||||
}
|
||||
|
||||
//! \brief Wrapper to Random generator
|
||||
|
||||
Reference in New Issue
Block a user