summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/edit/cpdf_encryptor.cpp17
-rw-r--r--core/fpdfapi/edit/cpdf_encryptor.h12
2 files changed, 15 insertions, 14 deletions
diff --git a/core/fpdfapi/edit/cpdf_encryptor.cpp b/core/fpdfapi/edit/cpdf_encryptor.cpp
index 45be9f8447..033df38a48 100644
--- a/core/fpdfapi/edit/cpdf_encryptor.cpp
+++ b/core/fpdfapi/edit/cpdf_encryptor.cpp
@@ -10,23 +10,20 @@
CPDF_Encryptor::CPDF_Encryptor(CPDF_CryptoHandler* pHandler,
int objnum,
const uint8_t* src_data,
- uint32_t src_size)
- : m_pData(nullptr), m_dwSize(0), m_bNewBuf(false) {
+ uint32_t src_size) {
if (src_size == 0)
return;
if (!pHandler) {
- m_pData = (uint8_t*)src_data;
+ m_pData = src_data;
m_dwSize = src_size;
return;
}
m_dwSize = pHandler->EncryptGetSize(objnum, 0, src_data, src_size);
- m_pData = FX_Alloc(uint8_t, m_dwSize);
- pHandler->EncryptContent(objnum, 0, src_data, src_size, m_pData, m_dwSize);
- m_bNewBuf = true;
+ m_pNewBuf.reset(FX_Alloc(uint8_t, m_dwSize));
+ pHandler->EncryptContent(objnum, 0, src_data, src_size, m_pNewBuf.get(),
+ m_dwSize);
+ m_pData = m_pNewBuf.get();
}
-CPDF_Encryptor::~CPDF_Encryptor() {
- if (m_bNewBuf)
- FX_Free(m_pData);
-}
+CPDF_Encryptor::~CPDF_Encryptor() {}
diff --git a/core/fpdfapi/edit/cpdf_encryptor.h b/core/fpdfapi/edit/cpdf_encryptor.h
index 1da601d491..a62a4ebf22 100644
--- a/core/fpdfapi/edit/cpdf_encryptor.h
+++ b/core/fpdfapi/edit/cpdf_encryptor.h
@@ -9,6 +9,10 @@
#include <stdint.h>
+#include <memory>
+
+#include "core/fxcrt/fx_memory.h"
+
class CPDF_CryptoHandler;
class CPDF_Encryptor {
@@ -20,12 +24,12 @@ class CPDF_Encryptor {
~CPDF_Encryptor();
uint32_t GetSize() const { return m_dwSize; }
- uint8_t* GetData() const { return m_pData; }
+ const uint8_t* GetData() const { return m_pData; }
private:
- uint8_t* m_pData;
- uint32_t m_dwSize;
- bool m_bNewBuf;
+ const uint8_t* m_pData = nullptr;
+ std::unique_ptr<uint8_t, FxFreeDeleter> m_pNewBuf;
+ uint32_t m_dwSize = 0;
};
#endif // CORE_FPDFAPI_EDIT_CPDF_ENCRYPTOR_H_