X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=sha1.cc;h=321807552535057a26c022e32d408b16b8ff4cdc;hb=a4cf5f4d8df46fa00992a210d587cd824cedcb08;hp=c7b71126daf03bc17d123e834f320938aea6ffd2;hpb=bf8eba693e2667688b83b2a4aa220ec8adcb7907;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);