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/parser/cpdf_encryptor.h" 8 9 #include "core/fpdfapi/parser/cpdf_crypto_handler.h" 10 CPDF_Encryptor(CPDF_CryptoHandler * pHandler,int objnum)11CPDF_Encryptor::CPDF_Encryptor(CPDF_CryptoHandler* pHandler, int objnum) 12 : m_pHandler(pHandler), m_ObjNum(objnum) { 13 ASSERT(m_pHandler); 14 } 15 Encrypt(pdfium::span<const uint8_t> src_data) const16std::vector<uint8_t> CPDF_Encryptor::Encrypt( 17 pdfium::span<const uint8_t> src_data) const { 18 if (src_data.empty()) 19 return std::vector<uint8_t>(); 20 21 std::vector<uint8_t> result; 22 uint32_t buf_size = m_pHandler->EncryptGetSize(src_data); 23 result.resize(buf_size); 24 m_pHandler->EncryptContent(m_ObjNum, 0, src_data, result.data(), 25 buf_size); // Updates |buf_size| with actual. 26 result.resize(buf_size); 27 return result; 28 } 29 ~CPDF_Encryptor()30CPDF_Encryptor::~CPDF_Encryptor() {} 31