summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2018-02-12 13:29:37 +0100
committerTor Andersson <tor.andersson@artifex.com>2018-02-12 15:27:58 +0100
commitf597f8dc0552b8e8facd59b11ac64f87fe6736db (patch)
tree7ff4b811ff28adaebace7222a91b7faf77f0f7cf
parente09f69509f160a22c9290fac054b790b0a80a0cc (diff)
downloadmupdf-f597f8dc0552b8e8facd59b11ac64f87fe6736db.tar.xz
Expose detailed PDF permissions.
-rw-r--r--include/mupdf/pdf/crypt.h21
-rw-r--r--source/pdf/pdf-crypt.c25
2 files changed, 31 insertions, 15 deletions
diff --git a/include/mupdf/pdf/crypt.h b/include/mupdf/pdf/crypt.h
index c01d3978..04c884eb 100644
--- a/include/mupdf/pdf/crypt.h
+++ b/include/mupdf/pdf/crypt.h
@@ -24,6 +24,27 @@ void pdf_print_crypt(fz_context *ctx, fz_output *out, pdf_crypt *crypt);
void pdf_write_digest(fz_context *ctx, fz_output *out, pdf_obj *byte_range, int digest_offset, int digest_length, pdf_pkcs7_signer *signer);
/*
+ User access permissions from PDF reference.
+*/
+enum
+{
+ PDF_PERM_PRINT = 1 << 2,
+ PDF_PERM_MODIFY = 1 << 3,
+ PDF_PERM_COPY = 1 << 4,
+ PDF_PERM_ANNOTATE = 1 << 5,
+ PDF_PERM_FORM = 1 << 8,
+ PDF_PERM_ACCESSIBILITY = 1 << 9, /* deprecated in pdf 2.0 (this permission is always granted) */
+ PDF_PERM_ASSEMBLE = 1 << 10,
+ PDF_PERM_PRINT_HQ = 1 << 11,
+ PDF_DEFAULT_PERM_FLAGS = 0xFFFFFFFC /* all permissions granted, reserved bits set appropriately */
+};
+
+/*
+ pdf_document_permissions: access the detailed permissions flag.
+*/
+int pdf_document_permissions(fz_context *ctx, pdf_document *doc);
+
+/*
pdf_signature_widget_byte_range: retrieve the byte range for a signature widget
*/
int pdf_signature_widget_byte_range(fz_context *ctx, pdf_document *doc, pdf_widget *widget, fz_range *byte_range);
diff --git a/source/pdf/pdf-crypt.c b/source/pdf/pdf-crypt.c
index f73617ff..a62b12f0 100644
--- a/source/pdf/pdf-crypt.c
+++ b/source/pdf/pdf-crypt.c
@@ -12,19 +12,6 @@ enum
PDF_CRYPT_UNKNOWN,
};
-enum
-{
- PDF_PERM_PRINT = 1 << 2,
- PDF_PERM_CHANGE = 1 << 3,
- PDF_PERM_COPY = 1 << 4,
- PDF_PERM_NOTES = 1 << 5,
- PDF_PERM_FILL_FORM = 1 << 8,
- PDF_PERM_ACCESSIBILITY = 1 << 9,
- PDF_PERM_ASSEMBLE = 1 << 10,
- PDF_PERM_HIGH_RES_PRINT = 1 << 11,
- PDF_DEFAULT_PERM_FLAGS = 0xfffc
-};
-
typedef struct pdf_crypt_filter_s pdf_crypt_filter;
struct pdf_crypt_filter_s
@@ -816,12 +803,20 @@ pdf_has_permission(fz_context *ctx, pdf_document *doc, fz_permission p)
{
case FZ_PERMISSION_PRINT: return doc->crypt->p & PDF_PERM_PRINT;
case FZ_PERMISSION_COPY: return doc->crypt->p & PDF_PERM_COPY;
- case FZ_PERMISSION_EDIT: return doc->crypt->p & PDF_PERM_CHANGE;
- case FZ_PERMISSION_ANNOTATE: return doc->crypt->p & PDF_PERM_NOTES;
+ case FZ_PERMISSION_EDIT: return doc->crypt->p & PDF_PERM_MODIFY;
+ case FZ_PERMISSION_ANNOTATE: return doc->crypt->p & PDF_PERM_ANNOTATE;
}
return 1;
}
+int
+pdf_document_permissions(fz_context *ctx, pdf_document *doc)
+{
+ if (doc->crypt)
+ return doc->crypt->p;
+ return PDF_DEFAULT_PERM_FLAGS;
+}
+
unsigned char *
pdf_crypt_key(fz_context *ctx, pdf_document *doc)
{