#pragma once #include #include static inline int base64_decode_value(unsigned char c) { if (c >= 'A' && c <= 'Z') return c - 'A'; if (c >= 'a' && c <= 'z') return c - 'a' + 26; if (c >= '0' && c <= '9') return c - '0' + 52; if (c == '+') return 62; if (c == '/') return 63; if (c == '=') return -2; return -1; } static inline int decode_base64(const unsigned char *in, size_t in_len, unsigned char *out) { size_t out_len = 0; int buf = 0; int bits = 0; for (size_t i = 0; i < in_len; ++i) { int v = base64_decode_value(in[i]); if (v == -1) { continue; } if (v == -2) { break; } buf = (buf << 6) | v; bits += 6; while (bits >= 8) { bits -= 8; out[out_len++] = (unsigned char)((buf >> bits) & 0xFF); } } return (int)out_len; }