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

Function cbm_cli_sha256_file

src/cli/cli.c:6707–6736  ·  view source on GitHub ↗

Compute the SHA-256 of a file in-process (no external hashing tool — those * differ per OS, may be absent, and mis-quote paths under cmd.exe). Writes a * 64-char hex digest + NUL to out. Returns 0 on success. Not static: * exercised directly by the self-update checksum regression test. */

Source from the content-addressed store, hash-verified

6705 * 64-char hex digest + NUL to out. Returns 0 on success. Not static:
6706 * exercised directly by the self-update checksum regression test. */
6707int cbm_cli_sha256_file(const char *path, char *out, size_t out_size) {
6708 if (out_size < SHA256_BUF_SIZE) {
6709 return CLI_ERR;
6710 }
6711 FILE *fp = cbm_fopen(path, "rb");
6712 if (!fp) {
6713 return CLI_ERR;
6714 }
6715 cbm_sha256_ctx ctx;
6716 cbm_sha256_init(&ctx);
6717 unsigned char buf[CLI_BUF_1K];
6718 size_t n;
6719 while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) {
6720 cbm_sha256_update(&ctx, buf, n);
6721 }
6722 int read_err = ferror(fp);
6723 fclose(fp);
6724 if (read_err) {
6725 return CLI_ERR;
6726 }
6727 uint8_t digest[CBM_SHA256_DIGEST_LEN];
6728 cbm_sha256_final(&ctx, digest);
6729 static const char hex[] = "0123456789abcdef";
6730 for (int i = 0; i < CBM_SHA256_DIGEST_LEN; i++) {
6731 out[i * 2] = hex[digest[i] >> 4];
6732 out[i * 2 + 1] = hex[digest[i] & 0x0f];
6733 }
6734 out[SHA256_HEX_LEN] = '\0';
6735 return 0;
6736}
6737
6738static int cli_checksum_hex_nibble(unsigned char value) {
6739 if (value >= (unsigned char)'0' && value <= (unsigned char)'9') {

Callers 3

verify_download_checksumFunction · 0.85
test_cli.cFile · 0.85
sha256_vector_okFunction · 0.85

Calls 4

cbm_fopenFunction · 0.85
cbm_sha256_initFunction · 0.85
cbm_sha256_updateFunction · 0.85
cbm_sha256_finalFunction · 0.85

Tested by 1

sha256_vector_okFunction · 0.68