summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r--core/fpdfapi/parser/cpdf_crypto_handler.h16
-rw-r--r--core/fpdfapi/parser/cpdf_parser.cpp11
-rw-r--r--core/fpdfapi/parser/cpdf_parser.h2
-rw-r--r--core/fpdfapi/parser/cpdf_security_handler.cpp4
-rw-r--r--core/fpdfapi/parser/cpdf_security_handler.h3
-rw-r--r--core/fpdfapi/parser/cpdf_syntax_parser.cpp6
-rw-r--r--core/fpdfapi/parser/cpdf_syntax_parser.h4
7 files changed, 21 insertions, 25 deletions
diff --git a/core/fpdfapi/parser/cpdf_crypto_handler.h b/core/fpdfapi/parser/cpdf_crypto_handler.h
index 1e3890a55b..24caff7081 100644
--- a/core/fpdfapi/parser/cpdf_crypto_handler.h
+++ b/core/fpdfapi/parser/cpdf_crypto_handler.h
@@ -7,6 +7,7 @@
#ifndef CORE_FPDFAPI_PARSER_CPDF_CRYPTO_HANDLER_H_
#define CORE_FPDFAPI_PARSER_CPDF_CRYPTO_HANDLER_H_
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_basic.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
@@ -14,10 +15,10 @@
class CPDF_Dictionary;
class CPDF_SecurityHandler;
-class CPDF_CryptoHandler {
+class CPDF_CryptoHandler : public CFX_Retainable {
public:
- CPDF_CryptoHandler();
- ~CPDF_CryptoHandler();
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
bool Init(CPDF_Dictionary* pEncryptDict,
CPDF_SecurityHandler* pSecurityHandler);
@@ -44,7 +45,11 @@ class CPDF_CryptoHandler {
bool Init(int cipher, const uint8_t* key, int keylen);
- protected:
+ private:
+ CPDF_CryptoHandler();
+ ~CPDF_CryptoHandler() override;
+
+ void PopulateKey(uint32_t objnum, uint32_t gennum, uint8_t* key);
void CryptBlock(bool bEncrypt,
uint32_t objnum,
uint32_t gennum,
@@ -64,9 +69,6 @@ class CPDF_CryptoHandler {
int m_KeyLen;
int m_Cipher;
uint8_t* m_pAESContext;
-
- private:
- void PopulateKey(uint32_t objnum, uint32_t gennum, uint8_t* key);
};
#endif // CORE_FPDFAPI_PARSER_CPDF_CRYPTO_HANDLER_H_
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp
index ecdeeacb19..f009798058 100644
--- a/core/fpdfapi/parser/cpdf_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_parser.cpp
@@ -100,8 +100,8 @@ void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) {
m_pEncryptDict = pDict;
}
-CPDF_CryptoHandler* CPDF_Parser::GetCryptoHandler() {
- return m_pSyntax->m_pCryptoHandler.get();
+CFX_RetainPtr<CPDF_CryptoHandler> CPDF_Parser::GetCryptoHandler() const {
+ return m_pSyntax->m_pCryptoHandler;
}
CFX_RetainPtr<IFX_SeekableReadStream> CPDF_Parser::GetFileAccess() const {
@@ -249,17 +249,16 @@ CPDF_Parser::Error CPDF_Parser::SetEncryptHandler() {
return PASSWORD_ERROR;
m_pSecurityHandler = std::move(pSecurityHandler);
- std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler(
- m_pSecurityHandler->CreateCryptoHandler());
+ auto pCryptoHandler = pdfium::MakeRetain<CPDF_CryptoHandler>();
if (!pCryptoHandler->Init(m_pEncryptDict, m_pSecurityHandler.get()))
return HANDLER_ERROR;
- m_pSyntax->SetEncrypt(std::move(pCryptoHandler));
+ m_pSyntax->SetEncrypt(pCryptoHandler);
}
return SUCCESS;
}
void CPDF_Parser::ReleaseEncryptHandler() {
- m_pSyntax->m_pCryptoHandler.reset();
+ m_pSyntax->m_pCryptoHandler.Reset();
m_pSecurityHandler.reset();
}
diff --git a/core/fpdfapi/parser/cpdf_parser.h b/core/fpdfapi/parser/cpdf_parser.h
index 47c2c9b885..7ae2d4627e 100644
--- a/core/fpdfapi/parser/cpdf_parser.h
+++ b/core/fpdfapi/parser/cpdf_parser.h
@@ -71,7 +71,7 @@ class CPDF_Parser {
uint16_t GetObjectGenNum(uint32_t objnum) const;
bool IsVersionUpdated() const { return m_bVersionUpdated; }
bool IsObjectFreeOrNull(uint32_t objnum) const;
- CPDF_CryptoHandler* GetCryptoHandler();
+ CFX_RetainPtr<CPDF_CryptoHandler> GetCryptoHandler() const;
CFX_RetainPtr<IFX_SeekableReadStream> GetFileAccess() const;
FX_FILESIZE GetObjectOffset(uint32_t objnum) const;
diff --git a/core/fpdfapi/parser/cpdf_security_handler.cpp b/core/fpdfapi/parser/cpdf_security_handler.cpp
index e95715b966..4ea5da3497 100644
--- a/core/fpdfapi/parser/cpdf_security_handler.cpp
+++ b/core/fpdfapi/parser/cpdf_security_handler.cpp
@@ -84,10 +84,6 @@ CPDF_SecurityHandler::CPDF_SecurityHandler()
CPDF_SecurityHandler::~CPDF_SecurityHandler() {}
-CPDF_CryptoHandler* CPDF_SecurityHandler::CreateCryptoHandler() {
- return new CPDF_CryptoHandler;
-}
-
bool CPDF_SecurityHandler::OnInit(CPDF_Parser* pParser,
CPDF_Dictionary* pEncryptDict) {
m_pParser = pParser;
diff --git a/core/fpdfapi/parser/cpdf_security_handler.h b/core/fpdfapi/parser/cpdf_security_handler.h
index 1a41b67195..93a4e4ff61 100644
--- a/core/fpdfapi/parser/cpdf_security_handler.h
+++ b/core/fpdfapi/parser/cpdf_security_handler.h
@@ -7,6 +7,7 @@
#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 "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
@@ -18,7 +19,6 @@
#define PDF_ENCRYPT_CONTENT 0
class CPDF_Array;
-class CPDF_CryptoHandler;
class CPDF_Dictionary;
class CPDF_Parser;
@@ -31,7 +31,6 @@ class CPDF_SecurityHandler {
uint32_t GetPermissions();
bool GetCryptInfo(int& cipher, const uint8_t*& buffer, int& keylen);
bool IsMetadataEncrypted() const;
- CPDF_CryptoHandler* CreateCryptoHandler();
void OnCreate(CPDF_Dictionary* pEncryptDict,
CPDF_Array* pIdArray,
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
index 1c84b859db..ecf2cf6e5b 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
@@ -635,7 +635,7 @@ std::unique_ptr<CPDF_Stream> CPDF_SyntaxParser::ReadStream(
const CFX_ByteStringC kEndObjStr("endobj");
CPDF_CryptoHandler* pCryptoHandler =
- objnum == m_MetadataObjnum ? nullptr : m_pCryptoHandler.get();
+ objnum == m_MetadataObjnum ? nullptr : m_pCryptoHandler.Get();
if (!pCryptoHandler) {
bool bSearchForKeyword = true;
if (len >= 0) {
@@ -911,6 +911,6 @@ FX_FILESIZE CPDF_SyntaxParser::FindTag(const CFX_ByteStringC& tag,
}
void CPDF_SyntaxParser::SetEncrypt(
- std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) {
- m_pCryptoHandler = std::move(pCryptoHandler);
+ const CFX_RetainPtr<CPDF_CryptoHandler>& pCryptoHandler) {
+ m_pCryptoHandler = pCryptoHandler;
}
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.h b/core/fpdfapi/parser/cpdf_syntax_parser.h
index 8dd9103f1b..9c2d84070d 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.h
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.h
@@ -51,7 +51,7 @@ class CPDF_SyntaxParser {
FX_FILESIZE limit);
FX_FILESIZE FindTag(const CFX_ByteStringC& tag, FX_FILESIZE limit);
- void SetEncrypt(std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler);
+ void SetEncrypt(const CFX_RetainPtr<CPDF_CryptoHandler>& pCryptoHandler);
bool ReadBlock(uint8_t* pBuf, uint32_t size);
bool GetCharAt(FX_FILESIZE pos, uint8_t& ch);
CFX_ByteString GetNextWord(bool* bIsNumber);
@@ -95,7 +95,7 @@ class CPDF_SyntaxParser {
uint8_t* m_pFileBuf;
uint32_t m_BufSize;
FX_FILESIZE m_BufOffset;
- std::unique_ptr<CPDF_CryptoHandler> m_pCryptoHandler;
+ CFX_RetainPtr<CPDF_CryptoHandler> m_pCryptoHandler;
uint8_t m_WordBuffer[257];
uint32_t m_WordSize;
CFX_WeakPtr<CFX_ByteStringPool> m_pPool;