mupdf
Loading...
Searching...
No Matches
crypt.h
Go to the documentation of this file.
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
29enum
30{
38};
39
40/*
41 Create crypt object for decrypting strings and streams
42 given the Encryption and ID objects.
43*/
45pdf_crypt *pdf_new_encrypt(fz_context *ctx, const char *opwd_utf8, const char *upwd_utf8, pdf_obj *id, int permissions, int algorithm);
47
48void pdf_crypt_obj(fz_context *ctx, pdf_crypt *crypt, pdf_obj *obj, int num, int gen);
49fz_stream *pdf_open_crypt(fz_context *ctx, fz_stream *chain, pdf_crypt *crypt, int num, int gen);
50fz_stream *pdf_open_crypt_with_filter(fz_context *ctx, fz_stream *chain, pdf_crypt *crypt, pdf_obj *name, int num, int gen);
51
54const char *pdf_crypt_method(fz_context *ctx, pdf_crypt *crypt);
60unsigned char *pdf_crypt_owner_password(fz_context *ctx, pdf_crypt *crypt);
61unsigned char *pdf_crypt_user_password(fz_context *ctx, pdf_crypt *crypt);
62unsigned char *pdf_crypt_owner_encryption(fz_context *ctx, pdf_crypt *crypt);
63unsigned char *pdf_crypt_user_encryption(fz_context *ctx, pdf_crypt *crypt);
65unsigned char *pdf_crypt_key(fz_context *ctx, pdf_crypt *crypt);
66
68
69void 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*/
74enum
75{
78 PDF_PERM_COPY = 1 << 4,
80 PDF_PERM_FORM = 1 << 8,
81 PDF_PERM_ACCESSIBILITY = 1 << 9, /* deprecated in pdf 2.0 (this permission is always granted) */
84};
85
87
88int 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*/
94
97
98/*
99 Retrieve the contents of a signature as a counted allocated
100 block that must be freed by the caller.
101*/
102size_t pdf_signature_contents(fz_context *ctx, pdf_document *doc, pdf_obj *signature, char **contents);
103
104void 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
106size_t pdf_encrypted_len(fz_context *ctx, pdf_crypt *crypt, int num, int gen, size_t len);
107
108#endif
struct pdf_annot pdf_annot
Definition annot.h:32
struct pdf_obj pdf_obj
Definition object.h:44
struct pdf_crypt pdf_crypt
Definition object.h:29
fz_stream * pdf_open_crypt(fz_context *ctx, fz_stream *chain, pdf_crypt *crypt, int num, int gen)
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)
int pdf_crypt_encrypt_metadata(fz_context *ctx, pdf_crypt *crypt)
int pdf_incremental_change_since_signing_widget(fz_context *ctx, pdf_annot *widget)
int pdf_crypt_revision(fz_context *ctx, pdf_crypt *crypt)
void pdf_print_crypt(fz_context *ctx, fz_output *out, pdf_crypt *crypt)
fz_stream * pdf_open_crypt_with_filter(fz_context *ctx, fz_stream *chain, pdf_crypt *crypt, pdf_obj *name, int num, int gen)
const char * pdf_crypt_string_method(fz_context *ctx, pdf_crypt *crypt)
unsigned char * pdf_crypt_user_password(fz_context *ctx, pdf_crypt *crypt)
unsigned char * pdf_crypt_permissions_encryption(fz_context *ctx, pdf_crypt *crypt)
int pdf_crypt_length(fz_context *ctx, pdf_crypt *crypt)
void pdf_drop_crypt(fz_context *ctx, pdf_crypt *crypt)
size_t pdf_signature_contents(fz_context *ctx, pdf_document *doc, pdf_obj *signature, char **contents)
int pdf_signature_byte_range(fz_context *ctx, pdf_document *doc, pdf_obj *signature, fz_range *byte_range)
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)
const char * pdf_crypt_method(fz_context *ctx, pdf_crypt *crypt)
pdf_crypt * pdf_new_encrypt(fz_context *ctx, const char *opwd_utf8, const char *upwd_utf8, pdf_obj *id, int permissions, int algorithm)
pdf_crypt * pdf_new_crypt(fz_context *ctx, pdf_obj *enc, pdf_obj *id)
@ PDF_PERM_ASSEMBLE
Definition crypt.h:82
@ PDF_PERM_ANNOTATE
Definition crypt.h:79
@ PDF_PERM_MODIFY
Definition crypt.h:77
@ PDF_PERM_FORM
Definition crypt.h:80
@ PDF_PERM_COPY
Definition crypt.h:78
@ PDF_PERM_ACCESSIBILITY
Definition crypt.h:81
@ PDF_PERM_PRINT
Definition crypt.h:76
@ PDF_PERM_PRINT_HQ
Definition crypt.h:83
const char * pdf_crypt_stream_method(fz_context *ctx, pdf_crypt *crypt)
unsigned char * pdf_crypt_user_encryption(fz_context *ctx, pdf_crypt *crypt)
unsigned char * pdf_crypt_owner_password(fz_context *ctx, pdf_crypt *crypt)
int pdf_document_permissions(fz_context *ctx, pdf_document *doc)
int pdf_crypt_permissions(fz_context *ctx, pdf_crypt *crypt)
size_t pdf_encrypted_len(fz_context *ctx, pdf_crypt *crypt, int num, int gen, size_t len)
int pdf_crypt_version(fz_context *ctx, pdf_crypt *crypt)
int pdf_signature_incremental_change_since_signing(fz_context *ctx, pdf_document *doc, pdf_obj *signature)
unsigned char * pdf_crypt_owner_encryption(fz_context *ctx, pdf_crypt *crypt)
fz_stream * pdf_signature_hash_bytes(fz_context *ctx, pdf_document *doc, pdf_obj *signature)
void pdf_crypt_obj(fz_context *ctx, pdf_crypt *crypt, pdf_obj *obj, int num, int gen)
@ PDF_ENCRYPT_UNKNOWN
Definition crypt.h:37
@ PDF_ENCRYPT_NONE
Definition crypt.h:32
@ PDF_ENCRYPT_RC4_40
Definition crypt.h:33
@ PDF_ENCRYPT_RC4_128
Definition crypt.h:34
@ PDF_ENCRYPT_AES_256
Definition crypt.h:36
@ PDF_ENCRYPT_AES_128
Definition crypt.h:35
@ PDF_ENCRYPT_KEEP
Definition crypt.h:31
unsigned char * pdf_crypt_key(fz_context *ctx, pdf_crypt *crypt)
Definition context.h:886
Definition output.h:111
Definition filter.h:35
Definition stream.h:320
Definition document.h:463
Definition form.h:230