container: root: macro: Hash: change output to CSV format
The output can now be used with container's CSV tools.
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
|
||||
|
||||
Reference in New Issue
Block a user