]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: Changed message_header_hash_more() to support any hash algorithm
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 1 Feb 2016 15:56:49 +0000 (17:56 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 1 Feb 2016 15:56:49 +0000 (17:56 +0200)
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

index 351a2f2a4b5d3733df18eb4d1874711b689b2059..0d5ce53dbfeaad2bcbe9eab79fa8b50197ab30fa 100644 (file)
@@ -50,7 +50,8 @@ int dsync_mail_get_hdr_hash(struct mail *mail, unsigned int version,
                        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)
index 289ef20c88af6fd74c8f7ee33776f52a9a840e38..fa6b183bc0a8bdf60bef27d7698cf94b07283d79 100644 (file)
@@ -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 @@ void message_header_hash_more(struct md5_context *md5_ctx,
        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 @@ void message_header_hash_more(struct md5_context *md5_ctx,
                    (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);
 }
index 3e5625cb1ce9e0849056f8c9eb8f07e56f27ac85..be6d4499723f7bb777821ac90ed11375aa578b11 100644 (file)
@@ -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);
 
index 8133ad18418aa0257122a8a65f9b5f88dea6d034..5a32328ccb8e5e648696aa1316adf400aa3a39c7 100644 (file)
@@ -19,7 +19,8 @@ static void test_dsync_mail_hash_more(void)
 
        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);