diff options
Diffstat (limited to 'xfa/fxfa')
-rw-r--r-- | xfa/fxfa/cxfa_checksumcontext.cpp | 151 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_checksumcontext.h | 34 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffdoc.cpp | 4 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffdoc.h | 4 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffdochandler.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffdochandler.h | 2 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_saxcontext.h | 19 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_saxreaderhandler.cpp | 129 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_saxreaderhandler.h | 49 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_simple_parser.cpp | 4 |
10 files changed, 8 insertions, 390 deletions
diff --git a/xfa/fxfa/cxfa_checksumcontext.cpp b/xfa/fxfa/cxfa_checksumcontext.cpp deleted file mode 100644 index a59bdb16bf..0000000000 --- a/xfa/fxfa/cxfa_checksumcontext.cpp +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/cxfa_checksumcontext.h" - -#include "core/fdrm/crypto/fx_crypt.h" -#include "third_party/base/ptr_util.h" -#include "xfa/fxfa/cxfa_saxreaderhandler.h" - -namespace { - -struct FX_BASE64DATA { - uint32_t data1 : 2; - uint32_t data2 : 6; - uint32_t data3 : 4; - uint32_t data4 : 4; - uint32_t data5 : 6; - uint32_t data6 : 2; - uint32_t data7 : 8; -}; - -const char g_FXBase64EncoderMap[64] = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', -}; - -void Base64EncodePiece(const FX_BASE64DATA& src, int32_t iBytes, char dst[4]) { - dst[0] = g_FXBase64EncoderMap[src.data2]; - uint32_t b = src.data1 << 4; - if (iBytes > 1) { - b |= src.data4; - } - dst[1] = g_FXBase64EncoderMap[b]; - if (iBytes > 1) { - b = src.data3 << 2; - if (iBytes > 2) { - b |= src.data6; - } - dst[2] = g_FXBase64EncoderMap[b]; - if (iBytes > 2) { - dst[3] = g_FXBase64EncoderMap[src.data5]; - } else { - dst[3] = '='; - } - } else { - dst[2] = dst[3] = '='; - } -} - -int32_t Base64EncodeA(const uint8_t* pSrc, int32_t iSrcLen, char* pDst) { - ASSERT(pSrc); - if (iSrcLen < 1) { - return 0; - } - if (!pDst) { - int32_t iDstLen = iSrcLen / 3 * 4; - if ((iSrcLen % 3) != 0) { - iDstLen += 4; - } - return iDstLen; - } - FX_BASE64DATA srcData; - int32_t iBytes = 3; - char* pDstEnd = pDst; - while (iSrcLen > 0) { - if (iSrcLen > 2) { - ((uint8_t*)&srcData)[0] = *pSrc++; - ((uint8_t*)&srcData)[1] = *pSrc++; - ((uint8_t*)&srcData)[2] = *pSrc++; - iSrcLen -= 3; - } else { - *((uint32_t*)&srcData) = 0; - ((uint8_t*)&srcData)[0] = *pSrc++; - if (iSrcLen > 1) { - ((uint8_t*)&srcData)[1] = *pSrc++; - } - iBytes = iSrcLen; - iSrcLen = 0; - } - Base64EncodePiece(srcData, iBytes, pDstEnd); - pDstEnd += 4; - } - return pDstEnd - pDst; -} - -} // namespace - -CXFA_ChecksumContext::CXFA_ChecksumContext() {} - -CXFA_ChecksumContext::~CXFA_ChecksumContext() {} - -void CXFA_ChecksumContext::StartChecksum() { - FinishChecksum(); - m_pByteContext = pdfium::MakeUnique<CRYPT_sha1_context>(); - CRYPT_SHA1Start(m_pByteContext.get()); - m_bsChecksum.clear(); - m_pSAXReader = pdfium::MakeUnique<CFX_SAXReader>(); -} - -bool CXFA_ChecksumContext::UpdateChecksum( - const CFX_RetainPtr<IFX_SeekableReadStream>& pSrcFile, - FX_FILESIZE offset, - size_t size) { - if (!m_pSAXReader || !pSrcFile) - return false; - - if (size < 1) - size = pSrcFile->GetSize(); - - CXFA_SAXReaderHandler handler(this); - m_pSAXReader->SetHandler(&handler); - if (m_pSAXReader->StartParse( - pSrcFile, (uint32_t)offset, (uint32_t)size, - CFX_SaxParseMode_NotSkipSpace | CFX_SaxParseMode_NotConvert_amp | - CFX_SaxParseMode_NotConvert_lt | CFX_SaxParseMode_NotConvert_gt | - CFX_SaxParseMode_NotConvert_sharp) < 0) { - return false; - } - return m_pSAXReader->ContinueParse(nullptr) > 99; -} - -void CXFA_ChecksumContext::FinishChecksum() { - m_pSAXReader.reset(); - if (m_pByteContext) { - uint8_t digest[20]; - FXSYS_memset(digest, 0, 20); - CRYPT_SHA1Finish(m_pByteContext.get(), digest); - int32_t nLen = Base64EncodeA(digest, 20, nullptr); - char* pBuffer = m_bsChecksum.GetBuffer(nLen); - Base64EncodeA(digest, 20, pBuffer); - m_bsChecksum.ReleaseBuffer(nLen); - m_pByteContext.reset(); - } -} - -CFX_ByteString CXFA_ChecksumContext::GetChecksum() const { - return m_bsChecksum; -} - -void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) { - if (!m_pByteContext) - return; - - CRYPT_SHA1Update(m_pByteContext.get(), bsText.raw_str(), bsText.GetLength()); -} diff --git a/xfa/fxfa/cxfa_checksumcontext.h b/xfa/fxfa/cxfa_checksumcontext.h deleted file mode 100644 index ca1b53007e..0000000000 --- a/xfa/fxfa/cxfa_checksumcontext.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_CXFA_CHECKSUMCONTEXT_H_ -#define XFA_FXFA_CXFA_CHECKSUMCONTEXT_H_ - -#include <memory> - -#include "core/fdrm/crypto/fx_crypt.h" -#include "xfa/fde/xml/cfx_saxreader.h" - -class CXFA_ChecksumContext { - public: - CXFA_ChecksumContext(); - ~CXFA_ChecksumContext(); - - void StartChecksum(); - void Update(const CFX_ByteStringC& bsText); - bool UpdateChecksum(const CFX_RetainPtr<IFX_SeekableReadStream>& pSrcFile, - FX_FILESIZE offset = 0, - size_t size = 0); - void FinishChecksum(); - CFX_ByteString GetChecksum() const; - - private: - std::unique_ptr<CFX_SAXReader> m_pSAXReader; - std::unique_ptr<CRYPT_sha1_context> m_pByteContext; - CFX_ByteString m_bsChecksum; -}; - -#endif // XFA_FXFA_CXFA_CHECKSUMCONTEXT_H_ diff --git a/xfa/fxfa/cxfa_ffdoc.cpp b/xfa/fxfa/cxfa_ffdoc.cpp index 43551008db..b5036926aa 100644 --- a/xfa/fxfa/cxfa_ffdoc.cpp +++ b/xfa/fxfa/cxfa_ffdoc.cpp @@ -14,13 +14,13 @@ #include "core/fpdfapi/parser/cpdf_document.h" #include "core/fpdfapi/parser/fpdf_parser_decode.h" #include "core/fpdfdoc/cpdf_nametree.h" +#include "core/fxcrt/cfx_checksumcontext.h" #include "core/fxcrt/fx_ext.h" #include "core/fxcrt/fx_memory.h" #include "third_party/base/ptr_util.h" #include "xfa/fde/xml/fde_xml_imp.h" #include "xfa/fwl/cfwl_notedriver.h" #include "xfa/fxfa/app/xfa_ffnotify.h" -#include "xfa/fxfa/cxfa_checksumcontext.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdocview.h" #include "xfa/fxfa/cxfa_ffwidget.h" @@ -403,7 +403,7 @@ CFX_RetainPtr<CFX_DIBitmap> CXFA_FFDoc::GetPDFNamedImage( bool CXFA_FFDoc::SavePackage( XFA_HashCode code, const CFX_RetainPtr<IFX_SeekableWriteStream>& pFile, - CXFA_ChecksumContext* pCSContext) { + CFX_ChecksumContext* pCSContext) { CXFA_Document* doc = m_pDocumentParser->GetDocument(); std::unique_ptr<CXFA_DataExporter> pExport(new CXFA_DataExporter(doc)); CXFA_Node* pNode = code == XFA_HASHCODE_Xfa ? doc->GetRoot() diff --git a/xfa/fxfa/cxfa_ffdoc.h b/xfa/fxfa/cxfa_ffdoc.h index 80dafba029..0bba956f14 100644 --- a/xfa/fxfa/cxfa_ffdoc.h +++ b/xfa/fxfa/cxfa_ffdoc.h @@ -14,7 +14,7 @@ #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_document_parser.h" -class CXFA_ChecksumContext; +class CFX_ChecksumContext; class CXFA_FFApp; class CXFA_FFNotify; class CXFA_FFDocView; @@ -73,7 +73,7 @@ class CXFA_FFDoc { bool SavePackage(XFA_HashCode code, const CFX_RetainPtr<IFX_SeekableWriteStream>& pFile, - CXFA_ChecksumContext* pCSContext); + CFX_ChecksumContext* pCSContext); bool ImportData(const CFX_RetainPtr<IFX_SeekableReadStream>& pStream, bool bXDP = true); diff --git a/xfa/fxfa/cxfa_ffdochandler.cpp b/xfa/fxfa/cxfa_ffdochandler.cpp index f926638406..b0a84fa29a 100644 --- a/xfa/fxfa/cxfa_ffdochandler.cpp +++ b/xfa/fxfa/cxfa_ffdochandler.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/cxfa_ffdochandler.h" -#include "xfa/fxfa/cxfa_checksumcontext.h" +#include "core/fxcrt/cfx_checksumcontext.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_scriptcontext.h" diff --git a/xfa/fxfa/cxfa_ffdochandler.h b/xfa/fxfa/cxfa_ffdochandler.h index b54c36c1d7..45b2ee07e1 100644 --- a/xfa/fxfa/cxfa_ffdochandler.h +++ b/xfa/fxfa/cxfa_ffdochandler.h @@ -9,7 +9,7 @@ #include "xfa/fxfa/fxfa.h" -class CXFA_ChecksumContext; +class CFX_ChecksumContext; class CXFA_FFDocHandler { public: diff --git a/xfa/fxfa/cxfa_saxcontext.h b/xfa/fxfa/cxfa_saxcontext.h deleted file mode 100644 index 47e7b78423..0000000000 --- a/xfa/fxfa/cxfa_saxcontext.h +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_CXFA_SAXCONTEXT_H_ -#define XFA_FXFA_CXFA_SAXCONTEXT_H_ - -class CXFA_SAXContext { - public: - CXFA_SAXContext() : m_eNode(CFX_SAXItem::Type::Unknown) {} - - CFX_ByteTextBuf m_TextBuf; - CFX_ByteString m_bsTagName; - CFX_SAXItem::Type m_eNode; -}; - -#endif // XFA_FXFA_CXFA_SAXCONTEXT_H_ diff --git a/xfa/fxfa/cxfa_saxreaderhandler.cpp b/xfa/fxfa/cxfa_saxreaderhandler.cpp deleted file mode 100644 index c09bdf5b4c..0000000000 --- a/xfa/fxfa/cxfa_saxreaderhandler.cpp +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/cxfa_saxreaderhandler.h" - -#include "xfa/fxfa/cxfa_checksumcontext.h" - -CXFA_SAXReaderHandler::CXFA_SAXReaderHandler(CXFA_ChecksumContext* pContext) - : m_pContext(pContext) { - ASSERT(m_pContext); -} - -CXFA_SAXReaderHandler::~CXFA_SAXReaderHandler() {} - -CXFA_SAXContext* CXFA_SAXReaderHandler::OnTagEnter( - const CFX_ByteStringC& bsTagName, - CFX_SAXItem::Type eType, - uint32_t dwStartPos) { - UpdateChecksum(true); - if (eType != CFX_SAXItem::Type::Tag && - eType != CFX_SAXItem::Type::Instruction) { - return nullptr; - } - - m_SAXContext.m_eNode = eType; - CFX_ByteTextBuf& textBuf = m_SAXContext.m_TextBuf; - textBuf << "<"; - if (eType == CFX_SAXItem::Type::Instruction) - textBuf << "?"; - - textBuf << bsTagName; - m_SAXContext.m_bsTagName = bsTagName; - return &m_SAXContext; -} - -void CXFA_SAXReaderHandler::OnTagAttribute(CXFA_SAXContext* pTag, - const CFX_ByteStringC& bsAttri, - const CFX_ByteStringC& bsValue) { - if (!pTag) - return; - pTag->m_TextBuf << " " << bsAttri << "=\"" << bsValue << "\""; -} - -void CXFA_SAXReaderHandler::OnTagBreak(CXFA_SAXContext* pTag) { - if (!pTag) - return; - - pTag->m_TextBuf << ">"; - UpdateChecksum(false); -} - -void CXFA_SAXReaderHandler::OnTagData(CXFA_SAXContext* pTag, - CFX_SAXItem::Type eType, - const CFX_ByteStringC& bsData, - uint32_t dwStartPos) { - if (!pTag) - return; - - CFX_ByteTextBuf& textBuf = pTag->m_TextBuf; - if (eType == CFX_SAXItem::Type::CharData) - textBuf << "<![CDATA["; - - textBuf << bsData; - if (eType == CFX_SAXItem::Type::CharData) - textBuf << "]]>"; -} - -void CXFA_SAXReaderHandler::OnTagClose(CXFA_SAXContext* pTag, - uint32_t dwEndPos) { - if (!pTag) - return; - - CFX_ByteTextBuf& textBuf = pTag->m_TextBuf; - if (pTag->m_eNode == CFX_SAXItem::Type::Instruction) - textBuf << "?>"; - else if (pTag->m_eNode == CFX_SAXItem::Type::Tag) - textBuf << "></" << pTag->m_bsTagName.AsStringC() << ">"; - - UpdateChecksum(false); -} - -void CXFA_SAXReaderHandler::OnTagEnd(CXFA_SAXContext* pTag, - const CFX_ByteStringC& bsTagName, - uint32_t dwEndPos) { - if (!pTag) - return; - - pTag->m_TextBuf << "</" << bsTagName << ">"; - UpdateChecksum(false); -} - -void CXFA_SAXReaderHandler::OnTargetData(CXFA_SAXContext* pTag, - CFX_SAXItem::Type eType, - const CFX_ByteStringC& bsData, - uint32_t dwStartPos) { - if (!pTag && eType != CFX_SAXItem::Type::Comment) - return; - - if (eType == CFX_SAXItem::Type::Comment) { - m_SAXContext.m_TextBuf << "<!--" << bsData << "-->"; - UpdateChecksum(false); - } else { - pTag->m_TextBuf << " " << bsData; - } -} - -void CXFA_SAXReaderHandler::UpdateChecksum(bool bCheckSpace) { - int32_t iLength = m_SAXContext.m_TextBuf.GetLength(); - if (iLength < 1) - return; - - uint8_t* pBuffer = m_SAXContext.m_TextBuf.GetBuffer(); - bool bUpdata = true; - if (bCheckSpace) { - bUpdata = false; - for (int32_t i = 0; i < iLength; i++) { - bUpdata = (pBuffer[i] > 0x20); - if (bUpdata) - break; - } - } - if (bUpdata) - m_pContext->Update(CFX_ByteStringC(pBuffer, iLength)); - - m_SAXContext.m_TextBuf.Clear(); -} diff --git a/xfa/fxfa/cxfa_saxreaderhandler.h b/xfa/fxfa/cxfa_saxreaderhandler.h deleted file mode 100644 index 3ad69322bb..0000000000 --- a/xfa/fxfa/cxfa_saxreaderhandler.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_CXFA_SAXREADERHANDLER_H_ -#define XFA_FXFA_CXFA_SAXREADERHANDLER_H_ - -#include "core/fxcrt/fx_string.h" -#include "xfa/fde/xml/cfx_saxreader.h" -#include "xfa/fxfa/cxfa_saxcontext.h" - -class CXFA_ChecksumContext; - -class CXFA_SAXReaderHandler { - public: - explicit CXFA_SAXReaderHandler(CXFA_ChecksumContext* pContext); - ~CXFA_SAXReaderHandler(); - - CXFA_SAXContext* OnTagEnter(const CFX_ByteStringC& bsTagName, - CFX_SAXItem::Type eType, - uint32_t dwStartPos); - void OnTagAttribute(CXFA_SAXContext* pTag, - const CFX_ByteStringC& bsAttri, - const CFX_ByteStringC& bsValue); - void OnTagBreak(CXFA_SAXContext* pTag); - void OnTagData(CXFA_SAXContext* pTag, - CFX_SAXItem::Type eType, - const CFX_ByteStringC& bsData, - uint32_t dwStartPos); - void OnTagClose(CXFA_SAXContext* pTag, uint32_t dwEndPos); - void OnTagEnd(CXFA_SAXContext* pTag, - const CFX_ByteStringC& bsTagName, - uint32_t dwEndPos); - - void OnTargetData(CXFA_SAXContext* pTag, - CFX_SAXItem::Type eType, - const CFX_ByteStringC& bsData, - uint32_t dwStartPos); - - private: - void UpdateChecksum(bool bCheckSpace); - - CXFA_ChecksumContext* m_pContext; - CXFA_SAXContext m_SAXContext; -}; - -#endif // XFA_FXFA_CXFA_SAXREADERHANDLER_H_ diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp index a4a785c98e..949f7864ea 100644 --- a/xfa/fxfa/parser/cxfa_simple_parser.cpp +++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp @@ -8,10 +8,10 @@ #include <utility> +#include "core/fxcrt/cfx_checksumcontext.h" #include "core/fxcrt/fx_ext.h" #include "third_party/base/ptr_util.h" #include "xfa/fgas/crt/fgas_codepage.h" -#include "xfa/fxfa/cxfa_checksumcontext.h" #include "xfa/fxfa/fxfa.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_node.h" @@ -661,7 +661,7 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_TemplateForm( m_pXMLParser->m_dwCheckStatus != 0x03) { return nullptr; } - std::unique_ptr<CXFA_ChecksumContext> pChecksum(new CXFA_ChecksumContext); + std::unique_ptr<CFX_ChecksumContext> pChecksum(new CFX_ChecksumContext); pChecksum->StartChecksum(); pChecksum->UpdateChecksum(m_pFileRead, m_pXMLParser->m_nStart[0], m_pXMLParser->m_nSize[0]); |