Skip to content

Commit

Permalink
Merge pull request #272 from frodegill/bytearray_to_string
Browse files Browse the repository at this point in the history
Utility function to convert byteArray to HEX string. Useful for printing fingerprint digests etc.
  • Loading branch information
vincent-richard authored Mar 26, 2022
2 parents 56b77ca + 6fd3632 commit fc69321
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/vmime/utility/stringUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "vmime/base.hpp"

#include <sstream>
#include <iostream>


namespace vmime {
Expand All @@ -52,6 +53,20 @@ class VMIME_EXPORT stringUtils {
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
Expand Down

0 comments on commit fc69321

Please sign in to comment.