function that encodes to base64 * output buffer is assumed to have the right length */
| 296 | /* function that encodes to base64 |
| 297 | * output buffer is assumed to have the right length */ |
| 298 | void base64encode(unsigned char *out, unsigned char *in, int inlen) |
| 299 | { |
| 300 | for (; inlen >= 3; inlen -= 3) |
| 301 | { |
| 302 | *out++ = base64digits[in[0] >> 2]; |
| 303 | *out++ = base64digits[((in[0] << 4) & 0x30) | (in[1] >> 4)]; |
| 304 | *out++ = base64digits[((in[1] << 2) & 0x3c) | (in[2] >> 6)]; |
| 305 | *out++ = base64digits[in[2] & 0x3f]; |
| 306 | in += 3; |
| 307 | } |
| 308 | |
| 309 | if (inlen > 0) |
| 310 | { |
| 311 | unsigned char fragment; |
| 312 | |
| 313 | *out++ = base64digits[in[0] >> 2]; |
| 314 | fragment = (in[0] << 4) & 0x30; |
| 315 | |
| 316 | if (inlen > 1) |
| 317 | fragment |= in[1] >> 4; |
| 318 | |
| 319 | *out++ = base64digits[fragment]; |
| 320 | *out++ = (inlen < 2) ? '=' : base64digits[(in[1] << 2) & 0x3c]; |
| 321 | *out++ = '='; |
| 322 | |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | /* function that encodes to base64URL |
| 327 | * output buffer is assumed to have the right length */ |
no outgoing calls
no test coverage detected