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

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

Issue 2613143002: use unique_ptr in xfa_checksum.h (Closed)
Patch Set: rebase Created 3 years, 11 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 | « no previous file | xfa/fxfa/xfa_checksum.h » ('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/xfa_checksum.h" 7 #include "xfa/fxfa/xfa_checksum.h"
8 8
9 #include "core/fdrm/crypto/fx_crypt.h" 9 #include "core/fdrm/crypto/fx_crypt.h"
10 #include "third_party/base/ptr_util.h"
10 11
11 namespace { 12 namespace {
12 13
13 struct FX_BASE64DATA { 14 struct FX_BASE64DATA {
14 uint32_t data1 : 2; 15 uint32_t data1 : 2;
15 uint32_t data2 : 6; 16 uint32_t data2 : 6;
16 uint32_t data3 : 4; 17 uint32_t data3 : 4;
17 uint32_t data4 : 4; 18 uint32_t data4 : 4;
18 uint32_t data5 : 6; 19 uint32_t data5 : 6;
19 uint32_t data6 : 2; 20 uint32_t data6 : 2;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 break; 204 break;
204 } 205 }
205 } 206 }
206 } 207 }
207 if (bUpdata) { 208 if (bUpdata) {
208 m_pContext->Update(CFX_ByteStringC(pBuffer, iLength)); 209 m_pContext->Update(CFX_ByteStringC(pBuffer, iLength));
209 } 210 }
210 m_SAXContext.m_TextBuf.Clear(); 211 m_SAXContext.m_TextBuf.Clear();
211 } 212 }
212 213
213 CXFA_ChecksumContext::CXFA_ChecksumContext() 214 CXFA_ChecksumContext::CXFA_ChecksumContext() {}
214 : m_pSAXReader(nullptr), m_pByteContext(nullptr) {}
215 215
216 CXFA_ChecksumContext::~CXFA_ChecksumContext() { 216 CXFA_ChecksumContext::~CXFA_ChecksumContext() {}
217 FinishChecksum();
218 }
219 217
220 void CXFA_ChecksumContext::StartChecksum() { 218 void CXFA_ChecksumContext::StartChecksum() {
221 FinishChecksum(); 219 FinishChecksum();
222 m_pByteContext = FX_Alloc(CRYPT_sha1_context, 1); 220 m_pByteContext = pdfium::MakeUnique<CRYPT_sha1_context>();
223 CRYPT_SHA1Start(m_pByteContext); 221 CRYPT_SHA1Start(m_pByteContext.get());
224 m_bsChecksum.clear(); 222 m_bsChecksum.clear();
225 m_pSAXReader = new CFX_SAXReader; 223 m_pSAXReader = pdfium::MakeUnique<CFX_SAXReader>();
226 } 224 }
227 225
228 bool CXFA_ChecksumContext::UpdateChecksum( 226 bool CXFA_ChecksumContext::UpdateChecksum(
229 const CFX_RetainPtr<IFX_SeekableReadStream>& pSrcFile, 227 const CFX_RetainPtr<IFX_SeekableReadStream>& pSrcFile,
230 FX_FILESIZE offset, 228 FX_FILESIZE offset,
231 size_t size) { 229 size_t size) {
232 if (!m_pSAXReader || !pSrcFile) 230 if (!m_pSAXReader || !pSrcFile)
233 return false; 231 return false;
234 232
235 if (size < 1) 233 if (size < 1)
236 size = pSrcFile->GetSize(); 234 size = pSrcFile->GetSize();
237 235
238 CXFA_SAXReaderHandler handler(this); 236 CXFA_SAXReaderHandler handler(this);
239 m_pSAXReader->SetHandler(&handler); 237 m_pSAXReader->SetHandler(&handler);
240 if (m_pSAXReader->StartParse( 238 if (m_pSAXReader->StartParse(
241 pSrcFile, (uint32_t)offset, (uint32_t)size, 239 pSrcFile, (uint32_t)offset, (uint32_t)size,
242 CFX_SaxParseMode_NotSkipSpace | CFX_SaxParseMode_NotConvert_amp | 240 CFX_SaxParseMode_NotSkipSpace | CFX_SaxParseMode_NotConvert_amp |
243 CFX_SaxParseMode_NotConvert_lt | CFX_SaxParseMode_NotConvert_gt | 241 CFX_SaxParseMode_NotConvert_lt | CFX_SaxParseMode_NotConvert_gt |
244 CFX_SaxParseMode_NotConvert_sharp) < 0) { 242 CFX_SaxParseMode_NotConvert_sharp) < 0) {
245 return false; 243 return false;
246 } 244 }
247 return m_pSAXReader->ContinueParse(nullptr) > 99; 245 return m_pSAXReader->ContinueParse(nullptr) > 99;
248 } 246 }
249 247
250 void CXFA_ChecksumContext::FinishChecksum() { 248 void CXFA_ChecksumContext::FinishChecksum() {
251 delete m_pSAXReader; 249 m_pSAXReader.reset();
252 m_pSAXReader = nullptr;
253 if (m_pByteContext) { 250 if (m_pByteContext) {
254 uint8_t digest[20]; 251 uint8_t digest[20];
255 FXSYS_memset(digest, 0, 20); 252 FXSYS_memset(digest, 0, 20);
256 CRYPT_SHA1Finish(m_pByteContext, digest); 253 CRYPT_SHA1Finish(m_pByteContext.get(), digest);
257 int32_t nLen = Base64EncodeA(digest, 20, nullptr); 254 int32_t nLen = Base64EncodeA(digest, 20, nullptr);
258 FX_CHAR* pBuffer = m_bsChecksum.GetBuffer(nLen); 255 FX_CHAR* pBuffer = m_bsChecksum.GetBuffer(nLen);
259 Base64EncodeA(digest, 20, pBuffer); 256 Base64EncodeA(digest, 20, pBuffer);
260 m_bsChecksum.ReleaseBuffer(nLen); 257 m_bsChecksum.ReleaseBuffer(nLen);
261 FX_Free(m_pByteContext); 258 m_pByteContext.reset();
262 m_pByteContext = nullptr;
263 } 259 }
264 } 260 }
265 261
266 CFX_ByteString CXFA_ChecksumContext::GetChecksum() const { 262 CFX_ByteString CXFA_ChecksumContext::GetChecksum() const {
267 return m_bsChecksum; 263 return m_bsChecksum;
268 } 264 }
269 265
270 void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) { 266 void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) {
271 if (m_pByteContext) { 267 if (!m_pByteContext)
272 CRYPT_SHA1Update(m_pByteContext, bsText.raw_str(), bsText.GetLength()); 268 return;
273 } 269
270 CRYPT_SHA1Update(m_pByteContext.get(), bsText.raw_str(), bsText.GetLength());
274 } 271 }
OLDNEW
« no previous file with comments | « no previous file | xfa/fxfa/xfa_checksum.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698