| 220 | } |
| 221 | |
| 222 | static void td_digest(cbm_test_declarations_t *declarations, const char *bytes, size_t len, |
| 223 | bool absent) { |
| 224 | cbm_sha256_ctx hash; |
| 225 | cbm_sha256_init(&hash); |
| 226 | const char *domain = absent ? "cbm-test-config-absent-v1" : "cbm-test-config-bytes-v1"; |
| 227 | cbm_sha256_update(&hash, domain, strlen(domain) + 1); |
| 228 | if (len) |
| 229 | cbm_sha256_update(&hash, bytes, len); |
| 230 | uint8_t digest[CBM_SHA256_DIGEST_LEN]; |
| 231 | cbm_sha256_final(&hash, digest); |
| 232 | static const char hex[] = "0123456789abcdef"; |
| 233 | for (int i = 0; i < CBM_SHA256_DIGEST_LEN; i++) { |
| 234 | declarations->digest[i * 2] = hex[digest[i] >> 4]; |
| 235 | declarations->digest[i * 2 + 1] = hex[digest[i] & 15]; |
| 236 | } |
| 237 | declarations->digest[CBM_SHA256_HEX_LEN] = '\0'; |
| 238 | } |
| 239 | |
| 240 | cbm_test_declarations_t *cbm_test_declarations_parse(const char *bytes, size_t len, bool absent) { |
| 241 | if (len > TD_MAX_BYTES || (absent && len) || (!absent && (!bytes || !len)) || |
no test coverage detected