comparison mupdf-source/include/mupdf/pdf/crypt.h @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 // Copyright (C) 2004-2023 Artifex Software, Inc.
2 //
3 // This file is part of MuPDF.
4 //
5 // MuPDF is free software: you can redistribute it and/or modify it under the
6 // terms of the GNU Affero General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or (at your option)
8 // any later version.
9 //
10 // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Affero General Public License
16 // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
17 //
18 // Alternative licensing terms are available from the licensor.
19 // For commercial licensing, see <https://www.artifex.com/> or contact
20 // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
21 // CA 94129, USA, for further information.
22
23 #ifndef MUPDF_PDF_CRYPT_H
24 #define MUPDF_PDF_CRYPT_H
25
26 #include "mupdf/pdf/document.h"
27 #include "mupdf/pdf/object.h"
28
29 enum
30 {
31 PDF_ENCRYPT_KEEP,
32 PDF_ENCRYPT_NONE,
33 PDF_ENCRYPT_RC4_40,
34 PDF_ENCRYPT_RC4_128,
35 PDF_ENCRYPT_AES_128,
36 PDF_ENCRYPT_AES_256,
37 PDF_ENCRYPT_UNKNOWN
38 };
39
40 /*
41 Create crypt object for decrypting strings and streams
42 given the Encryption and ID objects.
43 */
44 pdf_crypt *pdf_new_crypt(fz_context *ctx, pdf_obj *enc, pdf_obj *id);
45 pdf_crypt *pdf_new_encrypt(fz_context *ctx, const char *opwd_utf8, const char *upwd_utf8, pdf_obj *id, int permissions, int algorithm);
46 void pdf_drop_crypt(fz_context *ctx, pdf_crypt *crypt);
47
48 void pdf_crypt_obj(fz_context *ctx, pdf_crypt *crypt, pdf_obj *obj, int num, int gen);
49 fz_stream *pdf_open_crypt(fz_context *ctx, fz_stream *chain, pdf_crypt *crypt, int num, int gen);
50 fz_stream *pdf_open_crypt_with_filter(fz_context *ctx, fz_stream *chain, pdf_crypt *crypt, pdf_obj *name, int num, int gen);
51
52 int pdf_crypt_version(fz_context *ctx, pdf_crypt *crypt);
53 int pdf_crypt_revision(fz_context *ctx, pdf_crypt *crypt);
54 const char *pdf_crypt_method(fz_context *ctx, pdf_crypt *crypt);
55 const char *pdf_crypt_string_method(fz_context *ctx, pdf_crypt *crypt);
56 const char *pdf_crypt_stream_method(fz_context *ctx, pdf_crypt *crypt);
57 int pdf_crypt_length(fz_context *ctx, pdf_crypt *crypt);
58 int pdf_crypt_permissions(fz_context *ctx, pdf_crypt *crypt);
59 int pdf_crypt_encrypt_metadata(fz_context *ctx, pdf_crypt *crypt);
60 unsigned char *pdf_crypt_owner_password(fz_context *ctx, pdf_crypt *crypt);
61 unsigned char *pdf_crypt_user_password(fz_context *ctx, pdf_crypt *crypt);
62 unsigned char *pdf_crypt_owner_encryption(fz_context *ctx, pdf_crypt *crypt);
63 unsigned char *pdf_crypt_user_encryption(fz_context *ctx, pdf_crypt *crypt);
64 unsigned char *pdf_crypt_permissions_encryption(fz_context *ctx, pdf_crypt *crypt);
65 unsigned char *pdf_crypt_key(fz_context *ctx, pdf_crypt *crypt);
66
67 void pdf_print_crypt(fz_context *ctx, fz_output *out, pdf_crypt *crypt);
68
69 void pdf_write_digest(fz_context *ctx, fz_output *out, pdf_obj *byte_range, pdf_obj *field, size_t digest_offset, size_t digest_length, pdf_pkcs7_signer *signer);
70
71 /*
72 User access permissions from PDF reference.
73 */
74 enum
75 {
76 PDF_PERM_PRINT = 1 << 2,
77 PDF_PERM_MODIFY = 1 << 3,
78 PDF_PERM_COPY = 1 << 4,
79 PDF_PERM_ANNOTATE = 1 << 5,
80 PDF_PERM_FORM = 1 << 8,
81 PDF_PERM_ACCESSIBILITY = 1 << 9, /* deprecated in pdf 2.0 (this permission is always granted) */
82 PDF_PERM_ASSEMBLE = 1 << 10,
83 PDF_PERM_PRINT_HQ = 1 << 11,
84 };
85
86 int pdf_document_permissions(fz_context *ctx, pdf_document *doc);
87
88 int pdf_signature_byte_range(fz_context *ctx, pdf_document *doc, pdf_obj *signature, fz_range *byte_range);
89
90 /*
91 retrieve an fz_stream to read the bytes hashed for the signature
92 */
93 fz_stream *pdf_signature_hash_bytes(fz_context *ctx, pdf_document *doc, pdf_obj *signature);
94
95 int pdf_signature_incremental_change_since_signing(fz_context *ctx, pdf_document *doc, pdf_obj *signature);
96 int pdf_incremental_change_since_signing_widget(fz_context *ctx, pdf_annot *widget);
97
98 /*
99 Retrieve the contents of a signature as a counted allocated
100 block that must be freed by the caller.
101 */
102 size_t pdf_signature_contents(fz_context *ctx, pdf_document *doc, pdf_obj *signature, char **contents);
103
104 void pdf_encrypt_data(fz_context *ctx, pdf_crypt *crypt, int num, int gen, void (*fmt_str_out)(fz_context *, void *, const unsigned char *, size_t), void *arg, const unsigned char *s, size_t n);
105
106 size_t pdf_encrypted_len(fz_context *ctx, pdf_crypt *crypt, int num, int gen, size_t len);
107
108 #endif