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

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
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 }
134
133 FX_BOOL CXFA_ChecksumContext::StartChecksum() { 135 FX_BOOL 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; 141 return TRUE;
Lei Zhang 2016/04/27 19:23:50 Always returns true -> return void?
dsinclair 2016/04/27 19:31:32 Done.
140 } 142 }
143
141 FX_BOOL CXFA_ChecksumContext::UpdateChecksum(IFX_FileRead* pSrcFile, 144 FX_BOOL CXFA_ChecksumContext::UpdateChecksum(IFX_FileRead* pSrcFile,
142 FX_FILESIZE offset, 145 FX_FILESIZE offset,
143 size_t size) { 146 size_t size) {
144 if (m_pSAXReader == NULL) { 147 if (!m_pSAXReader || !pSrcFile)
145 return FALSE; 148 return FALSE;
146 } 149 if (size < 1)
147 if (pSrcFile == NULL) {
148 return FALSE;
149 }
150 if (size < 1) {
151 size = pSrcFile->GetSize(); 150 size = pSrcFile->GetSize();
152 } 151
153 CXFA_SAXReaderHandler handler(this); 152 CXFA_SAXReaderHandler handler(this);
154 m_pSAXReader->SetHandler(&handler); 153 m_pSAXReader->SetHandler(&handler);
155 if (m_pSAXReader->StartParse( 154 if (m_pSAXReader->StartParse(
156 pSrcFile, (uint32_t)offset, (uint32_t)size, 155 pSrcFile, (uint32_t)offset, (uint32_t)size,
157 FX_SAXPARSEMODE_NotSkipSpace | FX_SAXPARSEMODE_NotConvert_amp | 156 FX_SAXPARSEMODE_NotSkipSpace | FX_SAXPARSEMODE_NotConvert_amp |
158 FX_SAXPARSEMODE_NotConvert_lt | FX_SAXPARSEMODE_NotConvert_gt | 157 FX_SAXPARSEMODE_NotConvert_lt | FX_SAXPARSEMODE_NotConvert_gt |
159 FX_SAXPARSEMODE_NotConvert_sharp) < 0) { 158 FX_SAXPARSEMODE_NotConvert_sharp) < 0) {
160 return FALSE; 159 return FALSE;
161 } 160 }
162 return m_pSAXReader->ContinueParse(NULL) > 99; 161 return m_pSAXReader->ContinueParse(NULL) > 99;
163 } 162 }
163
164 void CXFA_ChecksumContext::FinishChecksum() { 164 void CXFA_ChecksumContext::FinishChecksum() {
165 if (m_pSAXReader) { 165 if (m_pSAXReader) {
166 m_pSAXReader->Release(); 166 m_pSAXReader->Release();
167 m_pSAXReader = NULL; 167 m_pSAXReader = NULL;
168 } 168 }
169 if (m_pByteContext) { 169 if (m_pByteContext) {
170 uint8_t digest[20]; 170 uint8_t digest[20];
171 FXSYS_memset(digest, 0, 20); 171 FXSYS_memset(digest, 0, 20);
172 CRYPT_SHA1Finish(m_pByteContext, digest); 172 CRYPT_SHA1Finish(m_pByteContext, digest);
173 int32_t nLen = FX_Base64EncodeA(digest, 20, NULL); 173 int32_t nLen = FX_Base64EncodeA(digest, 20, NULL);
174 FX_CHAR* pBuffer = m_bsChecksum.GetBuffer(nLen); 174 FX_CHAR* pBuffer = m_bsChecksum.GetBuffer(nLen);
175 FX_Base64EncodeA(digest, 20, pBuffer); 175 FX_Base64EncodeA(digest, 20, pBuffer);
176 m_bsChecksum.ReleaseBuffer(nLen); 176 m_bsChecksum.ReleaseBuffer(nLen);
177 FX_Free(m_pByteContext); 177 FX_Free(m_pByteContext);
178 m_pByteContext = NULL; 178 m_pByteContext = NULL;
179 } 179 }
180 } 180 }
181 void CXFA_ChecksumContext::GetChecksum(CFX_ByteString& bsChecksum) { 181 void CXFA_ChecksumContext::GetChecksum(CFX_ByteString& bsChecksum) {
182 bsChecksum = m_bsChecksum; 182 bsChecksum = m_bsChecksum;
183 } 183 }
184 void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) { 184 void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) {
185 if (m_pByteContext) { 185 if (m_pByteContext) {
186 CRYPT_SHA1Update(m_pByteContext, bsText.raw_str(), bsText.GetLength()); 186 CRYPT_SHA1Update(m_pByteContext, bsText.raw_str(), bsText.GetLength());
187 } 187 }
188 } 188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698