aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--camel/md5-utils.c29
-rw-r--r--camel/md5-utils.h4
3 files changed, 36 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 6dc63a38fe..afafba88fe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,9 @@
changed names to follow camel style.
(md5_get_digest_from_stream):
new methods.
+ (md5_get_digest_from_file):
+ new function : get file md5 signature.
+ To be used in providers code.
* camel/md5-utils.c: imported md5 coding
routine from rpm. Compiles.
diff --git a/camel/md5-utils.c b/camel/md5-utils.c
index 6d8039a0ba..aac720e8e9 100644
--- a/camel/md5-utils.c
+++ b/camel/md5-utils.c
@@ -316,3 +316,32 @@ md5_get_digest_from_stream (CamelStream *stream, gint buffer_size, guchar digest
+void
+md5_get_digest_from_file (gchar *filename, gint buffer_size, guchar digest[16])
+{
+ MD5Context ctx;
+ guchar tmp_buf[1024];
+ gint nb_bytes_read;
+ FILE *fp;
+
+ md5_init (&ctx);
+ fp = fopen(filename, "r");
+ if (!fp) {
+ return;
+ }
+
+ while ((nb_bytes_read = fread (tmp_buf, sizeof (guchar), 1024, fp)) > 0)
+ md5_update (&ctx, tmp_buf, nb_bytes_read);
+
+ if (ferror(fp)) {
+ fclose(fp);
+ return;
+ }
+
+ md5_final (digest, &ctx);
+
+}
+
+
+
+
diff --git a/camel/md5-utils.h b/camel/md5-utils.h
index 3c403e86d2..cb4768bbac 100644
--- a/camel/md5-utils.h
+++ b/camel/md5-utils.h
@@ -41,5 +41,9 @@ typedef struct {
void md5_get_digest (const gchar *buffer, gint buffer_size, guchar digest[16]);
void md5_get_digest_from_stream (CamelStream *stream, gint buffer_size, guchar digest[16]);
+/* use this onr when speed is needed */
+/* for use in provider code only */
+void md5_get_digest_from_file (gchar *filename, gint buffer_size, guchar digest[16]);
+
#endif /* MD5_UTILS_H */