summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvipdfm-x/pdfencrypt.c
diff options
context:
space:
mode:
authorAkira Kakuto <kakuto@fuk.kindai.ac.jp>2018-09-15 21:18:43 +0000
committerAkira Kakuto <kakuto@fuk.kindai.ac.jp>2018-09-15 21:18:43 +0000
commitb48ee037bd610ca845b3d7e070fb73284083423f (patch)
tree2cb5bf32fa459b3f3bde84aca83ab45eb4c7a661 /Build/source/texk/dvipdfm-x/pdfencrypt.c
parent1256fc8fd7b2e80c314e3a36c41012b70abf92f5 (diff)
Cleanup. Remove duplicated code. Reorganize initialization process (S. Hirata).
git-svn-id: svn://tug.org/texlive/trunk@48671 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/dvipdfm-x/pdfencrypt.c')
-rw-r--r--Build/source/texk/dvipdfm-x/pdfencrypt.c80
1 files changed, 34 insertions, 46 deletions
diff --git a/Build/source/texk/dvipdfm-x/pdfencrypt.c b/Build/source/texk/dvipdfm-x/pdfencrypt.c
index 23f4ea5c94b..f34e41c0fc8 100644
--- a/Build/source/texk/dvipdfm-x/pdfencrypt.c
+++ b/Build/source/texk/dvipdfm-x/pdfencrypt.c
@@ -32,6 +32,8 @@
#include "numbers.h"
#include "error.h"
#include "dpxconf.h"
+#include "dpxutil.h"
+
#include "pdfobj.h"
#include "unicode.h"
#include "dpxcrypt.h"
@@ -43,6 +45,9 @@
* TODO: Convert password to PDFDocEncoding. SASLPrep stringpref for AESV3.
*/
+static void pdf_enc_set_passwd (unsigned int bits, unsigned int perm,
+ const char *oplain, const char *uplain);
+
/* PDF-2.0 is not published yet. */
#define USE_ADOBE_EXTENSION 1
@@ -82,57 +87,20 @@ static const unsigned char padding_bytes[32] = {
0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a
};
-static void
-pdf_enc_init (int use_aes, int encrypt_metadata)
-{
- time_t current_time;
- struct pdf_sec *p = &sec_data;
-
- current_time = get_unique_time_if_given();
- if (current_time == INVALID_EPOCH_VALUE)
- current_time = time(NULL);
- srand(current_time); /* For AES IV */
- p->setting.use_aes = use_aes;
- p->setting.encrypt_metadata = encrypt_metadata;
- p->setting.need_adobe_extension = 0;
-}
-
-#define PRODUCER \
-"%s-%s, Copyright 2002-2015 by Jin-Hwan Cho, Matthias Franz, and Shunsaku Hirata"
-
void
-pdf_enc_compute_id_string (char *dviname, char *pdfname)
+pdf_enc_compute_id_string (const char *producer,
+ const char *dviname, const char *pdfname)
{
struct pdf_sec *p = &sec_data;
- char *date_string, *producer;
- time_t current_time;
- struct tm *bd_time;
+ char datestr[32];
MD5_CONTEXT md5;
- /* FIXME: This should be placed in main() or somewhere. */
- pdf_enc_init(1, 1);
-
MD5_init(&md5);
-
- date_string = NEW(15, char);
- current_time = get_unique_time_if_given();
- if (current_time == INVALID_EPOCH_VALUE) {
- time(&current_time);
- bd_time = localtime(&current_time);
- } else {
- bd_time = gmtime(&current_time);
- }
- sprintf(date_string, "%04d%02d%02d%02d%02d%02d",
- bd_time->tm_year + 1900, bd_time->tm_mon + 1, bd_time->tm_mday,
- bd_time->tm_hour, bd_time->tm_min, bd_time->tm_sec);
- MD5_write(&md5, (unsigned char *)date_string, strlen(date_string));
- RELEASE(date_string);
-
- producer = NEW(strlen(PRODUCER)+strlen(my_name)+strlen(VERSION), char);
- sprintf(producer, PRODUCER, my_name, VERSION);
- MD5_write(&md5, (unsigned char *)producer, strlen(producer));
- RELEASE(producer);
-
+ /* Don't use timezone for compatibility */
+ dpx_util_format_asn_date(datestr, 0);
+ MD5_write(&md5, (unsigned char *)datestr, strlen(datestr));
+ if (producer)
+ MD5_write(&md5, (unsigned char *)producer, strlen(producer));
if (dviname)
MD5_write(&md5, (unsigned char *)dviname, strlen(dviname));
if (pdfname)
@@ -140,6 +108,26 @@ pdf_enc_compute_id_string (char *dviname, char *pdfname)
MD5_final(p->ID, &md5);
}
+int
+pdf_init_encryption (struct pdf_enc_setting settings)
+{
+ time_t current_time;
+ struct pdf_sec *p = &sec_data;
+
+ current_time = dpx_util_get_unique_time_if_given();
+ if (current_time == INVALID_EPOCH_VALUE)
+ current_time = time(NULL);
+ srand(current_time); /* For AES IV */
+ p->setting.use_aes = settings.use_aes;
+ p->setting.encrypt_metadata = settings.encrypt_metadata;
+ p->setting.need_adobe_extension = 0;
+
+ pdf_enc_set_passwd(settings.key_size, settings.permission,
+ settings.oplain, settings.uplain);
+
+ return 0;
+}
+
static void
passwd_padding (const char *src, unsigned char *dst)
{
@@ -517,7 +505,7 @@ preproc_password (const char *passwd, char *outbuf, int V)
return error;
}
-void
+static void
pdf_enc_set_passwd (unsigned int bits, unsigned int perm,
const char *oplain, const char *uplain)
{