1 // Copyright 2017 The PDFium Authors 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/parser/cpdf_encryptor.h" 8 9 #include <stdint.h> 10 11 #include "core/fpdfapi/parser/cpdf_crypto_handler.h" 12 #include "core/fxcrt/data_vector.h" 13 #include "third_party/base/check.h" 14 CPDF_Encryptor(const CPDF_CryptoHandler * pHandler,int objnum)15CPDF_Encryptor::CPDF_Encryptor(const CPDF_CryptoHandler* pHandler, int objnum) 16 : m_pHandler(pHandler), m_ObjNum(objnum) { 17 DCHECK(m_pHandler); 18 } 19 Encrypt(pdfium::span<const uint8_t> src_data) const20DataVector<uint8_t> CPDF_Encryptor::Encrypt( 21 pdfium::span<const uint8_t> src_data) const { 22 if (src_data.empty()) 23 return DataVector<uint8_t>(); 24 25 DataVector<uint8_t> result; 26 size_t buf_size = m_pHandler->EncryptGetSize(src_data); 27 result.resize(buf_size); 28 m_pHandler->EncryptContent(m_ObjNum, 0, src_data, result.data(), 29 buf_size); // Updates |buf_size| with actual. 30 result.resize(buf_size); 31 return result; 32 } 33 34 CPDF_Encryptor::~CPDF_Encryptor() = default; 35