5 #include "uclient-utils.h"
7 static const char *b64 =
8 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
10 void base64_encode(const void *inbuf, unsigned int len, void *outbuf)
12 unsigned char *out = outbuf;
13 const uint8_t *in = inbuf;
17 for (i = 0; i < len - pad; i += 3) {
18 uint32_t in3 = (in[0] << 16) | (in[1] << 8) | in[2];
21 for (k = 3; k >= 0; k--) {
22 out[k] = b64[in3 & 0x3f];
30 uint32_t in2 = in[0] << (16 - 6);
35 in2 |= in[1] << (8 - 6);
36 out[2] = b64[in2 & 0x3f];
42 out[1] = b64[in2 & 0x3f];
44 out[0] = b64[in2 & 0x3f];
52 int uclient_urldecode(const char *in, char *out, bool decode_plus)
58 while ((c = *(in++))) {
60 if (!isxdigit(in[0]) || !isxdigit(in[1]))
65 c = strtol(dec, NULL, 16);
67 } else if (decode_plus && c == '+') {