From 6fd36329127c9fc88019e47e6d4840e8b26e8d64 Mon Sep 17 00:00:00 2001 From: Frode Roxrud Gill Date: Sun, 13 Mar 2022 11:59:02 +0100 Subject: Added utility function to convert byteArray to HEX string. Useful for printing fingerprint digests etc. --- src/vmime/utility/stringUtils.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/vmime/utility/stringUtils.hpp b/src/vmime/utility/stringUtils.hpp index 46789406..a4b05ec3 100644 --- a/src/vmime/utility/stringUtils.hpp +++ b/src/vmime/utility/stringUtils.hpp @@ -29,6 +29,7 @@ #include "vmime/base.hpp" #include +#include namespace vmime { @@ -52,6 +53,20 @@ public: return string(reinterpret_cast (data), count); } + /** Makes a HEX string from byteArray. + * + * @param data byteArray containing data + * @return a string object containing a hex copy of the specified data + */ + static const string makeHexStringFromBytes(const byteArray& data) { + std::stringstream ss; + for (const byte_t& b : data) + { + ss << std::hex << int(b); + } + return ss.str(); + } + /** Casts a string to bytes. * * @param str string -- cgit v1.2.3