summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r--core/fpdfapi/parser/cpdf_parser.cpp19
-rw-r--r--core/fpdfapi/parser/cpdf_parser.h5
-rw-r--r--core/fpdfapi/parser/cpdf_security_handler.cpp5
-rw-r--r--core/fpdfapi/parser/cpdf_security_handler.h10
4 files changed, 25 insertions, 14 deletions
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp
index 17f49c6324..a1b8a2deba 100644
--- a/core/fpdfapi/parser/cpdf_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_parser.cpp
@@ -155,10 +155,6 @@ void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) {
m_pEncryptDict = pDict;
}
-CPDF_CryptoHandler* CPDF_Parser::GetCryptoHandler() const {
- return m_pCryptoHandler.get();
-}
-
RetainPtr<IFX_SeekableReadStream> CPDF_Parser::GetFileAccess() const {
return m_pSyntax->GetFileAccess();
}
@@ -315,17 +311,15 @@ CPDF_Parser::Error CPDF_Parser::SetEncryptHandler() {
m_Password))
return PASSWORD_ERROR;
- m_pSecurityHandler = std::move(pSecurityHandler);
- auto pCryptoHandler = pdfium::MakeUnique<CPDF_CryptoHandler>();
- if (!pCryptoHandler->Init(m_pEncryptDict.Get(), m_pSecurityHandler.get()))
+ if (!pSecurityHandler->InitCryptoHandler())
return HANDLER_ERROR;
- m_pCryptoHandler = std::move(pCryptoHandler);
+
+ m_pSecurityHandler = std::move(pSecurityHandler);
}
return SUCCESS;
}
void CPDF_Parser::ReleaseEncryptHandler() {
- m_pCryptoHandler.reset();
m_pSecurityHandler.reset();
SetEncryptDictionary(nullptr);
}
@@ -1276,9 +1270,12 @@ std::unique_ptr<CPDF_Object> CPDF_Parser::ParseIndirectObjectAtInternal(
if (result && objnum && result->GetObjNum() != objnum)
return nullptr;
- const bool should_decrypt = m_pCryptoHandler && objnum != m_MetadataObjnum;
+ const bool should_decrypt = m_pSecurityHandler &&
+ m_pSecurityHandler->GetCryptoHandler() &&
+ objnum != m_MetadataObjnum;
if (should_decrypt)
- result = m_pCryptoHandler->DecryptObjectTree(std::move(result));
+ result = m_pSecurityHandler->GetCryptoHandler()->DecryptObjectTree(
+ std::move(result));
return result;
}
diff --git a/core/fpdfapi/parser/cpdf_parser.h b/core/fpdfapi/parser/cpdf_parser.h
index 0c7d29f728..2dee1ab9e1 100644
--- a/core/fpdfapi/parser/cpdf_parser.h
+++ b/core/fpdfapi/parser/cpdf_parser.h
@@ -76,7 +76,9 @@ class CPDF_Parser {
FX_FILESIZE GetObjectPositionOrZero(uint32_t objnum) const;
uint16_t GetObjectGenNum(uint32_t objnum) const;
bool IsObjectFreeOrNull(uint32_t objnum) const;
- CPDF_CryptoHandler* GetCryptoHandler() const;
+ CPDF_SecurityHandler* GetSecurityHandler() const {
+ return m_pSecurityHandler.get();
+ }
RetainPtr<IFX_SeekableReadStream> GetFileAccess() const;
bool IsObjectFree(uint32_t objnum) const;
@@ -221,7 +223,6 @@ class CPDF_Parser {
// All indirect object numbers that are being parsed.
std::set<uint32_t> m_ParsingObjNums;
- std::unique_ptr<CPDF_CryptoHandler> m_pCryptoHandler;
uint32_t m_MetadataObjnum = 0;
};
diff --git a/core/fpdfapi/parser/cpdf_security_handler.cpp b/core/fpdfapi/parser/cpdf_security_handler.cpp
index dce2ac4fdc..03c15458a9 100644
--- a/core/fpdfapi/parser/cpdf_security_handler.cpp
+++ b/core/fpdfapi/parser/cpdf_security_handler.cpp
@@ -706,3 +706,8 @@ void CPDF_SecurityHandler::AES256_SetPerms(CPDF_Dictionary* pEncryptDict,
CRYPT_AESEncrypt(&aes, buf1, buf, 16);
pEncryptDict->SetNewFor<CPDF_String>("Perms", ByteString(buf1, 16), false);
}
+
+bool CPDF_SecurityHandler::InitCryptoHandler() {
+ m_pCryptoHandler = pdfium::MakeUnique<CPDF_CryptoHandler>();
+ return m_pCryptoHandler->Init(m_pEncryptDict.Get(), this);
+}
diff --git a/core/fpdfapi/parser/cpdf_security_handler.h b/core/fpdfapi/parser/cpdf_security_handler.h
index 8b55fa21a7..c03d97c411 100644
--- a/core/fpdfapi/parser/cpdf_security_handler.h
+++ b/core/fpdfapi/parser/cpdf_security_handler.h
@@ -7,7 +7,8 @@
#ifndef CORE_FPDFAPI_PARSER_CPDF_SECURITY_HANDLER_H_
#define CORE_FPDFAPI_PARSER_CPDF_SECURITY_HANDLER_H_
-#include "core/fpdfapi/parser/cpdf_crypto_handler.h"
+#include <memory>
+
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
@@ -19,6 +20,7 @@
#define PDF_ENCRYPT_CONTENT 0
class CPDF_Array;
+class CPDF_CryptoHandler;
class CPDF_Dictionary;
class CPDF_Parser;
@@ -57,6 +59,11 @@ class CPDF_SecurityHandler {
uint8_t* key,
int key_len);
+ bool InitCryptoHandler();
+ CPDF_CryptoHandler* GetCryptoHandler() const {
+ return m_pCryptoHandler.get();
+ }
+
private:
bool LoadDict(CPDF_Dictionary* pEncryptDict);
bool LoadDict(CPDF_Dictionary* pEncryptDict,
@@ -107,6 +114,7 @@ class CPDF_SecurityHandler {
uint8_t m_EncryptKey[32];
int m_KeyLen;
bool m_bOwnerUnlocked;
+ std::unique_ptr<CPDF_CryptoHandler> m_pCryptoHandler;
};
#endif // CORE_FPDFAPI_PARSER_CPDF_SECURITY_HANDLER_H_