Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: core/include/fpdfapi/fpdf_parser.h

Issue 1781593003: Split off IPDF_SecurityHandler and CPDF_StandardSecurityHandler. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Nits Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « BUILD.gn ('k') | core/include/fpdfapi/ipdf_security_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #ifndef CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_ 7 #ifndef CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_
8 #define CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_ 8 #define CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_
9 9
10 #include <map> 10 #include <map>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 ~ScopedSetInsertion() { m_Set->erase(m_Entry); } 57 ~ScopedSetInsertion() { m_Set->erase(m_Entry); }
58 58
59 private: 59 private:
60 std::set<T>* const m_Set; 60 std::set<T>* const m_Set;
61 const T m_Entry; 61 const T m_Entry;
62 }; 62 };
63 63
64 // Indexed by 8-bit char code, contains unicode code points. 64 // Indexed by 8-bit char code, contains unicode code points.
65 extern const FX_WORD PDFDocEncoding[256]; 65 extern const FX_WORD PDFDocEncoding[256];
66 66
67 #define FXCIPHER_NONE 0
68 #define FXCIPHER_RC4 1
69 #define FXCIPHER_AES 2
70 #define FXCIPHER_AES2 3
71
72 class IPDF_SecurityHandler {
73 public:
74 virtual ~IPDF_SecurityHandler() {}
75
76 virtual FX_BOOL OnInit(CPDF_Parser* pParser,
77 CPDF_Dictionary* pEncryptDict) = 0;
78
79 virtual FX_DWORD GetPermissions() = 0;
80 virtual FX_BOOL GetCryptInfo(int& cipher,
81 const uint8_t*& buffer,
82 int& keylen) = 0;
83
84 virtual FX_BOOL IsMetadataEncrypted() = 0;
85 virtual CPDF_CryptoHandler* CreateCryptoHandler() = 0;
86 };
87
88 #define PDF_ENCRYPT_CONTENT 0
89
90 class CPDF_StandardSecurityHandler : public IPDF_SecurityHandler {
91 public:
92 CPDF_StandardSecurityHandler();
93 ~CPDF_StandardSecurityHandler() override;
94
95 // IPDF_SecurityHandler:
96 FX_BOOL OnInit(CPDF_Parser* pParser, CPDF_Dictionary* pEncryptDict) override;
97 FX_DWORD GetPermissions() override;
98 FX_BOOL GetCryptInfo(int& cipher,
99 const uint8_t*& buffer,
100 int& keylen) override;
101 FX_BOOL IsMetadataEncrypted() override;
102 CPDF_CryptoHandler* CreateCryptoHandler() override;
103
104 void OnCreate(CPDF_Dictionary* pEncryptDict,
105 CPDF_Array* pIdArray,
106 const uint8_t* user_pass,
107 FX_DWORD user_size,
108 const uint8_t* owner_pass,
109 FX_DWORD owner_size,
110 FX_DWORD type = PDF_ENCRYPT_CONTENT);
111
112 void OnCreate(CPDF_Dictionary* pEncryptDict,
113 CPDF_Array* pIdArray,
114 const uint8_t* user_pass,
115 FX_DWORD user_size,
116 FX_DWORD type = PDF_ENCRYPT_CONTENT);
117
118 CFX_ByteString GetUserPassword(const uint8_t* owner_pass,
119 FX_DWORD pass_size,
120 int32_t key_len);
121 int CheckPassword(const uint8_t* password,
122 FX_DWORD pass_size,
123 FX_BOOL bOwner,
124 uint8_t* key,
125 int key_len);
126
127 private:
128 int m_Version;
129
130 int m_Revision;
131
132 CPDF_Parser* m_pParser;
133
134 CPDF_Dictionary* m_pEncryptDict;
135
136 FX_BOOL LoadDict(CPDF_Dictionary* pEncryptDict);
137 FX_BOOL LoadDict(CPDF_Dictionary* pEncryptDict,
138 FX_DWORD type,
139 int& cipher,
140 int& key_len);
141
142 FX_BOOL CheckUserPassword(const uint8_t* password,
143 FX_DWORD pass_size,
144 FX_BOOL bIgnoreEncryptMeta,
145 uint8_t* key,
146 int32_t key_len);
147
148 FX_BOOL CheckOwnerPassword(const uint8_t* password,
149 FX_DWORD pass_size,
150 uint8_t* key,
151 int32_t key_len);
152 FX_BOOL AES256_CheckPassword(const uint8_t* password,
153 FX_DWORD size,
154 FX_BOOL bOwner,
155 uint8_t* key);
156 void AES256_SetPassword(CPDF_Dictionary* pEncryptDict,
157 const uint8_t* password,
158 FX_DWORD size,
159 FX_BOOL bOwner,
160 const uint8_t* key);
161 void AES256_SetPerms(CPDF_Dictionary* pEncryptDict,
162 FX_DWORD permission,
163 FX_BOOL bEncryptMetadata,
164 const uint8_t* key);
165 void OnCreate(CPDF_Dictionary* pEncryptDict,
166 CPDF_Array* pIdArray,
167 const uint8_t* user_pass,
168 FX_DWORD user_size,
169 const uint8_t* owner_pass,
170 FX_DWORD owner_size,
171 FX_BOOL bDefault,
172 FX_DWORD type);
173 FX_BOOL CheckSecurity(int32_t key_len);
174
175 FX_DWORD m_Permissions;
176
177 int m_Cipher;
178
179 uint8_t m_EncryptKey[32];
180
181 int m_KeyLen;
182 };
183
184 IPDF_SecurityHandler* FPDF_CreateStandardSecurityHandler();
185
186 class CPDF_CryptoHandler { 67 class CPDF_CryptoHandler {
187 public: 68 public:
188 virtual ~CPDF_CryptoHandler() {} 69 virtual ~CPDF_CryptoHandler() {}
189 70
190 virtual FX_BOOL Init(CPDF_Dictionary* pEncryptDict, 71 virtual FX_BOOL Init(CPDF_Dictionary* pEncryptDict,
191 IPDF_SecurityHandler* pSecurityHandler) = 0; 72 IPDF_SecurityHandler* pSecurityHandler) = 0;
192 73
193 virtual FX_DWORD DecryptGetSize(FX_DWORD src_size) = 0; 74 virtual FX_DWORD DecryptGetSize(FX_DWORD src_size) = 0;
194 75
195 virtual void* DecryptStart(FX_DWORD objnum, FX_DWORD gennum) = 0; 76 virtual void* DecryptStart(FX_DWORD objnum, FX_DWORD gennum) = 0;
(...skipping 12 matching lines...) Expand all
208 89
209 virtual FX_BOOL EncryptContent(FX_DWORD objnum, 90 virtual FX_BOOL EncryptContent(FX_DWORD objnum,
210 FX_DWORD version, 91 FX_DWORD version,
211 const uint8_t* src_buf, 92 const uint8_t* src_buf,
212 FX_DWORD src_size, 93 FX_DWORD src_size,
213 uint8_t* dest_buf, 94 uint8_t* dest_buf,
214 FX_DWORD& dest_size) = 0; 95 FX_DWORD& dest_size) = 0;
215 96
216 void Decrypt(FX_DWORD objnum, FX_DWORD version, CFX_ByteString& str); 97 void Decrypt(FX_DWORD objnum, FX_DWORD version, CFX_ByteString& str);
217 }; 98 };
99
218 class CPDF_StandardCryptoHandler : public CPDF_CryptoHandler { 100 class CPDF_StandardCryptoHandler : public CPDF_CryptoHandler {
219 public: 101 public:
220 CPDF_StandardCryptoHandler(); 102 CPDF_StandardCryptoHandler();
221 ~CPDF_StandardCryptoHandler() override; 103 ~CPDF_StandardCryptoHandler() override;
222 104
223 // CPDF_CryptoHandler 105 // CPDF_CryptoHandler
224 FX_BOOL Init(CPDF_Dictionary* pEncryptDict, 106 FX_BOOL Init(CPDF_Dictionary* pEncryptDict,
225 IPDF_SecurityHandler* pSecurityHandler) override; 107 IPDF_SecurityHandler* pSecurityHandler) override;
226 FX_DWORD DecryptGetSize(FX_DWORD src_size) override; 108 FX_DWORD DecryptGetSize(FX_DWORD src_size) override;
227 void* DecryptStart(FX_DWORD objnum, FX_DWORD gennum) override; 109 void* DecryptStart(FX_DWORD objnum, FX_DWORD gennum) override;
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 FX_DWORD src_size, 339 FX_DWORD src_size,
458 const CPDF_Dictionary* pDict, 340 const CPDF_Dictionary* pDict,
459 uint8_t*& dest_buf, 341 uint8_t*& dest_buf,
460 FX_DWORD& dest_size, 342 FX_DWORD& dest_size,
461 CFX_ByteString& ImageEncoding, 343 CFX_ByteString& ImageEncoding,
462 CPDF_Dictionary*& pImageParms, 344 CPDF_Dictionary*& pImageParms,
463 FX_DWORD estimated_size, 345 FX_DWORD estimated_size,
464 FX_BOOL bImageAcc); 346 FX_BOOL bImageAcc);
465 347
466 #endif // CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_ 348 #endif // CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | core/include/fpdfapi/ipdf_security_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698