2018-06-13 13:18:18 +00:00
|
|
|
#ifndef LLARP_ENCODE_HPP
|
|
|
|
#define LLARP_ENCODE_HPP
|
2018-06-21 13:04:45 +00:00
|
|
|
#include <stdint.h>
|
2018-06-25 15:12:08 +00:00
|
|
|
#include <cstdlib>
|
2018-06-13 13:18:18 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
/// encode V as hex to stack
|
|
|
|
/// null terminate
|
|
|
|
/// return pointer to base of stack buffer on success otherwise returns
|
|
|
|
/// nullptr
|
|
|
|
template < typename V, typename Stack >
|
|
|
|
const char*
|
|
|
|
HexEncode(const V& value, Stack& stack)
|
|
|
|
{
|
|
|
|
size_t idx = 0;
|
|
|
|
char* ptr = &stack[0];
|
|
|
|
char* end = ptr + sizeof(stack);
|
|
|
|
while(idx < value.size())
|
|
|
|
{
|
|
|
|
auto wrote = snprintf(ptr, end - ptr, "%.2x", value[idx]);
|
|
|
|
if(wrote == -1)
|
|
|
|
return nullptr;
|
|
|
|
ptr += wrote;
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
*ptr = 0;
|
|
|
|
return &stack[0];
|
|
|
|
}
|
2018-06-21 11:13:40 +00:00
|
|
|
|
2018-06-25 15:12:08 +00:00
|
|
|
int
|
|
|
|
char2int(char input);
|
|
|
|
void
|
|
|
|
HexDecode(const char* src, uint8_t* target);
|
2018-06-13 13:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|