0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 20:13:05 +02:00
openvpn3/openvpn/common/hexstr.hpp

34 lines
568 B
C++
Raw Normal View History

2011-09-30 00:42:37 +02:00
#ifndef OPENVPN_COMMON_HEXSTR_H
#define OPENVPN_COMMON_HEXSTR_H
#include <string>
namespace openvpn {
char hexchar(const int c)
{
if (c < 10)
return '0' + c;
else if (c < 16)
return 'a' - 10 + c;
else
return '?';
}
std::string hexstr(const unsigned char *data, size_t size)
{
std::string ret;
ret.reserve(size*2+1);
while (size--)
{
const unsigned char c = *data++;
ret += hexchar(c >> 4);
ret += hexchar(c & 0x0F);
}
return ret;
}
} // namespace openvpn
#endif // OPENVPN_COMMON_HEXSTR_H