diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-05-16 17:07:02 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-05-16 17:07:02 +0000 |
commit | 6facd15a7ecfbae24f2c356fa3b358288120a6f2 (patch) | |
tree | 414690887496c657e1147fd6e1342dd1bee7ba53 /core/fpdfapi | |
parent | fc0bbda00d476ba0c0b43dd88fd1d1a1d11577cc (diff) | |
download | pdfium-6facd15a7ecfbae24f2c356fa3b358288120a6f2.tar.xz |
Use pdfium::span<> in cpdf_creator.
Change-Id: I959fe5dc30fcfe2176c7e5a64b07d082313a22b4
Reviewed-on: https://pdfium-review.googlesource.com/32595
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi')
-rw-r--r-- | core/fpdfapi/edit/cpdf_creator.cpp | 8 | ||||
-rw-r--r-- | core/fpdfapi/edit/cpdf_encryptor.cpp | 6 | ||||
-rw-r--r-- | core/fpdfapi/edit/cpdf_flateencoder.h | 6 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_crypto_handler.cpp | 20 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_crypto_handler.h | 7 |
5 files changed, 21 insertions, 26 deletions
diff --git a/core/fpdfapi/edit/cpdf_creator.cpp b/core/fpdfapi/edit/cpdf_creator.cpp index 8a9eb5493e..5e3f9ee592 100644 --- a/core/fpdfapi/edit/cpdf_creator.cpp +++ b/core/fpdfapi/edit/cpdf_creator.cpp @@ -21,6 +21,7 @@ #include "core/fpdfapi/parser/fpdf_parser_utility.h" #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/fx_random.h" +#include "third_party/base/span.h" namespace { @@ -164,8 +165,7 @@ bool CPDF_Creator::WriteStream(const CPDF_Object* pStream, uint32_t objnum, CPDF_CryptoHandler* pCrypto) { CPDF_FlateEncoder encoder(pStream->AsStream(), pStream != m_pMetadata); - CPDF_Encryptor encryptor( - pCrypto, objnum, pdfium::make_span(encoder.GetData(), encoder.GetSize())); + CPDF_Encryptor encryptor(pCrypto, objnum, encoder.GetSpan()); if (static_cast<uint32_t>(encoder.GetDict()->GetIntegerFor("Length")) != encryptor.GetSpan().size()) { encoder.CloneDict(); @@ -238,9 +238,7 @@ bool CPDF_Creator::WriteDirectObj(uint32_t objnum, } case CPDF_Object::STREAM: { CPDF_FlateEncoder encoder(pObj->AsStream(), true); - CPDF_Encryptor encryptor( - GetCryptoHandler(), objnum, - pdfium::make_span(encoder.GetData(), encoder.GetSize())); + CPDF_Encryptor encryptor(GetCryptoHandler(), objnum, encoder.GetSpan()); if (static_cast<uint32_t>(encoder.GetDict()->GetIntegerFor("Length")) != encryptor.GetSpan().size()) { encoder.CloneDict(); diff --git a/core/fpdfapi/edit/cpdf_encryptor.cpp b/core/fpdfapi/edit/cpdf_encryptor.cpp index fd969b8b2c..61976186d2 100644 --- a/core/fpdfapi/edit/cpdf_encryptor.cpp +++ b/core/fpdfapi/edit/cpdf_encryptor.cpp @@ -18,11 +18,9 @@ CPDF_Encryptor::CPDF_Encryptor(CPDF_CryptoHandler* pHandler, return; } - uint32_t buf_size = - pHandler->EncryptGetSize(objnum, 0, src_data.data(), src_data.size()); + uint32_t buf_size = pHandler->EncryptGetSize(objnum, 0, src_data); m_NewBuf.resize(buf_size); - pHandler->EncryptContent(objnum, 0, src_data.data(), src_data.size(), - m_NewBuf.data(), + pHandler->EncryptContent(objnum, 0, src_data, m_NewBuf.data(), buf_size); // Updates |buf_size| with actual. m_NewBuf.resize(buf_size); m_Span = m_NewBuf; diff --git a/core/fpdfapi/edit/cpdf_flateencoder.h b/core/fpdfapi/edit/cpdf_flateencoder.h index b69b54d93b..05633f6814 100644 --- a/core/fpdfapi/edit/cpdf_flateencoder.h +++ b/core/fpdfapi/edit/cpdf_flateencoder.h @@ -14,6 +14,7 @@ #include "core/fxcrt/fx_memory.h" #include "core/fxcrt/maybe_owned.h" #include "core/fxcrt/retain_ptr.h" +#include "third_party/base/span.h" class CPDF_Stream; @@ -28,8 +29,9 @@ class CPDF_FlateEncoder { // Returns |m_pClonedDict| if it is valid. Otherwise returns |m_pDict|. const CPDF_Dictionary* GetDict() const; - uint32_t GetSize() const { return m_dwSize; } - const uint8_t* GetData() const { return m_pData.Get(); } + pdfium::span<const uint8_t> GetSpan() const { + return pdfium::make_span(m_pData.Get(), m_dwSize); + } private: uint32_t m_dwSize; diff --git a/core/fpdfapi/parser/cpdf_crypto_handler.cpp b/core/fpdfapi/parser/cpdf_crypto_handler.cpp index fa784668fa..f0bf1139fd 100644 --- a/core/fpdfapi/parser/cpdf_crypto_handler.cpp +++ b/core/fpdfapi/parser/cpdf_crypto_handler.cpp @@ -375,23 +375,21 @@ bool CPDF_CryptoHandler::DecryptStream(void* context, bool CPDF_CryptoHandler::DecryptFinish(void* context, CFX_BinaryBuf& dest_buf) { return CryptFinish(context, dest_buf, false); } -uint32_t CPDF_CryptoHandler::EncryptGetSize(uint32_t objnum, - uint32_t version, - const uint8_t* src_buf, - uint32_t src_size) { - if (m_Cipher == FXCIPHER_AES) { - return src_size + 32; - } - return src_size; + +uint32_t CPDF_CryptoHandler::EncryptGetSize( + uint32_t objnum, + uint32_t version, + pdfium::span<const uint8_t> source) const { + return m_Cipher == FXCIPHER_AES ? source.size() + 32 : source.size(); } bool CPDF_CryptoHandler::EncryptContent(uint32_t objnum, uint32_t gennum, - const uint8_t* src_buf, - uint32_t src_size, + pdfium::span<const uint8_t> source, uint8_t* dest_buf, uint32_t& dest_size) { - CryptBlock(true, objnum, gennum, src_buf, src_size, dest_buf, dest_size); + CryptBlock(true, objnum, gennum, source.data(), source.size(), dest_buf, + dest_size); return true; } diff --git a/core/fpdfapi/parser/cpdf_crypto_handler.h b/core/fpdfapi/parser/cpdf_crypto_handler.h index 1ca2130717..23dfe4aae1 100644 --- a/core/fpdfapi/parser/cpdf_crypto_handler.h +++ b/core/fpdfapi/parser/cpdf_crypto_handler.h @@ -15,6 +15,7 @@ #include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" #include "core/fxcrt/retain_ptr.h" +#include "third_party/base/span.h" class CPDF_Dictionary; class CPDF_Object; @@ -32,12 +33,10 @@ class CPDF_CryptoHandler { uint32_t EncryptGetSize(uint32_t objnum, uint32_t version, - const uint8_t* src_buf, - uint32_t src_size); + pdfium::span<const uint8_t> source) const; bool EncryptContent(uint32_t objnum, uint32_t version, - const uint8_t* src_buf, - uint32_t src_size, + pdfium::span<const uint8_t> source, uint8_t* dest_buf, uint32_t& dest_size); |