~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/poppler/poppler/SecurityHandler.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "poppler-config.h"
 
13
 
 
14
#ifdef USE_GCC_PRAGMAS
 
15
#pragma interface
 
16
#endif
 
17
 
 
18
#include "goo/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
  virtual CryptAlgorithm getEncAlgorithm() = 0;
 
79
 
 
80
protected:
 
81
 
 
82
  PDFDoc *doc;
 
83
};
 
84
 
 
85
//------------------------------------------------------------------------
 
86
// StandardSecurityHandler
 
87
//------------------------------------------------------------------------
 
88
 
 
89
class StandardSecurityHandler: public SecurityHandler {
 
90
public:
 
91
 
 
92
  StandardSecurityHandler(PDFDoc *docA, Object *encryptDictA);
 
93
  virtual ~StandardSecurityHandler();
 
94
 
 
95
  virtual void *makeAuthData(GooString *ownerPassword,
 
96
                             GooString *userPassword);
 
97
  virtual void *getAuthData();
 
98
  virtual void freeAuthData(void *authData);
 
99
  virtual GBool authorize(void *authData);
 
100
  virtual int getPermissionFlags() { return permFlags; }
 
101
  virtual GBool getOwnerPasswordOk() { return ownerPasswordOk; }
 
102
  virtual Guchar *getFileKey() { return fileKey; }
 
103
  virtual int getFileKeyLength() { return fileKeyLength; }
 
104
  virtual int getEncVersion() { return encVersion; }
 
105
  virtual int getEncRevision() { return encRevision; }
 
106
  virtual CryptAlgorithm getEncAlgorithm() { return encAlgorithm; }
 
107
 
 
108
private:
 
109
 
 
110
  int permFlags;
 
111
  GBool ownerPasswordOk;
 
112
  Guchar fileKey[16];
 
113
  int fileKeyLength;
 
114
  int encVersion;
 
115
  int encRevision;
 
116
  GBool encryptMetadata;
 
117
  CryptAlgorithm encAlgorithm;
 
118
 
 
119
  GooString *ownerKey, *userKey;
 
120
  GooString *fileID;
 
121
  GBool ok;
 
122
};
 
123
 
 
124
#ifdef ENABLE_PLUGINS
 
125
//------------------------------------------------------------------------
 
126
// ExternalSecurityHandler
 
127
//------------------------------------------------------------------------
 
128
 
 
129
class ExternalSecurityHandler: public SecurityHandler {
 
130
public:
 
131
 
 
132
  ExternalSecurityHandler(PDFDoc *docA, Object *encryptDictA,
 
133
                          XpdfSecurityHandler *xshA);
 
134
  virtual ~ExternalSecurityHandler();
 
135
 
 
136
  virtual void *makeAuthData(GooString *ownerPassword,
 
137
                             GooString *userPassword);
 
138
  virtual void *getAuthData();
 
139
  virtual void freeAuthData(void *authData);
 
140
  virtual GBool authorize(void *authData);
 
141
  virtual int getPermissionFlags() { return permFlags; }
 
142
  virtual GBool getOwnerPasswordOk() { return gFalse; }
 
143
  virtual Guchar *getFileKey() { return fileKey; }
 
144
  virtual int getFileKeyLength() { return fileKeyLength; }
 
145
  virtual int getEncVersion() { return encVersion; }
 
146
  virtual CryptAlgorithm getEncAlgorithm() { return encAlgorithm; }
 
147
 
 
148
private:
 
149
 
 
150
  Object encryptDict;
 
151
  XpdfSecurityHandler *xsh;
 
152
  void *docData;
 
153
  int permFlags;
 
154
  Guchar fileKey[16];
 
155
  int fileKeyLength;
 
156
  int encVersion;
 
157
  CryptAlgorithm encAlgorithm;
 
158
  GBool ok;
 
159
};
 
160
#endif // ENABLE_PLUGINS
 
161
 
 
162
#endif