Merge pull request #272 from frodegill/bytearray_to_string

Utility function to convert byteArray to HEX string. Useful for printing fingerprint digests etc.
This commit is contained in:
Vincent Richard 2022-03-26 22:30:00 +01:00 committed by GitHub
commit fc69321d53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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