summaryrefslogtreecommitdiff
path: root/csum-file.c
diff options
context:
space:
mode:
Diffstat (limited to 'csum-file.c')
-rw-r--r--csum-file.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/csum-file.c b/csum-file.c
index 7510950fa3..60f58f662a 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -187,3 +187,19 @@ uint32_t crc32_end(struct hashfile *f)
f->do_crc = 0;
return f->crc32;
}
+
+int hashfile_checksum_valid(const unsigned char *data, size_t total_len)
+{
+ unsigned char got[GIT_MAX_RAWSZ];
+ git_hash_ctx ctx;
+ size_t data_len = total_len - the_hash_algo->rawsz;
+
+ if (total_len < the_hash_algo->rawsz)
+ return 0; /* say "too short"? */
+
+ the_hash_algo->init_fn(&ctx);
+ the_hash_algo->update_fn(&ctx, data, data_len);
+ the_hash_algo->final_fn(got, &ctx);
+
+ return hasheq(got, data + data_len);
+}