summaryrefslogtreecommitdiff
path: root/xfa/fxfa/app/xfa_checksum.cpp
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-05-19 18:07:11 -0700
committerCommit bot <commit-bot@chromium.org>2016-05-19 18:07:11 -0700
commitfc2cdf8657534467fd807e216d50650b0e959868 (patch)
treea0642ba14ee4e438e97957825772e8dd16e347a2 /xfa/fxfa/app/xfa_checksum.cpp
parent411f1185f44b7862a9b1c16e588407ae197752dd (diff)
downloadpdfium-fc2cdf8657534467fd807e216d50650b0e959868.tar.xz
fgas/ code cleanup.
This CL shuffles code around in the fgas/ headers, removes unused functions and adds anonymous namepaces for static methods and data. Review-Url: https://codereview.chromium.org/1992033002
Diffstat (limited to 'xfa/fxfa/app/xfa_checksum.cpp')
-rw-r--r--xfa/fxfa/app/xfa_checksum.cpp88
1 files changed, 85 insertions, 3 deletions
diff --git a/xfa/fxfa/app/xfa_checksum.cpp b/xfa/fxfa/app/xfa_checksum.cpp
index fab14c9b17..b5d9fdeb7d 100644
--- a/xfa/fxfa/app/xfa_checksum.cpp
+++ b/xfa/fxfa/app/xfa_checksum.cpp
@@ -7,7 +7,89 @@
#include "xfa/fxfa/include/xfa_checksum.h"
#include "core/fdrm/crypto/include/fx_crypt.h"
-#include "xfa/fgas/crt/fgas_algorithm.h"
+
+namespace {
+
+struct FX_BASE64DATA {
+ uint32_t data1 : 2;
+ uint32_t data2 : 6;
+ uint32_t data3 : 4;
+ uint32_t data4 : 4;
+ uint32_t data5 : 6;
+ uint32_t data6 : 2;
+ uint32_t data7 : 8;
+};
+
+const FX_CHAR g_FXBase64EncoderMap[64] = {
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
+ 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
+ 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/',
+};
+
+void Base64EncodePiece(const FX_BASE64DATA& src,
+ int32_t iBytes,
+ FX_CHAR dst[4]) {
+ dst[0] = g_FXBase64EncoderMap[src.data2];
+ uint32_t b = src.data1 << 4;
+ if (iBytes > 1) {
+ b |= src.data4;
+ }
+ dst[1] = g_FXBase64EncoderMap[b];
+ if (iBytes > 1) {
+ b = src.data3 << 2;
+ if (iBytes > 2) {
+ b |= src.data6;
+ }
+ dst[2] = g_FXBase64EncoderMap[b];
+ if (iBytes > 2) {
+ dst[3] = g_FXBase64EncoderMap[src.data5];
+ } else {
+ dst[3] = '=';
+ }
+ } else {
+ dst[2] = dst[3] = '=';
+ }
+}
+
+int32_t Base64EncodeA(const uint8_t* pSrc, int32_t iSrcLen, FX_CHAR* pDst) {
+ ASSERT(pSrc != NULL);
+ if (iSrcLen < 1) {
+ return 0;
+ }
+ if (pDst == NULL) {
+ int32_t iDstLen = iSrcLen / 3 * 4;
+ if ((iSrcLen % 3) != 0) {
+ iDstLen += 4;
+ }
+ return iDstLen;
+ }
+ FX_BASE64DATA srcData;
+ int32_t iBytes = 3;
+ FX_CHAR* pDstEnd = pDst;
+ while (iSrcLen > 0) {
+ if (iSrcLen > 2) {
+ ((uint8_t*)&srcData)[0] = *pSrc++;
+ ((uint8_t*)&srcData)[1] = *pSrc++;
+ ((uint8_t*)&srcData)[2] = *pSrc++;
+ iSrcLen -= 3;
+ } else {
+ *((uint32_t*)&srcData) = 0;
+ ((uint8_t*)&srcData)[0] = *pSrc++;
+ if (iSrcLen > 1) {
+ ((uint8_t*)&srcData)[1] = *pSrc++;
+ }
+ iBytes = iSrcLen;
+ iSrcLen = 0;
+ }
+ Base64EncodePiece(srcData, iBytes, pDstEnd);
+ pDstEnd += 4;
+ }
+ return pDstEnd - pDst;
+}
+
+} // namespace
CXFA_SAXReaderHandler::CXFA_SAXReaderHandler(CXFA_ChecksumContext* pContext)
: m_pContext(pContext) {
@@ -167,9 +249,9 @@ void CXFA_ChecksumContext::FinishChecksum() {
uint8_t digest[20];
FXSYS_memset(digest, 0, 20);
CRYPT_SHA1Finish(m_pByteContext, digest);
- int32_t nLen = FX_Base64EncodeA(digest, 20, NULL);
+ int32_t nLen = Base64EncodeA(digest, 20, NULL);
FX_CHAR* pBuffer = m_bsChecksum.GetBuffer(nLen);
- FX_Base64EncodeA(digest, 20, pBuffer);
+ Base64EncodeA(digest, 20, pBuffer);
m_bsChecksum.ReleaseBuffer(nLen);
FX_Free(m_pByteContext);
m_pByteContext = NULL;