-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.h
47 lines (35 loc) · 764 Bytes
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include <string>
#include <sstream>
#ifdef _MSC_VER
# include <cstdint>
#else
# include <stdint.h>
#endif
namespace utils {
//
// Crypto
//
static const int SIGNATURE_LENGTH = 64; // in bytes
bool signature_verify(const uint8_t *sig,
const uint8_t *data,
size_t datalen);
//
// UTF-8 codec
//
std::string utf8_encode(const std::wstring &str);
std::wstring utf8_decode(const std::string &str);
//
// Hex codec
//
template <typename T>
inline std::string hex_encode(const T &val)
{
std::ostringstream stream;
stream << std::hex << val;
return stream.str();
}
template <>
std::string hex_encode<std::string>(const std::string &str);
std::string hex_decode(const std::string &hex);
}