summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2017-12-07 18:31:37 +0000
committerRobin Watts <robin.watts@artifex.com>2018-01-05 11:47:08 +0000
commitfd0bf575229a79bc22901b0bd8ba4dbd356faa22 (patch)
tree3041da3cb23e3df8fda8f7f9cb0f8fdcdb94a626 /include
parent25593f4f9df0c4a9b9adaa84aaa33fe2a89087f6 (diff)
downloadmupdf-fd0bf575229a79bc22901b0bd8ba4dbd356faa22.tar.xz
Enable saving of encrypted PDF files.
We need both RC4 and AES encryption. RC4 is a straight reversable stream, and our AES library knows how to encrypt as well as decrypt, so it's "just" a matter of calling them correctly. We therefore expose a generic "encrypt this data" routine (and a matching "how long will the data be once encrypted" routine) within pdf-crypt.c. We then extend our our PDF object output routines to call these. This is enough to get encrypted data preserved over calls to mutool clean. Unfortunately the created files aren't readable, due to 2 further problems, also fixed here. Firstly, mutool clean does not preserve the Encrypt entry in the trailer. This is a simple fix. Secondly, we are required NOT to encrypt the Encrypt entry. This requires us to spot the crypt entry and to special case it.
Diffstat (limited to 'include')
-rw-r--r--include/mupdf/pdf/crypt.h4
-rw-r--r--include/mupdf/pdf/document.h1
-rw-r--r--include/mupdf/pdf/object.h3
3 files changed, 7 insertions, 1 deletions
diff --git a/include/mupdf/pdf/crypt.h b/include/mupdf/pdf/crypt.h
index cb8eba41..f66fe0d2 100644
--- a/include/mupdf/pdf/crypt.h
+++ b/include/mupdf/pdf/crypt.h
@@ -59,4 +59,8 @@ int pdf_check_signature(fz_context *ctx, pdf_document *doc, pdf_widget *widget,
*/
void pdf_sign_signature(fz_context *ctx, pdf_document *doc, pdf_widget *widget, const char *sigfile, const char *password);
+void pdf_encrypt_data(fz_context *ctx, pdf_crypt *crypt, int num, int gen, void (*fmt_str_out)(fz_context *, void *, const unsigned char *, int), void *arg, const unsigned char *s, int n);
+
+int pdf_encrypted_len(fz_context *ctx, pdf_crypt *crypt, int num, int gen, int len);
+
#endif
diff --git a/include/mupdf/pdf/document.h b/include/mupdf/pdf/document.h
index 63f94bcd..ebd04401 100644
--- a/include/mupdf/pdf/document.h
+++ b/include/mupdf/pdf/document.h
@@ -4,7 +4,6 @@
typedef struct pdf_lexbuf_s pdf_lexbuf;
typedef struct pdf_lexbuf_large_s pdf_lexbuf_large;
typedef struct pdf_xref_s pdf_xref;
-typedef struct pdf_crypt_s pdf_crypt;
typedef struct pdf_ocg_descriptor_s pdf_ocg_descriptor;
typedef struct pdf_portfolio_s pdf_portfolio;
diff --git a/include/mupdf/pdf/object.h b/include/mupdf/pdf/object.h
index 4177112b..306ab21b 100644
--- a/include/mupdf/pdf/object.h
+++ b/include/mupdf/pdf/object.h
@@ -2,6 +2,7 @@
#define MUPDF_PDF_OBJECT_H
typedef struct pdf_document_s pdf_document;
+typedef struct pdf_crypt_s pdf_crypt;
/* Defined in PDF 1.7 according to Acrobat limit. */
#define PDF_MAX_OBJECT_NUMBER 8388607
@@ -142,7 +143,9 @@ int pdf_obj_refs(fz_context *ctx, pdf_obj *ref);
int pdf_obj_parent_num(fz_context *ctx, pdf_obj *obj);
int pdf_sprint_obj(fz_context *ctx, char *s, int n, pdf_obj *obj, int tight);
+int pdf_sprint_encrypted_obj(fz_context *ctx, char *s, int n, pdf_obj *obj, int tight, pdf_crypt *crypt, int num, int gen);
int pdf_print_obj(fz_context *ctx, fz_output *out, pdf_obj *obj, int tight);
+int pdf_print_encrypted_obj(fz_context *ctx, fz_output *out, pdf_obj *obj, int tight, pdf_crypt *crypt, int num, int gen);
char *pdf_to_utf8(fz_context *ctx, pdf_obj *src);
char *pdf_load_stream_as_utf8(fz_context *ctx, pdf_obj *src);