| 497 | |
| 498 | static bool server_image_media_type(const char *media_type) { |
| 499 | return media_type && |
| 500 | (!strcasecmp(media_type, "image/png") || |
| 501 | !strcasecmp(media_type, "image/jpeg") || |
| 502 | !strcasecmp(media_type, "image/jpg")); |
| 503 | } |
| 504 | |
| 505 | static bool server_image_inputs_push_base64(server_image_inputs *images, |
| 506 | const char *media_type, |
| 507 | const char *base64, |
| 508 | char marker[SERVER_IMAGE_MARKER_BYTES]) { |
| 509 | if (!server_image_media_type(media_type)) return false; |
| 510 | server_image_input image = {0}; |
| 511 | if (!server_decode_base64(base64, &image.encoded, &image.encoded_len)) |
| 512 | return false; |
| 513 | unsigned char nonce[12]; |
| 514 | if (!random_bytes(nonce, sizeof(nonce))) { |
| 515 | uint64_t fallback = (uint64_t)time(NULL) ^ |
| 516 | ((uint64_t)getpid() << 32) ^ |
| 517 | (uint64_t)(uintptr_t)images; |
| 518 | memcpy(nonce, &fallback, sizeof(fallback)); |
| 519 | memset(nonce + sizeof(fallback), 0, sizeof(nonce) - sizeof(fallback)); |
| 520 | } |
| 521 | static const char hex[] = "0123456789abcdef"; |
| 522 | size_t pos = (size_t)snprintf(image.marker, sizeof(image.marker), |
no test coverage detected