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
|
//! \brief Hash generator macro
|
||||||
class Hash final
|
class Hash final
|
||||||
{
|
{
|
||||||
|
//! Text description of Hash impl, encoded digest
|
||||||
using t_hash = std::map<std::string, std::string>;
|
using t_hash = std::map<std::string, std::string>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -221,25 +222,26 @@ class Hash final
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
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)
|
static void encode(const std::string& message)
|
||||||
{
|
{
|
||||||
auto print = [](const std::string& title, const t_hash& hash) {
|
std::cout << "\nNOTE: outer quotes (that contain the message) will not be "
|
||||||
std::cout << title;
|
"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";
|
std::cout << "\nimpl,message,digest\n";
|
||||||
|
print(message, Hash::botan_encode(message));
|
||||||
print("\nEncoded (Botan):\n", Hash::botan_encode(message));
|
print(message, Hash::cryptopp_encode(message));
|
||||||
print("\nEncoded (Crypto++):\n", Hash::cryptopp_encode(message));
|
print(message, Hash::libsodium_encode(message));
|
||||||
print("\nEncoded (libsodium):\n", Hash::libsodium_encode(message));
|
std::cout << std::flush;
|
||||||
|
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \brief Wrapper to encoder
|
//! \brief Wrapper to encoder
|
||||||
|
|||||||
Reference in New Issue
Block a user