| 150 | // --- encoding & HTTP --- |
| 151 | |
| 152 | bool base64_encode(const unsigned char *data, int size, std::string &out) { |
| 153 | DWORD needed = 0; |
| 154 | if (!CryptBinaryToStringA(data, static_cast<DWORD>(size), CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, nullptr, |
| 155 | &needed)) { |
| 156 | return false; |
| 157 | } |
| 158 | |
| 159 | if (needed == 0) { |
| 160 | out.clear(); |
| 161 | return true; |
| 162 | } |
| 163 | |
| 164 | out.assign(needed - 1, '\0'); |
| 165 | return CryptBinaryToStringA(data, static_cast<DWORD>(size), CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, &out[0], |
| 166 | &needed) == TRUE; |
| 167 | } |
| 168 | |
| 169 | bool http_post_json(const ParsedUrl &url, const std::string &body, int timeout_ms, std::string &response, |
| 170 | DWORD &status_code, const wchar_t *user_agent) { |