Split md5 function.
Signed-off-by: yzrh <yzrh@noema.org>
This commit is contained in:
parent
a18de8f2ef
commit
9019a18449
4 changed files with 43 additions and 10 deletions
|
@ -4,11 +4,11 @@
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
#
|
#
|
||||||
|
|
||||||
src = melon.c iconv.c zlib.c jbig2.c jpeg.c jp2.c \
|
src = melon.c iconv.c zlib.c jbig2.c jpeg.c jp2.c md5.c \
|
||||||
cnki_caj.c cnki_hn.c cnki_kdh.c cnki_outline_tree.c cnki_pdf.c \
|
cnki_caj.c cnki_hn.c cnki_kdh.c cnki_outline_tree.c cnki_pdf.c \
|
||||||
cnki_zlib.c cnki_jbig.c cnki_jbig_dec.c cnki_jbig2.c cnki.c \
|
cnki_zlib.c cnki_jbig.c cnki_jbig_dec.c cnki_jbig2.c cnki.c \
|
||||||
pdf_cnki.c pdf_get.c pdf_parser.c pdf_writer.c pdf.c
|
pdf_cnki.c pdf_get.c pdf_parser.c pdf_writer.c pdf.c
|
||||||
inc = extern.h version.h iconv.h zlib.h jbig2.h jpeg.h jp2.h \
|
inc = extern.h version.h iconv.h zlib.h jbig2.h jpeg.h jp2.h md5.h \
|
||||||
cnki.h pdf_cnki.h cnki_jbig.h cnki_jbig_dec.h pdf.h
|
cnki.h pdf_cnki.h cnki_jbig.h cnki_jbig_dec.h pdf.h
|
||||||
|
|
||||||
obj = ${src:.c=.o}
|
obj = ${src:.c=.o}
|
||||||
|
|
24
src/md5.c
Normal file
24
src/md5.c
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023, yzrh <yzrh@noema.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <openssl/md5.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
strmd5(unsigned char **dst, int *dst_size,
|
||||||
|
const unsigned char * restrict src, int src_size)
|
||||||
|
{
|
||||||
|
*dst_size = MD5_DIGEST_LENGTH;
|
||||||
|
*dst = malloc(*dst_size);
|
||||||
|
|
||||||
|
if (*dst == NULL)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
MD5(src, src_size, *dst);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
9
src/md5.h
Normal file
9
src/md5.h
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023, yzrh <yzrh@noema.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
strmd5(unsigned char **dst, int *dst_size,
|
||||||
|
const unsigned char * restrict src, int src_size);
|
|
@ -5,11 +5,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include <openssl/md5.h>
|
#include "md5.h"
|
||||||
|
|
||||||
#include "pdf.h"
|
#include "pdf.h"
|
||||||
|
|
||||||
int
|
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);
|
buf_size = snprintf(buf, 64, "%lx%x", timestamp, size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
unsigned char str[64];
|
int fid_size;
|
||||||
memcpy(str, buf, 64);
|
unsigned char *fid;
|
||||||
|
|
||||||
unsigned char fid[MD5_DIGEST_LENGTH];
|
if (strmd5(&fid, &fid_size, (unsigned char *) buf, buf_size) != 0)
|
||||||
MD5(str, buf_size, fid);
|
return 1;
|
||||||
|
|
||||||
pdf_object_t *ptr = *pdf;
|
pdf_object_t *ptr = *pdf;
|
||||||
while (ptr->next != NULL)
|
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++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
fputs("<", *fp);
|
fputs("<", *fp);
|
||||||
|
|
||||||
for (int j = 0; j < MD5_DIGEST_LENGTH; j++)
|
for (int j = 0; j < fid_size; j++)
|
||||||
fprintf(*fp, "%02x", fid[j]);
|
fprintf(*fp, "%02x", fid[j]);
|
||||||
|
|
||||||
fputs(">", *fp);
|
fputs(">", *fp);
|
||||||
|
@ -191,5 +189,7 @@ pdf_dump_trailer(pdf_object_t **pdf, FILE **fp, int xref)
|
||||||
|
|
||||||
fputs("%%EOF\n", *fp);
|
fputs("%%EOF\n", *fp);
|
||||||
|
|
||||||
|
free(fid);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue