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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | xfa/fxfa/xfa_checksum.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: xfa/fxfa/app/xfa_checksum.cpp
diff --git a/xfa/fxfa/app/xfa_checksum.cpp b/xfa/fxfa/app/xfa_checksum.cpp
index 641ec7880e12fb782d8e33e70a56ad8b81fb18fd..09c42719c11e0f8a3175eca65b636516d1496ec9 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());
}
« 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