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

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

Issue 1992033002: fgas/ code cleanup. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master 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
11 namespace {
12
13 struct FX_BASE64DATA {
14 uint32_t data1 : 2;
15 uint32_t data2 : 6;
16 uint32_t data3 : 4;
17 uint32_t data4 : 4;
18 uint32_t data5 : 6;
19 uint32_t data6 : 2;
20 uint32_t data7 : 8;
21 };
22
23 const FX_CHAR g_FXBase64EncoderMap[64] = {
24 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
25 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
26 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
27 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
28 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/',
29 };
30
31 void Base64EncodePiece(const FX_BASE64DATA& src,
32 int32_t iBytes,
33 FX_CHAR dst[4]) {
34 dst[0] = g_FXBase64EncoderMap[src.data2];
35 uint32_t b = src.data1 << 4;
36 if (iBytes > 1) {
37 b |= src.data4;
38 }
39 dst[1] = g_FXBase64EncoderMap[b];
40 if (iBytes > 1) {
41 b = src.data3 << 2;
42 if (iBytes > 2) {
43 b |= src.data6;
44 }
45 dst[2] = g_FXBase64EncoderMap[b];
46 if (iBytes > 2) {
47 dst[3] = g_FXBase64EncoderMap[src.data5];
48 } else {
49 dst[3] = '=';
50 }
51 } else {
52 dst[2] = dst[3] = '=';
53 }
54 }
55
56 int32_t Base64EncodeA(const uint8_t* pSrc, int32_t iSrcLen, FX_CHAR* pDst) {
57 ASSERT(pSrc != NULL);
58 if (iSrcLen < 1) {
59 return 0;
60 }
61 if (pDst == NULL) {
62 int32_t iDstLen = iSrcLen / 3 * 4;
63 if ((iSrcLen % 3) != 0) {
64 iDstLen += 4;
65 }
66 return iDstLen;
67 }
68 FX_BASE64DATA srcData;
69 int32_t iBytes = 3;
70 FX_CHAR* pDstEnd = pDst;
71 while (iSrcLen > 0) {
72 if (iSrcLen > 2) {
73 ((uint8_t*)&srcData)[0] = *pSrc++;
74 ((uint8_t*)&srcData)[1] = *pSrc++;
75 ((uint8_t*)&srcData)[2] = *pSrc++;
76 iSrcLen -= 3;
77 } else {
78 *((uint32_t*)&srcData) = 0;
79 ((uint8_t*)&srcData)[0] = *pSrc++;
80 if (iSrcLen > 1) {
81 ((uint8_t*)&srcData)[1] = *pSrc++;
82 }
83 iBytes = iSrcLen;
84 iSrcLen = 0;
85 }
86 Base64EncodePiece(srcData, iBytes, pDstEnd);
87 pDstEnd += 4;
88 }
89 return pDstEnd - pDst;
90 }
91
92 } // namespace
11 93
12 CXFA_SAXReaderHandler::CXFA_SAXReaderHandler(CXFA_ChecksumContext* pContext) 94 CXFA_SAXReaderHandler::CXFA_SAXReaderHandler(CXFA_ChecksumContext* pContext)
13 : m_pContext(pContext) { 95 : m_pContext(pContext) {
14 ASSERT(m_pContext); 96 ASSERT(m_pContext);
15 } 97 }
16 CXFA_SAXReaderHandler::~CXFA_SAXReaderHandler() {} 98 CXFA_SAXReaderHandler::~CXFA_SAXReaderHandler() {}
17 void* CXFA_SAXReaderHandler::OnTagEnter(const CFX_ByteStringC& bsTagName, 99 void* CXFA_SAXReaderHandler::OnTagEnter(const CFX_ByteStringC& bsTagName,
18 FX_SAXNODE eType, 100 FX_SAXNODE eType,
19 uint32_t dwStartPos) { 101 uint32_t dwStartPos) {
20 UpdateChecksum(TRUE); 102 UpdateChecksum(TRUE);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 return m_pSAXReader->ContinueParse(NULL) > 99; 242 return m_pSAXReader->ContinueParse(NULL) > 99;
161 } 243 }
162 244
163 void CXFA_ChecksumContext::FinishChecksum() { 245 void CXFA_ChecksumContext::FinishChecksum() {
164 delete m_pSAXReader; 246 delete m_pSAXReader;
165 m_pSAXReader = nullptr; 247 m_pSAXReader = nullptr;
166 if (m_pByteContext) { 248 if (m_pByteContext) {
167 uint8_t digest[20]; 249 uint8_t digest[20];
168 FXSYS_memset(digest, 0, 20); 250 FXSYS_memset(digest, 0, 20);
169 CRYPT_SHA1Finish(m_pByteContext, digest); 251 CRYPT_SHA1Finish(m_pByteContext, digest);
170 int32_t nLen = FX_Base64EncodeA(digest, 20, NULL); 252 int32_t nLen = Base64EncodeA(digest, 20, NULL);
171 FX_CHAR* pBuffer = m_bsChecksum.GetBuffer(nLen); 253 FX_CHAR* pBuffer = m_bsChecksum.GetBuffer(nLen);
172 FX_Base64EncodeA(digest, 20, pBuffer); 254 Base64EncodeA(digest, 20, pBuffer);
173 m_bsChecksum.ReleaseBuffer(nLen); 255 m_bsChecksum.ReleaseBuffer(nLen);
174 FX_Free(m_pByteContext); 256 FX_Free(m_pByteContext);
175 m_pByteContext = NULL; 257 m_pByteContext = NULL;
176 } 258 }
177 } 259 }
178 260
179 CFX_ByteString CXFA_ChecksumContext::GetChecksum() const { 261 CFX_ByteString CXFA_ChecksumContext::GetChecksum() const {
180 return m_bsChecksum; 262 return m_bsChecksum;
181 } 263 }
182 264
183 void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) { 265 void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) {
184 if (m_pByteContext) { 266 if (m_pByteContext) {
185 CRYPT_SHA1Update(m_pByteContext, bsText.raw_str(), bsText.GetLength()); 267 CRYPT_SHA1Update(m_pByteContext, bsText.raw_str(), bsText.GetLength());
186 } 268 }
187 } 269 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698