lokinet/llarp/encode.cpp

28 lines
516 B
C++
Raw Normal View History

2018-06-21 11:11:55 +00:00
#include <llarp/encode.hpp>
2018-06-21 11:13:40 +00:00
#include <stdexcept>
2018-06-21 11:11:55 +00:00
2018-06-21 11:13:40 +00:00
namespace llarp
2018-06-21 11:11:55 +00:00
{
int
char2int(char input)
2018-06-21 11:13:40 +00:00
{
if(input >= '0' && input <= '9')
return input - '0';
if(input >= 'A' && input <= 'F')
return input - 'A' + 10;
if(input >= 'a' && input <= 'f')
return input - 'a' + 10;
2018-09-04 19:15:06 +00:00
return 0;
2018-06-21 11:13:40 +00:00
}
void
HexDecode(const char* src, uint8_t* target)
2018-06-21 11:11:55 +00:00
{
2018-06-21 11:13:40 +00:00
while(*src && src[1])
{
*(target++) = char2int(*src) * 16 + char2int(src[1]);
2018-06-21 11:13:40 +00:00
src += 2;
}
2018-06-21 11:11:55 +00:00
}
2018-07-09 03:34:29 +00:00
} // namespace llarp