diff options
author | Artem Strygin <art-snake@yandex-team.ru> | 2017-10-03 18:10:10 +0300 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-10-03 16:09:25 +0000 |
commit | 6caef3028fd5ce9751fb246b084ad0e139aa9c77 (patch) | |
tree | 2279a9a55eb913344241d3aec44c572006d2c9de /core/fpdfapi | |
parent | 97538d86576da009ea3f40546cd5e8a49d6126a3 (diff) | |
download | pdfium-6caef3028fd5ce9751fb246b084ad0e139aa9c77.tar.xz |
Change the ownership of the CPDF_CryptoHandler.
Change-Id: I3ae8337c1a77063470eb5baa97db62ea2e90688b
Reviewed-on: https://pdfium-review.googlesource.com/15230
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Art Snake <art-snake@yandex-team.ru>
Diffstat (limited to 'core/fpdfapi')
-rw-r--r-- | core/fpdfapi/edit/cpdf_creator.cpp | 2 | ||||
-rw-r--r-- | core/fpdfapi/edit/cpdf_creator.h | 3 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_crypto_handler.h | 9 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_parser.cpp | 10 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_parser.h | 4 |
5 files changed, 13 insertions, 15 deletions
diff --git a/core/fpdfapi/edit/cpdf_creator.cpp b/core/fpdfapi/edit/cpdf_creator.cpp index c060f5897b..e176d85044 100644 --- a/core/fpdfapi/edit/cpdf_creator.cpp +++ b/core/fpdfapi/edit/cpdf_creator.cpp @@ -807,7 +807,7 @@ void CPDF_Creator::InitID() { CPDF_SecurityHandler handler; handler.OnCreate(m_pEncryptDict.Get(), m_pIDArray.get(), user_pass.raw_str(), user_pass.GetLength(), flag); - m_pCryptoHandler = pdfium::MakeRetain<CPDF_CryptoHandler>(); + m_pCryptoHandler = pdfium::MakeUnique<CPDF_CryptoHandler>(); m_pCryptoHandler->Init(m_pEncryptDict.Get(), &handler); m_bSecurityChanged = true; } diff --git a/core/fpdfapi/edit/cpdf_creator.h b/core/fpdfapi/edit/cpdf_creator.h index e8fe18f87d..4e8f9e8dbe 100644 --- a/core/fpdfapi/edit/cpdf_creator.h +++ b/core/fpdfapi/edit/cpdf_creator.h @@ -12,6 +12,7 @@ #include <vector> #include "core/fxcrt/fx_stream.h" +#include "core/fxcrt/maybe_owned.h" #include "core/fxcrt/retain_ptr.h" #include "core/fxcrt/unowned_ptr.h" @@ -85,7 +86,7 @@ class CPDF_Creator { bool m_bSecurityChanged; UnownedPtr<CPDF_Dictionary> m_pEncryptDict; uint32_t m_dwEncryptObjNum; - RetainPtr<CPDF_CryptoHandler> m_pCryptoHandler; + fxcrt::MaybeOwned<CPDF_CryptoHandler> m_pCryptoHandler; UnownedPtr<CPDF_Object> m_pMetadata; uint32_t m_dwLastObjNum; std::unique_ptr<IFX_ArchiveStream> m_Archive; diff --git a/core/fpdfapi/parser/cpdf_crypto_handler.h b/core/fpdfapi/parser/cpdf_crypto_handler.h index 60f32b70ba..7175088de4 100644 --- a/core/fpdfapi/parser/cpdf_crypto_handler.h +++ b/core/fpdfapi/parser/cpdf_crypto_handler.h @@ -20,10 +20,10 @@ class CPDF_Dictionary; class CPDF_Object; class CPDF_SecurityHandler; -class CPDF_CryptoHandler : public Retainable { +class CPDF_CryptoHandler { public: - template <typename T, typename... Args> - friend RetainPtr<T> pdfium::MakeRetain(Args&&... args); + CPDF_CryptoHandler(); + ~CPDF_CryptoHandler(); static bool IsSignatureDictionary(const CPDF_Dictionary* dictionary); @@ -48,9 +48,6 @@ class CPDF_CryptoHandler : public Retainable { bool IsCipherAES() const; private: - CPDF_CryptoHandler(); - ~CPDF_CryptoHandler() override; - uint32_t DecryptGetSize(uint32_t src_size); void* DecryptStart(uint32_t objnum, uint32_t gennum); ByteString Decrypt(uint32_t objnum, uint32_t gennum, const ByteString& str); diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp index 336e6625b5..1965146728 100644 --- a/core/fpdfapi/parser/cpdf_parser.cpp +++ b/core/fpdfapi/parser/cpdf_parser.cpp @@ -155,8 +155,8 @@ void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) { m_pEncryptDict = pDict; } -RetainPtr<CPDF_CryptoHandler> CPDF_Parser::GetCryptoHandler() const { - return m_pCryptoHandler; +CPDF_CryptoHandler* CPDF_Parser::GetCryptoHandler() const { + return m_pCryptoHandler.get(); } RetainPtr<IFX_SeekableReadStream> CPDF_Parser::GetFileAccess() const { @@ -315,16 +315,16 @@ CPDF_Parser::Error CPDF_Parser::SetEncryptHandler() { return PASSWORD_ERROR; m_pSecurityHandler = std::move(pSecurityHandler); - auto pCryptoHandler = pdfium::MakeRetain<CPDF_CryptoHandler>(); + auto pCryptoHandler = pdfium::MakeUnique<CPDF_CryptoHandler>(); if (!pCryptoHandler->Init(m_pEncryptDict.Get(), m_pSecurityHandler.get())) return HANDLER_ERROR; - m_pCryptoHandler = pCryptoHandler; + m_pCryptoHandler = std::move(pCryptoHandler); } return SUCCESS; } void CPDF_Parser::ReleaseEncryptHandler() { - m_pCryptoHandler.Reset(); + m_pCryptoHandler.reset(); m_pSecurityHandler.reset(); SetEncryptDictionary(nullptr); } diff --git a/core/fpdfapi/parser/cpdf_parser.h b/core/fpdfapi/parser/cpdf_parser.h index 5114ee6ba3..0c7d29f728 100644 --- a/core/fpdfapi/parser/cpdf_parser.h +++ b/core/fpdfapi/parser/cpdf_parser.h @@ -76,7 +76,7 @@ class CPDF_Parser { FX_FILESIZE GetObjectPositionOrZero(uint32_t objnum) const; uint16_t GetObjectGenNum(uint32_t objnum) const; bool IsObjectFreeOrNull(uint32_t objnum) const; - RetainPtr<CPDF_CryptoHandler> GetCryptoHandler() const; + CPDF_CryptoHandler* GetCryptoHandler() const; RetainPtr<IFX_SeekableReadStream> GetFileAccess() const; bool IsObjectFree(uint32_t objnum) const; @@ -221,7 +221,7 @@ class CPDF_Parser { // All indirect object numbers that are being parsed. std::set<uint32_t> m_ParsingObjNums; - RetainPtr<CPDF_CryptoHandler> m_pCryptoHandler; + std::unique_ptr<CPDF_CryptoHandler> m_pCryptoHandler; uint32_t m_MetadataObjnum = 0; }; |