Various Datatypes.
[AROS-Contrib.git] / arospdf / xpdf / SecurityHandler.h
blobe47fc8bc93b23c9ec36449776dcae1db1bfb6929
1 //========================================================================
2 //
3 // SecurityHandler.h
4 //
5 // Copyright 2004 Glyph & Cog, LLC
6 //
7 //========================================================================
9 #ifndef SECURITYHANDLER_H
10 #define SECURITYHANDLER_H
12 #include <aconf.h>
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
18 #include "gtypes.h"
19 #include "Object.h"
21 class GString;
22 class PDFDoc;
23 struct XpdfSecurityHandler;
25 //------------------------------------------------------------------------
26 // SecurityHandler
27 //------------------------------------------------------------------------
29 class SecurityHandler {
30 public:
32 static SecurityHandler *make(PDFDoc *docA, xObject *encryptDictA);
34 SecurityHandler(PDFDoc *docA);
35 virtual ~SecurityHandler();
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(GString *ownerPassword,
47 GString *userPassword);
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(GString *ownerPassword,
53 GString *userPassword) = 0;
55 // Construct authorization data, typically by prompting the user for
56 // a password. Returns an authorization data xObject, or NULL to
57 // cancel.
58 virtual void *getAuthData() = 0;
60 // Free the authorization data returned by makeAuthData or
61 // getAuthData.
62 virtual void freeAuthData(void *authData) = 0;
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;
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 CryptAlgorithm getEncAlgorithm() = 0;
79 protected:
81 PDFDoc *doc;
84 //------------------------------------------------------------------------
85 // StandardSecurityHandler
86 //------------------------------------------------------------------------
88 class StandardSecurityHandler: public SecurityHandler {
89 public:
91 StandardSecurityHandler(PDFDoc *docA, xObject *encryptDictA);
92 virtual ~StandardSecurityHandler();
94 virtual void *makeAuthData(GString *ownerPassword,
95 GString *userPassword);
96 virtual void *getAuthData();
97 virtual void freeAuthData(void *authData);
98 virtual GBool authorize(void *authData);
99 virtual int getPermissionFlags() { return permFlags; }
100 virtual GBool getOwnerPasswordOk() { return ownerPasswordOk; }
101 virtual Guchar *getFileKey() { return fileKey; }
102 virtual int getFileKeyLength() { return fileKeyLength; }
103 virtual int getEncVersion() { return encVersion; }
104 virtual CryptAlgorithm getEncAlgorithm() { return encAlgorithm; }
106 private:
108 int permFlags;
109 GBool ownerPasswordOk;
110 Guchar fileKey[16];
111 int fileKeyLength;
112 int encVersion;
113 int encRevision;
114 CryptAlgorithm encAlgorithm;
115 GBool encryptMetadata;
117 GString *ownerKey, *userKey;
118 GString *fileID;
119 GBool ok;
122 #ifdef ENABLE_PLUGINS
123 //------------------------------------------------------------------------
124 // ExternalSecurityHandler
125 //------------------------------------------------------------------------
127 class ExternalSecurityHandler: public SecurityHandler {
128 public:
130 ExternalSecurityHandler(PDFDoc *docA, xObject *encryptDictA,
131 XpdfSecurityHandler *xshA);
132 virtual ~ExternalSecurityHandler();
134 virtual void *makeAuthData(GString *ownerPassword,
135 GString *userPassword);
136 virtual void *getAuthData();
137 virtual void freeAuthData(void *authData);
138 virtual GBool authorize(void *authData);
139 virtual int getPermissionFlags() { return permFlags; }
140 virtual GBool getOwnerPasswordOk() { return gFalse; }
141 virtual Guchar *getFileKey() { return fileKey; }
142 virtual int getFileKeyLength() { return fileKeyLength; }
143 virtual int getEncVersion() { return encVersion; }
144 virtual CryptAlgorithm getEncAlgorithm() { return encAlgorithm; }
146 private:
148 xObject encryptDict;
149 XpdfSecurityHandler *xsh;
150 void *docData;
151 int permFlags;
152 Guchar fileKey[16];
153 int fileKeyLength;
154 int encVersion;
155 CryptAlgorithm encAlgorithm;
156 GBool ok;
158 #endif // ENABLE_PLUGINS
160 #endif