| 278 | } |
| 279 | |
| 280 | static bool gd_bytes(gd_context_t *g, const void *data, size_t length) { |
| 281 | if (!gd_check(g)) { |
| 282 | return false; |
| 283 | } |
| 284 | uint64_t count = (uint64_t)length; |
| 285 | if ((size_t)count != length || count > g->limits.max_framed_bytes - g->bytes) { |
| 286 | return gd_fail(g, CBM_STORE_GRAPH_DIGEST_LIMIT); |
| 287 | } |
| 288 | if (length && !data) { |
| 289 | return gd_fail(g, CBM_STORE_GRAPH_DIGEST_ERROR); |
| 290 | } |
| 291 | const unsigned char *p = data; |
| 292 | while (length) { |
| 293 | size_t chunk = length > GD_CHUNK_BYTES ? GD_CHUNK_BYTES : length; |
| 294 | if (!gd_check(g)) { |
| 295 | return false; |
| 296 | } |
| 297 | cbm_sha256_update(&g->sha, p, chunk); |
| 298 | g->bytes += (uint64_t)chunk; |
| 299 | if (!gd_check(g)) { |
| 300 | return false; |
| 301 | } |
| 302 | p += chunk; |
| 303 | length -= chunk; |
| 304 | } |
| 305 | return true; |
| 306 | } |
| 307 | |
| 308 | static bool gd_u8(gd_context_t *g, unsigned char value) { |
| 309 | return gd_bytes(g, &value, 1); |
no test coverage detected