Change the translation of the "Help" menu item to "?", so that the menu can be displa...
[reactos.git] / rosapps / smartpdf / poppler / poppler / SecurityHandler.h
1 //========================================================================
2 //
3 // SecurityHandler.h
4 //
5 // Copyright 2004 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #ifndef SECURITYHANDLER_H
10 #define SECURITYHANDLER_H
11
12 #include <config.h>
13
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
17
18 #include "gtypes.h"
19 #include "Object.h"
20
21 class GooString;
22 class PDFDoc;
23 struct XpdfSecurityHandler;
24
25 //------------------------------------------------------------------------
26 // SecurityHandler
27 //------------------------------------------------------------------------
28
29 class SecurityHandler {
30 public:
31
32 static SecurityHandler *make(PDFDoc *docA, Object *encryptDictA);
33
34 SecurityHandler(PDFDoc *docA);
35 virtual ~SecurityHandler();
36
37 // Check the document's encryption. If the document is encrypted,
38 // this will first try <ownerPassword> and <userPassword> (in
39 // "batch" mode), and if those fail, it will attempt to request a
40 // password from the user. This is the high-level function that
41 // calls the lower level functions for the specific security handler
42 // (requesting a password three times, etc.). Returns true if the
43 // document can be opened (if it's unencrypted, or if a correct
44 // password is obtained); false otherwise (encrypted and no correct
45 // password).
46 GBool checkEncryption(GooString *ownerPassword,
47 GooString *userPassword);
48
49 // Create authorization data for the specified owner and user
50 // passwords. If the security handler doesn't support "batch" mode,
51 // this function should return NULL.
52 virtual void *makeAuthData(GooString *ownerPassword,
53 GooString *userPassword) = 0;
54
55 // Construct authorization data, typically by prompting the user for
56 // a password. Returns an authorization data object, or NULL to
57 // cancel.
58 virtual void *getAuthData() = 0;
59
60 // Free the authorization data returned by makeAuthData or
61 // getAuthData.
62 virtual void freeAuthData(void *authData) = 0;
63
64 // Attempt to authorize the document, using the supplied
65 // authorization data (which may be NULL). Returns true if
66 // successful (i.e., if at least the right to open the document was
67 // granted).
68 virtual GBool authorize(void *authData) = 0;
69
70 // Return the various authorization parameters. These are only
71 // valid after authorize has returned true.
72 virtual int getPermissionFlags() = 0;
73 virtual GBool getOwnerPasswordOk() = 0;
74 virtual Guchar *getFileKey() = 0;
75 virtual int getFileKeyLength() = 0;
76 virtual int getEncVersion() = 0;
77 virtual int getEncRevision() = 0;
78
79 protected:
80
81 PDFDoc *doc;
82 };
83
84 //------------------------------------------------------------------------
85 // StandardSecurityHandler
86 //------------------------------------------------------------------------
87
88 class StandardAuthData {
89 public:
90
91 StandardAuthData(GooString *ownerPasswordA, GooString *userPasswordA) {
92 ownerPassword = ownerPasswordA;
93 userPassword = userPasswordA;
94 }
95
96 ~StandardAuthData() {
97 delete ownerPassword;
98 delete userPassword;
99 }
100
101 GooString *ownerPassword;
102 GooString *userPassword;
103 };
104
105 class StandardSecurityHandler: public SecurityHandler {
106 public:
107
108 StandardSecurityHandler(PDFDoc *docA, Object *encryptDictA);
109 virtual ~StandardSecurityHandler();
110
111 virtual void *makeAuthData(GooString *ownerPassword,
112 GooString *userPassword);
113 virtual void *getAuthData();
114 virtual void freeAuthData(void *authData);
115 virtual GBool authorize(void *authData);
116 virtual int getPermissionFlags() { return permFlags; }
117 virtual GBool getOwnerPasswordOk() { return ownerPasswordOk; }
118 virtual Guchar *getFileKey() { return fileKey; }
119 virtual int getFileKeyLength() { return fileKeyLength; }
120 virtual int getEncVersion() { return encVersion; }
121 virtual int getEncRevision() { return encRevision; }
122
123 private:
124
125 int permFlags;
126 GBool ownerPasswordOk;
127 Guchar fileKey[16];
128 int fileKeyLength;
129 int encVersion;
130 int encRevision;
131 GBool encryptMetadata;
132
133 GooString *ownerKey, *userKey;
134 GooString *fileID;
135 GBool ok;
136 };
137
138 #ifdef ENABLE_PLUGINS
139 //------------------------------------------------------------------------
140 // ExternalSecurityHandler
141 //------------------------------------------------------------------------
142
143 class ExternalSecurityHandler: public SecurityHandler {
144 public:
145
146 ExternalSecurityHandler(PDFDoc *docA, Object *encryptDictA,
147 XpdfSecurityHandler *xshA);
148 virtual ~ExternalSecurityHandler();
149
150 virtual void *makeAuthData(GooString *ownerPassword,
151 GooString *userPassword);
152 virtual void *getAuthData();
153 virtual void freeAuthData(void *authData);
154 virtual GBool authorize(void *authData);
155 virtual int getPermissionFlags() { return permFlags; }
156 virtual GBool getOwnerPasswordOk() { return gFalse; }
157 virtual Guchar *getFileKey() { return fileKey; }
158 virtual int getFileKeyLength() { return fileKeyLength; }
159 virtual int getEncVersion() { return encVersion; }
160
161 private:
162
163 Object encryptDict;
164 XpdfSecurityHandler *xsh;
165 void *docData;
166 int permFlags;
167 Guchar fileKey[16];
168 int fileKeyLength;
169 int encVersion;
170 GBool ok;
171 };
172 #endif // ENABLE_PLUGINS
173
174 #endif