X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=sha1.cc;h=321807552535057a26c022e32d408b16b8ff4cdc;hb=dbba40b5a3722e4acb0cc043f0be1bebff872f27;hp=c7b71126daf03bc17d123e834f320938aea6ffd2;hpb=b1a0bfe834d45694851787317da2cd55add2d7bb;p=cumulus.git diff --git a/sha1.cc b/sha1.cc index c7b7112..3218075 100644 --- a/sha1.cc +++ b/sha1.cc @@ -30,6 +30,7 @@ #include "sha1.h" #include +#include #include #include @@ -348,6 +349,28 @@ void SHA1Checksum::process(const void *data, size_t len) sha1_process_bytes(data, len, &ctx); } +bool SHA1Checksum::process_file(const char *filename) +{ + FILE *f = fopen(filename, "rb"); + if (f == NULL) + return false; + + while (!feof(f)) { + char buf[4096]; + size_t bytes = fread(buf, 1, sizeof(buf), f); + + if (ferror(f)) { + fclose(f); + return false; + } + + process(buf, bytes); + } + + fclose(f); + return true; +} + const uint8_t *SHA1Checksum::checksum() { sha1_finish_ctx(&ctx, resbuf);