| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fxfa/include/xfa_checksum.h" | 7 #include "xfa/fxfa/include/xfa_checksum.h" |
| 8 | 8 |
| 9 #include "core/fdrm/crypto/include/fx_crypt.h" | 9 #include "core/fdrm/crypto/include/fx_crypt.h" |
| 10 | 10 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 dst[3] = g_FXBase64EncoderMap[src.data5]; | 47 dst[3] = g_FXBase64EncoderMap[src.data5]; |
| 48 } else { | 48 } else { |
| 49 dst[3] = '='; | 49 dst[3] = '='; |
| 50 } | 50 } |
| 51 } else { | 51 } else { |
| 52 dst[2] = dst[3] = '='; | 52 dst[2] = dst[3] = '='; |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 int32_t Base64EncodeA(const uint8_t* pSrc, int32_t iSrcLen, FX_CHAR* pDst) { | 56 int32_t Base64EncodeA(const uint8_t* pSrc, int32_t iSrcLen, FX_CHAR* pDst) { |
| 57 ASSERT(pSrc != NULL); | 57 ASSERT(pSrc); |
| 58 if (iSrcLen < 1) { | 58 if (iSrcLen < 1) { |
| 59 return 0; | 59 return 0; |
| 60 } | 60 } |
| 61 if (pDst == NULL) { | 61 if (!pDst) { |
| 62 int32_t iDstLen = iSrcLen / 3 * 4; | 62 int32_t iDstLen = iSrcLen / 3 * 4; |
| 63 if ((iSrcLen % 3) != 0) { | 63 if ((iSrcLen % 3) != 0) { |
| 64 iDstLen += 4; | 64 iDstLen += 4; |
| 65 } | 65 } |
| 66 return iDstLen; | 66 return iDstLen; |
| 67 } | 67 } |
| 68 FX_BASE64DATA srcData; | 68 FX_BASE64DATA srcData; |
| 69 int32_t iBytes = 3; | 69 int32_t iBytes = 3; |
| 70 FX_CHAR* pDstEnd = pDst; | 70 FX_CHAR* pDstEnd = pDst; |
| 71 while (iSrcLen > 0) { | 71 while (iSrcLen > 0) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 96 ASSERT(m_pContext); | 96 ASSERT(m_pContext); |
| 97 } | 97 } |
| 98 CXFA_SAXReaderHandler::~CXFA_SAXReaderHandler() {} | 98 CXFA_SAXReaderHandler::~CXFA_SAXReaderHandler() {} |
| 99 CXFA_SAXContext* CXFA_SAXReaderHandler::OnTagEnter( | 99 CXFA_SAXContext* CXFA_SAXReaderHandler::OnTagEnter( |
| 100 const CFX_ByteStringC& bsTagName, | 100 const CFX_ByteStringC& bsTagName, |
| 101 CFX_SAXItem::Type eType, | 101 CFX_SAXItem::Type eType, |
| 102 uint32_t dwStartPos) { | 102 uint32_t dwStartPos) { |
| 103 UpdateChecksum(TRUE); | 103 UpdateChecksum(TRUE); |
| 104 if (eType != CFX_SAXItem::Type::Tag && | 104 if (eType != CFX_SAXItem::Type::Tag && |
| 105 eType != CFX_SAXItem::Type::Instruction) { | 105 eType != CFX_SAXItem::Type::Instruction) { |
| 106 return NULL; | 106 return nullptr; |
| 107 } | 107 } |
| 108 m_SAXContext.m_eNode = eType; | 108 m_SAXContext.m_eNode = eType; |
| 109 CFX_ByteTextBuf& textBuf = m_SAXContext.m_TextBuf; | 109 CFX_ByteTextBuf& textBuf = m_SAXContext.m_TextBuf; |
| 110 textBuf << "<"; | 110 textBuf << "<"; |
| 111 if (eType == CFX_SAXItem::Type::Instruction) { | 111 if (eType == CFX_SAXItem::Type::Instruction) { |
| 112 textBuf << "?"; | 112 textBuf << "?"; |
| 113 } | 113 } |
| 114 textBuf << bsTagName; | 114 textBuf << bsTagName; |
| 115 m_SAXContext.m_bsTagName = bsTagName; | 115 m_SAXContext.m_bsTagName = bsTagName; |
| 116 return &m_SAXContext; | 116 return &m_SAXContext; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 235 |
| 236 CXFA_SAXReaderHandler handler(this); | 236 CXFA_SAXReaderHandler handler(this); |
| 237 m_pSAXReader->SetHandler(&handler); | 237 m_pSAXReader->SetHandler(&handler); |
| 238 if (m_pSAXReader->StartParse( | 238 if (m_pSAXReader->StartParse( |
| 239 pSrcFile, (uint32_t)offset, (uint32_t)size, | 239 pSrcFile, (uint32_t)offset, (uint32_t)size, |
| 240 CFX_SaxParseMode_NotSkipSpace | CFX_SaxParseMode_NotConvert_amp | | 240 CFX_SaxParseMode_NotSkipSpace | CFX_SaxParseMode_NotConvert_amp | |
| 241 CFX_SaxParseMode_NotConvert_lt | CFX_SaxParseMode_NotConvert_gt | | 241 CFX_SaxParseMode_NotConvert_lt | CFX_SaxParseMode_NotConvert_gt | |
| 242 CFX_SaxParseMode_NotConvert_sharp) < 0) { | 242 CFX_SaxParseMode_NotConvert_sharp) < 0) { |
| 243 return FALSE; | 243 return FALSE; |
| 244 } | 244 } |
| 245 return m_pSAXReader->ContinueParse(NULL) > 99; | 245 return m_pSAXReader->ContinueParse(nullptr) > 99; |
| 246 } | 246 } |
| 247 | 247 |
| 248 void CXFA_ChecksumContext::FinishChecksum() { | 248 void CXFA_ChecksumContext::FinishChecksum() { |
| 249 delete m_pSAXReader; | 249 delete m_pSAXReader; |
| 250 m_pSAXReader = nullptr; | 250 m_pSAXReader = nullptr; |
| 251 if (m_pByteContext) { | 251 if (m_pByteContext) { |
| 252 uint8_t digest[20]; | 252 uint8_t digest[20]; |
| 253 FXSYS_memset(digest, 0, 20); | 253 FXSYS_memset(digest, 0, 20); |
| 254 CRYPT_SHA1Finish(m_pByteContext, digest); | 254 CRYPT_SHA1Finish(m_pByteContext, digest); |
| 255 int32_t nLen = Base64EncodeA(digest, 20, NULL); | 255 int32_t nLen = Base64EncodeA(digest, 20, nullptr); |
| 256 FX_CHAR* pBuffer = m_bsChecksum.GetBuffer(nLen); | 256 FX_CHAR* pBuffer = m_bsChecksum.GetBuffer(nLen); |
| 257 Base64EncodeA(digest, 20, pBuffer); | 257 Base64EncodeA(digest, 20, pBuffer); |
| 258 m_bsChecksum.ReleaseBuffer(nLen); | 258 m_bsChecksum.ReleaseBuffer(nLen); |
| 259 FX_Free(m_pByteContext); | 259 FX_Free(m_pByteContext); |
| 260 m_pByteContext = NULL; | 260 m_pByteContext = nullptr; |
| 261 } | 261 } |
| 262 } | 262 } |
| 263 | 263 |
| 264 CFX_ByteString CXFA_ChecksumContext::GetChecksum() const { | 264 CFX_ByteString CXFA_ChecksumContext::GetChecksum() const { |
| 265 return m_bsChecksum; | 265 return m_bsChecksum; |
| 266 } | 266 } |
| 267 | 267 |
| 268 void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) { | 268 void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) { |
| 269 if (m_pByteContext) { | 269 if (m_pByteContext) { |
| 270 CRYPT_SHA1Update(m_pByteContext, bsText.raw_str(), bsText.GetLength()); | 270 CRYPT_SHA1Update(m_pByteContext, bsText.raw_str(), bsText.GetLength()); |
| 271 } | 271 } |
| 272 } | 272 } |
| OLD | NEW |