Added utility function to convert byteArray to HEX string. Useful for printing fingerprint digests etc.

This commit is contained in:
Frode Roxrud Gill 2022-03-13 11:59:02 +01:00
parent 46c09fa8a5
commit 6fd3632912

View File

@ -29,6 +29,7 @@
#include "vmime/base.hpp"
#include <sstream>
#include <iostream>
namespace vmime {
@ -52,6 +53,20 @@ public:
return string(reinterpret_cast <const char*>(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