Coverage Report

Created: 2025-07-11 06:50

/src/xpdf-4.05/xpdf/SecurityHandler.h
Line
Count
Source (jump to first uncovered 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 <aconf.h>
13
14
#include "gtypes.h"
15
#include "Object.h"
16
17
class GString;
18
class PDFDoc;
19
struct XpdfSecurityHandler;
20
21
//------------------------------------------------------------------------
22
// SecurityHandler
23
//------------------------------------------------------------------------
24
25
class SecurityHandler {
26
public:
27
28
  static SecurityHandler *make(PDFDoc *docA, Object *encryptDictA);
29
30
  SecurityHandler(PDFDoc *docA);
31
  virtual ~SecurityHandler();
32
33
  // Returns true if the file is actually unencrypted.
34
0
  virtual GBool isUnencrypted() { return gFalse; }
35
36
  // Check the document's encryption.  If the document is encrypted,
37
  // this will first try <ownerPassword> and <userPassword> (in
38
  // "batch" mode), and if those fail, it will attempt to request a
39
  // password from the user.  This is the high-level function that
40
  // calls the lower level functions for the specific security handler
41
  // (requesting a password three times, etc.).  Returns true if the
42
  // document can be opened (if it's unencrypted, or if a correct
43
  // password is obtained); false otherwise (encrypted and no correct
44
  // password).
45
  GBool checkEncryption(GString *ownerPassword,
46
      GString *userPassword);
47
48
  // Create authorization data for the specified owner and user
49
  // passwords.  If the security handler doesn't support "batch" mode,
50
  // this function should return NULL.
51
  virtual void *makeAuthData(GString *ownerPassword,
52
           GString *userPassword) = 0;
53
54
  // Construct authorization data, typically by prompting the user for
55
  // a password.  Returns an authorization data object, or NULL to
56
  // cancel.
57
  virtual void *getAuthData() = 0;
58
59
  // Free the authorization data returned by makeAuthData or
60
  // getAuthData.
61
  virtual void freeAuthData(void *authData) = 0;
62
63
  // Attempt to authorize the document, using the supplied
64
  // authorization data (which may be NULL).  Returns true if
65
  // successful (i.e., if at least the right to open the document was
66
  // granted).
67
  virtual GBool authorize(void *authData) = 0;
68
69
  // Return the various authorization parameters.  These are only
70
  // valid after authorize has returned true.
71
  virtual int getPermissionFlags() = 0;
72
  virtual GBool getOwnerPasswordOk() = 0;
73
  virtual Guchar *getFileKey() = 0;
74
  virtual int getFileKeyLength() = 0;
75
  virtual int getEncVersion() = 0;
76
  virtual CryptAlgorithm getEncAlgorithm() = 0;
77
78
protected:
79
80
  PDFDoc *doc;
81
};
82
83
//------------------------------------------------------------------------
84
// StandardSecurityHandler
85
//------------------------------------------------------------------------
86
87
class StandardSecurityHandler: public SecurityHandler {
88
public:
89
90
  StandardSecurityHandler(PDFDoc *docA, Object *encryptDictA);
91
  virtual ~StandardSecurityHandler();
92
93
  virtual GBool isUnencrypted();
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
124
  virtual int getPermissionFlags() { return permFlags; }
100
124
  virtual GBool getOwnerPasswordOk() { return ownerPasswordOk; }
101
124
  virtual Guchar *getFileKey() { return fileKey; }
102
124
  virtual int getFileKeyLength() { return fileKeyLength; }
103
124
  virtual int getEncVersion() { return encVersion; }
104
124
  virtual CryptAlgorithm getEncAlgorithm() { return encAlgorithm; }
105
106
private:
107
108
  int permFlags;
109
  GBool ownerPasswordOk;
110
  Guchar fileKey[32];
111
  int fileKeyLength;
112
  int encVersion;
113
  int encRevision;
114
  CryptAlgorithm encAlgorithm;
115
  GBool encryptMetadata;
116
117
  GString *ownerKey, *userKey;
118
  GString *ownerEnc, *userEnc;
119
  GString *fileID;
120
  GBool ok;
121
};
122
123
#endif