beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / poppler / SecurityHandler.h
blobc2991c8f3756771f7bca0494b68be1d866bdf51e
1 //========================================================================
2 //
3 // SecurityHandler.h
4 //
5 // Copyright 2004 Glyph & Cog, LLC
6 //
7 //========================================================================
9 //========================================================================
11 // Modified under the Poppler project - http://poppler.freedesktop.org
13 // All changes made under the Poppler project to this file are licensed
14 // under GPL version 2 or later
16 // Copyright (C) 2012 Albert Astals Cid <aacid@kde.org>
18 // To see a description of the changes please see the Changelog file that
19 // came with your tarball or type make ChangeLog if you are building from git
21 //========================================================================
23 #ifndef SECURITYHANDLER_H
24 #define SECURITYHANDLER_H
26 #include "poppler-config.h"
28 #ifdef USE_GCC_PRAGMAS
29 #pragma interface
30 #endif
32 #include "goo/gtypes.h"
33 #include "Object.h"
35 class GooString;
36 class PDFDoc;
37 struct XpdfSecurityHandler;
39 //------------------------------------------------------------------------
40 // SecurityHandler
41 //------------------------------------------------------------------------
43 class SecurityHandler {
44 public:
46 static SecurityHandler *make(PDFDoc *docA, Object *encryptDictA);
48 SecurityHandler(PDFDoc *docA);
49 virtual ~SecurityHandler();
51 // Returns true if the file is actually unencrypted.
52 virtual GBool isUnencrypted() { return gFalse; }
54 // Check the document's encryption. If the document is encrypted,
55 // this will first try <ownerPassword> and <userPassword> (in
56 // "batch" mode), and if those fail, it will attempt to request a
57 // password from the user. This is the high-level function that
58 // calls the lower level functions for the specific security handler
59 // (requesting a password three times, etc.). Returns true if the
60 // document can be opened (if it's unencrypted, or if a correct
61 // password is obtained); false otherwise (encrypted and no correct
62 // password).
63 GBool checkEncryption(GooString *ownerPassword,
64 GooString *userPassword);
66 // Create authorization data for the specified owner and user
67 // passwords. If the security handler doesn't support "batch" mode,
68 // this function should return NULL.
69 virtual void *makeAuthData(GooString *ownerPassword,
70 GooString *userPassword) = 0;
72 // Construct authorization data, typically by prompting the user for
73 // a password. Returns an authorization data object, or NULL to
74 // cancel.
75 virtual void *getAuthData() = 0;
77 // Free the authorization data returned by makeAuthData or
78 // getAuthData.
79 virtual void freeAuthData(void *authData) = 0;
81 // Attempt to authorize the document, using the supplied
82 // authorization data (which may be NULL). Returns true if
83 // successful (i.e., if at least the right to open the document was
84 // granted).
85 virtual GBool authorize(void *authData) = 0;
87 // Return the various authorization parameters. These are only
88 // valid after authorize has returned true.
89 virtual int getPermissionFlags() = 0;
90 virtual GBool getOwnerPasswordOk() = 0;
91 virtual Guchar *getFileKey() = 0;
92 virtual int getFileKeyLength() = 0;
93 virtual int getEncVersion() = 0;
94 virtual int getEncRevision() = 0;
95 virtual CryptAlgorithm getEncAlgorithm() = 0;
97 protected:
99 PDFDoc *doc;
102 //------------------------------------------------------------------------
103 // StandardSecurityHandler
104 //------------------------------------------------------------------------
106 class StandardSecurityHandler: public SecurityHandler {
107 public:
109 StandardSecurityHandler(PDFDoc *docA, Object *encryptDictA);
110 virtual ~StandardSecurityHandler();
112 virtual GBool isUnencrypted();
113 virtual void *makeAuthData(GooString *ownerPassword,
114 GooString *userPassword);
115 virtual void *getAuthData();
116 virtual void freeAuthData(void *authData);
117 virtual GBool authorize(void *authData);
118 virtual int getPermissionFlags() { return permFlags; }
119 virtual GBool getOwnerPasswordOk() { return ownerPasswordOk; }
120 virtual Guchar *getFileKey() { return fileKey; }
121 virtual int getFileKeyLength() { return fileKeyLength; }
122 virtual int getEncVersion() { return encVersion; }
123 virtual int getEncRevision() { return encRevision; }
124 virtual CryptAlgorithm getEncAlgorithm() { return encAlgorithm; }
126 private:
128 int permFlags;
129 GBool ownerPasswordOk;
130 Guchar fileKey[32];
131 int fileKeyLength;
132 int encVersion;
133 int encRevision;
134 GBool encryptMetadata;
135 CryptAlgorithm encAlgorithm;
137 GooString *ownerKey, *userKey;
138 GooString *ownerEnc, *userEnc;
139 GooString *fileID;
140 GBool ok;
143 #ifdef ENABLE_PLUGINS
144 //------------------------------------------------------------------------
145 // ExternalSecurityHandler
146 //------------------------------------------------------------------------
148 class ExternalSecurityHandler: public SecurityHandler {
149 public:
151 ExternalSecurityHandler(PDFDoc *docA, Object *encryptDictA,
152 XpdfSecurityHandler *xshA);
153 virtual ~ExternalSecurityHandler();
155 virtual void *makeAuthData(GooString *ownerPassword,
156 GooString *userPassword);
157 virtual void *getAuthData();
158 virtual void freeAuthData(void *authData);
159 virtual GBool authorize(void *authData);
160 virtual int getPermissionFlags() { return permFlags; }
161 virtual GBool getOwnerPasswordOk() { return gFalse; }
162 virtual Guchar *getFileKey() { return fileKey; }
163 virtual int getFileKeyLength() { return fileKeyLength; }
164 virtual int getEncVersion() { return encVersion; }
165 virtual int getEncRevision() { return encRevision; }
166 virtual CryptAlgorithm getEncAlgorithm() { return encAlgorithm; }
168 private:
170 Object encryptDict;
171 XpdfSecurityHandler *xsh;
172 void *docData;
173 int permFlags;
174 Guchar fileKey[16];
175 int fileKeyLength;
176 int encVersion;
177 int encRevision;
178 CryptAlgorithm encAlgorithm;
179 GBool ok;
181 #endif // ENABLE_PLUGINS
183 #endif