1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/llarp/encode.cpp

28 lines
559 B
C++
Raw Normal View History

2018-06-21 13:11:55 +02:00
#include <llarp/encode.hpp>
2018-06-21 13:13:40 +02:00
#include <stdexcept>
2018-06-21 13:11:55 +02:00
2018-06-21 13:13:40 +02:00
namespace llarp
2018-06-21 13:11:55 +02:00
{
int
char2int(char input)
2018-06-21 13:13:40 +02: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;
throw std::invalid_argument("Invalid input string");
}
void
HexDecode(const char* src, uint8_t* target)
2018-06-21 13:11:55 +02:00
{
2018-06-21 13:13:40 +02:00
while(*src && src[1])
{
*(target++) = char2int(*src) * 16 + char2int(src[1]);
2018-06-21 13:13:40 +02:00
src += 2;
}
2018-06-21 13:11:55 +02:00
}
2018-07-09 05:34:29 +02:00
} // namespace llarp