summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2017-01-18 14:30:36 -0800
committerCommit bot <commit-bot@chromium.org>2017-01-18 14:30:36 -0800
commit85c532b35b53836bebfdb8f8832905d5f313cf47 (patch)
tree0b541a077feaa50eada829077d9144d621481626
parente507dc5004184ae3f8fd1cd19b723b4be69a46da (diff)
downloadpdfium-85c532b35b53836bebfdb8f8832905d5f313cf47.tar.xz
use unique_ptr in xfa_checksum.h
Review-Url: https://codereview.chromium.org/2613143002
-rw-r--r--xfa/fxfa/app/xfa_checksum.cpp29
-rw-r--r--xfa/fxfa/xfa_checksum.h6
2 files changed, 17 insertions, 18 deletions
diff --git a/xfa/fxfa/app/xfa_checksum.cpp b/xfa/fxfa/app/xfa_checksum.cpp
index 641ec7880e..09c42719c1 100644
--- a/xfa/fxfa/app/xfa_checksum.cpp
+++ b/xfa/fxfa/app/xfa_checksum.cpp
@@ -7,6 +7,7 @@
#include "xfa/fxfa/xfa_checksum.h"
#include "core/fdrm/crypto/fx_crypt.h"
+#include "third_party/base/ptr_util.h"
namespace {
@@ -210,19 +211,16 @@ void CXFA_SAXReaderHandler::UpdateChecksum(bool bCheckSpace) {
m_SAXContext.m_TextBuf.Clear();
}
-CXFA_ChecksumContext::CXFA_ChecksumContext()
- : m_pSAXReader(nullptr), m_pByteContext(nullptr) {}
+CXFA_ChecksumContext::CXFA_ChecksumContext() {}
-CXFA_ChecksumContext::~CXFA_ChecksumContext() {
- FinishChecksum();
-}
+CXFA_ChecksumContext::~CXFA_ChecksumContext() {}
void CXFA_ChecksumContext::StartChecksum() {
FinishChecksum();
- m_pByteContext = FX_Alloc(CRYPT_sha1_context, 1);
- CRYPT_SHA1Start(m_pByteContext);
+ m_pByteContext = pdfium::MakeUnique<CRYPT_sha1_context>();
+ CRYPT_SHA1Start(m_pByteContext.get());
m_bsChecksum.clear();
- m_pSAXReader = new CFX_SAXReader;
+ m_pSAXReader = pdfium::MakeUnique<CFX_SAXReader>();
}
bool CXFA_ChecksumContext::UpdateChecksum(
@@ -248,18 +246,16 @@ bool CXFA_ChecksumContext::UpdateChecksum(
}
void CXFA_ChecksumContext::FinishChecksum() {
- delete m_pSAXReader;
- m_pSAXReader = nullptr;
+ m_pSAXReader.reset();
if (m_pByteContext) {
uint8_t digest[20];
FXSYS_memset(digest, 0, 20);
- CRYPT_SHA1Finish(m_pByteContext, digest);
+ CRYPT_SHA1Finish(m_pByteContext.get(), digest);
int32_t nLen = Base64EncodeA(digest, 20, nullptr);
FX_CHAR* pBuffer = m_bsChecksum.GetBuffer(nLen);
Base64EncodeA(digest, 20, pBuffer);
m_bsChecksum.ReleaseBuffer(nLen);
- FX_Free(m_pByteContext);
- m_pByteContext = nullptr;
+ m_pByteContext.reset();
}
}
@@ -268,7 +264,8 @@ CFX_ByteString CXFA_ChecksumContext::GetChecksum() const {
}
void CXFA_ChecksumContext::Update(const CFX_ByteStringC& bsText) {
- if (m_pByteContext) {
- CRYPT_SHA1Update(m_pByteContext, bsText.raw_str(), bsText.GetLength());
- }
+ if (!m_pByteContext)
+ return;
+
+ CRYPT_SHA1Update(m_pByteContext.get(), bsText.raw_str(), bsText.GetLength());
}
diff --git a/xfa/fxfa/xfa_checksum.h b/xfa/fxfa/xfa_checksum.h
index 45c3db59c9..31cf101553 100644
--- a/xfa/fxfa/xfa_checksum.h
+++ b/xfa/fxfa/xfa_checksum.h
@@ -7,6 +7,8 @@
#ifndef XFA_FXFA_XFA_CHECKSUM_H_
#define XFA_FXFA_XFA_CHECKSUM_H_
+#include <memory>
+
#include "core/fdrm/crypto/fx_crypt.h"
#include "xfa/fde/xml/cfx_saxreader.h"
#include "xfa/fxfa/fxfa.h"
@@ -70,8 +72,8 @@ class CXFA_ChecksumContext {
CFX_ByteString GetChecksum() const;
protected:
- CFX_SAXReader* m_pSAXReader;
- CRYPT_sha1_context* m_pByteContext;
+ std::unique_ptr<CFX_SAXReader> m_pSAXReader;
+ std::unique_ptr<CRYPT_sha1_context> m_pByteContext;
CFX_ByteString m_bsChecksum;
};