Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(374)

Side by Side Diff: xfa/fxfa/app/xfa_checksum.cpp

Issue 1930533002: More IFX_ interface cleanup. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fwl/theme/cfwl_widgettp.cpp ('k') | xfa/fxfa/app/xfa_ffapp.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "xfa/fgas/crt/fgas_algorithm.h" 10 #include "xfa/fgas/crt/fgas_algorithm.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } 119 }
120 } 120 }
121 } 121 }
122 if (bUpdata) { 122 if (bUpdata) {
123 m_pContext->Update(CFX_ByteStringC(pBuffer, iLength)); 123 m_pContext->Update(CFX_ByteStringC(pBuffer, iLength));
124 } 124 }
125 m_SAXContext.m_TextBuf.Clear(); 125 m_SAXContext.m_TextBuf.Clear();
126 } 126 }
127 127
128 CXFA_ChecksumContext::CXFA_ChecksumContext() 128 CXFA_ChecksumContext::CXFA_ChecksumContext()
129 : m_pSAXReader(NULL), m_pByteContext(NULL) {} 129 : m_pSAXReader(nullptr), m_pByteContext(nullptr) {}
130
130 CXFA_ChecksumContext::~CXFA_ChecksumContext() { 131 CXFA_ChecksumContext::~CXFA_ChecksumContext() {
131 FinishChecksum(); 132 FinishChecksum();
132 } 133 }
133 FX_BOOL CXFA_ChecksumContext::StartChecksum() { 134
135 void CXFA_ChecksumContext::StartChecksum() {
134 FinishChecksum(); 136 FinishChecksum();
135 m_pByteContext = FX_Alloc(uint8_t, 128); 137 m_pByteContext = FX_Alloc(uint8_t, 128);
136 CRYPT_SHA1Start(m_pByteContext); 138 CRYPT_SHA1Start(m_pByteContext);
137 m_bsChecksum.clear(); 139 m_bsChecksum.clear();
138 m_pSAXReader = FX_SAXReader_Create(); 140 m_pSAXReader = new CFX_SAXReader;
139 return m_pSAXReader != NULL;
140 } 141 }
142
141 FX_BOOL CXFA_ChecksumContext::UpdateChecksum(IFX_FileRead* pSrcFile, 143 FX_BOOL CXFA_ChecksumContext::UpdateChecksum(IFX_FileRead* pSrcFile,
142 FX_FILESIZE offset, 144 FX_FILESIZE offset,
143 size_t size) { 145 size_t size) {
144 if (m_pSAXReader == NULL) { 146 if (!m_pSAXReader || !pSrcFile)
145 return FALSE; 147 return FALSE;
146 } 148 if (size < 1)
147 if (pSrcFile == NULL) {
148 return FALSE;
149 }
150 if (size < 1) {
151 size = pSrcFile->GetSize(); 149 size = pSrcFile->GetSize();
152 } 150
153 CXFA_SAXReaderHandler handler(this); 151 CXFA_SAXReaderHandler handler(this);
154 m_pSAXReader->SetHandler(&handler); 152 m_pSAXReader->SetHandler(&handler);
155 if (m_pSAXReader->StartParse( 153 if (m_pSAXReader->StartParse(
156 pSrcFile, (uint32_t)offset, (uint32_t)size, 154 pSrcFile, (uint32_t)offset, (uint32_t)size,
157 FX_SAXPARSEMODE_NotSkipSpace | FX_SAXPARSEMODE_NotConvert_amp | 155 FX_SAXPARSEMODE_NotSkipSpace | FX_SAXPARSEMODE_NotConvert_amp |
158 FX_SAXPARSEMODE_NotConvert_lt | FX_SAXPARSEMODE_NotConvert_gt | 156 FX_SAXPARSEMODE_NotConvert_lt | FX_SAXPARSEMODE_NotConvert_gt |
159 FX_SAXPARSEMODE_NotConvert_sharp) < 0) { 157 FX_SAXPARSEMODE_NotConvert_sharp) < 0) {
160 return FALSE; 158 return FALSE;
161 } 159 }
162 return m_pSAXReader->ContinueParse(NULL) > 99; 160 return m_pSAXReader->ContinueParse(NULL) > 99;
163 } 161 }
162
164 void CXFA_ChecksumContext::FinishChecksum() { 163 void CXFA_ChecksumContext::FinishChecksum() {
165 if (m_pSAXReader) { 164 if (m_pSAXReader) {
166 m_pSAXReader->Release(); 165 m_pSAXReader->Release();
167 m_pSAXReader = NULL; 166 m_pSAXReader = NULL;
168 } 167 }
169 if (m_pByteContext) { 168 if (m_pByteContext) {
170 uint8_t digest[20]; 169 uint8_t digest[20];
171 FXSYS_memset(digest, 0, 20); 170 FXSYS_memset(digest, 0, 20);
172 CRYPT_SHA1Finish(m_pByteContext, digest); 171 CRYPT_SHA1Finish(m_pByteContext, digest);
173 int32_t nLen = FX_Base64EncodeA(digest, 20, NULL); 172 int32_t nLen = FX_Base64EncodeA(digest, 20, NULL);
174 FX_CHAR* pBuffer = m_bsChecksum.GetBuffer(nLen); 173 FX_CHAR* pBuffer = m_bsChecksum.GetBuffer(nLen);
175 FX_Base64EncodeA(digest, 20, pBuffer); 174 FX_Base64EncodeA(digest, 20, pBuffer);
176 m_bsChecksum.ReleaseBuffer(nLen); 175 m_bsChecksum.ReleaseBuffer(nLen);
177 FX_Free(m_pByteContext); 176 FX_Free(m_pByteContext);
178 m_pByteContext = NULL; 177 m_pByteContext = NULL;
179 } 178 }
180 } 179 }
181 void CXFA_ChecksumContext::GetChecksum(CFX_ByteString& bsChecksum) { 180 void CXFA_ChecksumContext::GetChecksum(CFX_ByteString& bsChecksum) {
182 bsChecksum = m_bsChecksum; 181 bsChecksum = m_bsChecksum;
183 } 182 }
184 void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) { 183 void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) {
185 if (m_pByteContext) { 184 if (m_pByteContext) {
186 CRYPT_SHA1Update(m_pByteContext, bsText.raw_str(), bsText.GetLength()); 185 CRYPT_SHA1Update(m_pByteContext, bsText.raw_str(), bsText.GetLength());
187 } 186 }
188 } 187 }
OLDNEW
« no previous file with comments | « xfa/fwl/theme/cfwl_widgettp.cpp ('k') | xfa/fxfa/app/xfa_ffapp.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698