From 9019a184494e6fc220bcc1eb8f47f33fe0f3e506 Mon Sep 17 00:00:00 2001 From: yzrh Date: Sun, 1 Jan 2023 10:44:27 +0000 Subject: Split md5 function. Signed-off-by: yzrh --- src/pdf_writer.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/pdf_writer.c') diff --git a/src/pdf_writer.c b/src/pdf_writer.c index be64e49..465d26b 100644 --- a/src/pdf_writer.c +++ b/src/pdf_writer.c @@ -5,11 +5,9 @@ */ #include -#include #include -#include - +#include "md5.h" #include "pdf.h" int @@ -144,11 +142,11 @@ pdf_dump_trailer(pdf_object_t **pdf, FILE **fp, int xref) buf_size = snprintf(buf, 64, "%lx%x", timestamp, size); #endif - unsigned char str[64]; - memcpy(str, buf, 64); + int fid_size; + unsigned char *fid; - unsigned char fid[MD5_DIGEST_LENGTH]; - MD5(str, buf_size, fid); + if (strmd5(&fid, &fid_size, (unsigned char *) buf, buf_size) != 0) + return 1; pdf_object_t *ptr = *pdf; while (ptr->next != NULL) @@ -172,7 +170,7 @@ pdf_dump_trailer(pdf_object_t **pdf, FILE **fp, int xref) for (int i = 0; i < 2; i++) { fputs("<", *fp); - for (int j = 0; j < MD5_DIGEST_LENGTH; j++) + for (int j = 0; j < fid_size; j++) fprintf(*fp, "%02x", fid[j]); fputs(">", *fp); @@ -191,5 +189,7 @@ pdf_dump_trailer(pdf_object_t **pdf, FILE **fp, int xref) fputs("%%EOF\n", *fp); + free(fid); + return 0; } -- cgit v1.2.3