changeset 19690:f2430d582c74

lib-mail: Changed message_header_hash_more() to support any hash algorithm
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 01 Feb 2016 17:56:49 +0200
parents 8bcb62e748b9
children 69502e2013f3
files src/doveadm/dsync/dsync-mail.c src/lib-mail/message-header-hash.c src/lib-mail/message-header-hash.h src/lib-mail/test-message-header-hash.c
diffstat 4 files changed, 12 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/doveadm/dsync/dsync-mail.c	Mon Feb 01 17:38:11 2016 +0200
+++ b/src/doveadm/dsync/dsync-mail.c	Mon Feb 01 17:56:49 2016 +0200
@@ -50,7 +50,8 @@
 			break;
 		if (size == 0)
 			break;
-		message_header_hash_more(&md5_ctx, version, data, size);
+		message_header_hash_more(&hash_method_md5, &md5_ctx, version,
+					 data, size);
 		i_stream_skip(input, size);
 	}
 	if (input->stream_errno != 0)
--- a/src/lib-mail/message-header-hash.c	Mon Feb 01 17:38:11 2016 +0200
+++ b/src/lib-mail/message-header-hash.c	Mon Feb 01 17:56:49 2016 +0200
@@ -1,10 +1,10 @@
 /* Copyright (c) 2013-2016 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
-#include "md5.h"
+#include "hash-method.h"
 #include "message-header-hash.h"
 
-void message_header_hash_more(struct md5_context *md5_ctx,
+void message_header_hash_more(const struct hash_method *method, void *context,
 			      unsigned int version,
 			      const unsigned char *data, size_t size)
 {
@@ -13,7 +13,7 @@
 	i_assert(version == 1 || version == 2);
 
 	if (version == 1) {
-		md5_update(md5_ctx, data, size);
+		method->loop(context, data, size);
 		return;
 	}
 	/* - Dovecot IMAP replaces NULs with 0x80 character.
@@ -35,11 +35,11 @@
 		    (data[i] != '\t' && data[i] != '\n')) {
 			/* remove repeated '?' */
 			if (start < i || i == 0) {
-				md5_update(md5_ctx, data + start, i-start);
-				md5_update(md5_ctx, "?", 1);
+				method->loop(context, data + start, i-start);
+				method->loop(context, "?", 1);
 			}
 			start = i+1;
 		}
 	}
-	md5_update(md5_ctx, data + start, i-start);
+	method->loop(context, data + start, i-start);
 }
--- a/src/lib-mail/message-header-hash.h	Mon Feb 01 17:38:11 2016 +0200
+++ b/src/lib-mail/message-header-hash.h	Mon Feb 01 17:56:49 2016 +0200
@@ -1,9 +1,9 @@
 #ifndef MESSAGE_HEADER_HASH_H
 #define MESSAGE_HEADER_HASH_H
 
-struct md5_context;
+struct hash_method;
 
-void message_header_hash_more(struct md5_context *md5_ctx,
+void message_header_hash_more(const struct hash_method *method, void *context,
 			      unsigned int version,
 			      const unsigned char *data, size_t size);
 
--- a/src/lib-mail/test-message-header-hash.c	Mon Feb 01 17:38:11 2016 +0200
+++ b/src/lib-mail/test-message-header-hash.c	Mon Feb 01 17:56:49 2016 +0200
@@ -19,7 +19,8 @@
 
 	test_begin("dsync_mail_hash_more v2");
 	md5_init(&md5_ctx);
-	message_header_hash_more(&md5_ctx, 2, test_input, sizeof(test_input)-1);
+	message_header_hash_more(&hash_method_md5, &md5_ctx, 2,
+				 test_input, sizeof(test_input)-1);
 	md5_final(&md5_ctx, md5_input);
 
 	md5_init(&md5_ctx);