MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / sha256_vector_ok

Function sha256_vector_ok

tests/test_cli.c:3023–3043  ·  view source on GitHub ↗

Hash `content` (len bytes) via a temp file and compare to expected hex. * Returns 1 on match, 0 otherwise. */

Source from the content-addressed store, hash-verified

3021/* Hash `content` (len bytes) via a temp file and compare to expected hex.
3022 * Returns 1 on match, 0 otherwise. */
3023static int sha256_vector_ok(const void *content, size_t len, const char *expected) {
3024 char path[512];
3025 snprintf(path, sizeof(path), "%s/cbm_sha_XXXXXX", cbm_tmpdir());
3026 int fd = cbm_mkstemp(path);
3027 if (fd < 0) {
3028 return 0;
3029 }
3030 FILE *fp = fdopen(fd, "wb");
3031 if (!fp) {
3032 return 0;
3033 }
3034 if (len > 0) {
3035 fwrite(content, 1, len, fp);
3036 }
3037 fclose(fp);
3038
3039 char digest[128] = {0};
3040 int rc = cbm_cli_sha256_file(path, digest, sizeof(digest));
3041 remove(path);
3042 return rc == 0 && strcmp(digest, expected) == 0;
3043}
3044
3045/* NIST FIPS 180-4 SHA-256 test vectors: empty input, a single block ("abc"),
3046 * and a 56-byte input that forces the length padding into a second block. */

Callers 1

test_cli.cFile · 0.85

Calls 3

cbm_tmpdirFunction · 0.85
cbm_mkstempFunction · 0.85
cbm_cli_sha256_fileFunction · 0.85

Tested by

no test coverage detected