1 // Copyright 2017 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "core/fpdfapi/edit/cpdf_encryptor.h"
8 #include "core/fpdfapi/parser/cpdf_crypto_handler.h"
9
CPDF_Encryptor(CPDF_CryptoHandler * pHandler,int objnum,uint8_t * src_data,uint32_t src_size)10 CPDF_Encryptor::CPDF_Encryptor(CPDF_CryptoHandler* pHandler,
11 int objnum,
12 uint8_t* src_data,
13 uint32_t src_size)
14 : m_pData(nullptr), m_dwSize(0), m_bNewBuf(false) {
15 if (src_size == 0)
16 return;
17
18 if (!pHandler) {
19 m_pData = (uint8_t*)src_data;
20 m_dwSize = src_size;
21 return;
22 }
23 m_dwSize = pHandler->EncryptGetSize(objnum, 0, src_data, src_size);
24 m_pData = FX_Alloc(uint8_t, m_dwSize);
25 pHandler->EncryptContent(objnum, 0, src_data, src_size, m_pData, m_dwSize);
26 m_bNewBuf = true;
27 }
28
~CPDF_Encryptor()29 CPDF_Encryptor::~CPDF_Encryptor() {
30 if (m_bNewBuf)
31 FX_Free(m_pData);
32 }
33