mbox-md5-all.c revision bcb4e51a409d94ae670de96afb8483a4f7855294
89a126810703c666309310d0f3189e9834d70b5bTimo Sirainen/* Copyright (c) 2004-2018 Dovecot authors, see the included COPYING file */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen#include "lib.h"
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen#include "md5.h"
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen#include "message-parser.h"
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen#include "mbox-md5.h"
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainenstruct mbox_md5_context {
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen struct md5_context hdr_md5_ctx;
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen};
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainen
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainenstatic struct mbox_md5_context *mbox_md5_all_init(void)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen{
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen struct mbox_md5_context *ctx;
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen ctx = i_new(struct mbox_md5_context, 1);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen md5_init(&ctx->hdr_md5_ctx);
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen return ctx;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen}
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainenstatic void mbox_md5_all_more(struct mbox_md5_context *ctx,
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen struct message_header_line *hdr)
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen{
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen md5_update(&ctx->hdr_md5_ctx, hdr->value, hdr->value_len);
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen}
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainenstatic void mbox_md5_all_finish(struct mbox_md5_context *ctx,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen unsigned char result[STATIC_ARRAY 16])
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen{
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen md5_final(&ctx->hdr_md5_ctx, result);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen i_free(ctx);
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen}
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenstruct mbox_md5_vfuncs mbox_md5_all = {
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen mbox_md5_all_init,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen mbox_md5_all_more,
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen mbox_md5_all_finish
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen};
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen