source: trunk/poppler/mypoppler/poppler/SecurityHandler.h @ 27

Last change on this file since 27 was 27, checked in by Eugene Romanenko, 16 years ago

poppler updated to version 0.5.2, also needed changes to be compatible with new poppler

File size: 4.7 KB
Line 
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
21class GooString;
22class PDFDoc;
23struct XpdfSecurityHandler;
24
25//------------------------------------------------------------------------
26// SecurityHandler
27//------------------------------------------------------------------------
28
29class SecurityHandler {
30public:
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
79protected:
80
81  PDFDoc *doc;
82};
83
84//------------------------------------------------------------------------
85// StandardSecurityHandler
86//------------------------------------------------------------------------
87
88class StandardSecurityHandler: public SecurityHandler {
89public:
90
91  StandardSecurityHandler(PDFDoc *docA, Object *encryptDictA);
92  virtual ~StandardSecurityHandler();
93
94  virtual void *makeAuthData(GooString *ownerPassword,
95                             GooString *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 int getEncRevision() { return encRevision; }
105
106private:
107
108  int permFlags;
109  GBool ownerPasswordOk;
110  Guchar fileKey[16];
111  int fileKeyLength;
112  int encVersion;
113  int encRevision;
114  GBool encryptMetadata;
115
116  GooString *ownerKey, *userKey;
117  GooString *fileID;
118  GBool ok;
119};
120
121#ifdef ENABLE_PLUGINS
122//------------------------------------------------------------------------
123// ExternalSecurityHandler
124//------------------------------------------------------------------------
125
126class ExternalSecurityHandler: public SecurityHandler {
127public:
128
129  ExternalSecurityHandler(PDFDoc *docA, Object *encryptDictA,
130                          XpdfSecurityHandler *xshA);
131  virtual ~ExternalSecurityHandler();
132
133  virtual void *makeAuthData(GooString *ownerPassword,
134                             GooString *userPassword);
135  virtual void *getAuthData();
136  virtual void freeAuthData(void *authData);
137  virtual GBool authorize(void *authData);
138  virtual int getPermissionFlags() { return permFlags; }
139  virtual GBool getOwnerPasswordOk() { return gFalse; }
140  virtual Guchar *getFileKey() { return fileKey; }
141  virtual int getFileKeyLength() { return fileKeyLength; }
142  virtual int getEncVersion() { return encVersion; }
143
144private:
145
146  Object encryptDict;
147  XpdfSecurityHandler *xsh;
148  void *docData;
149  int permFlags;
150  Guchar fileKey[16];
151  int fileKeyLength;
152  int encVersion;
153  GBool ok;
154};
155#endif // ENABLE_PLUGINS
156
157#endif
Note: See TracBrowser for help on using the repository browser.