2016-10-13 10:37:02 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_XMLSECURITY_INC_PDFIO_PDFDOCUMENT_HXX
|
|
|
|
#define INCLUDED_XMLSECURITY_INC_PDFIO_PDFDOCUMENT_HXX
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2016-10-18 09:21:05 +02:00
|
|
|
#include <com/sun/star/security/XCertificate.hpp>
|
|
|
|
|
2016-10-13 10:37:02 +02:00
|
|
|
#include <tools/stream.hxx>
|
|
|
|
|
|
|
|
#include <xmlsecuritydllapi.h>
|
2016-10-13 21:07:55 +02:00
|
|
|
#include <sigstruct.hxx>
|
2016-10-13 10:37:02 +02:00
|
|
|
|
|
|
|
namespace xmlsecurity
|
|
|
|
{
|
|
|
|
namespace pdfio
|
|
|
|
{
|
|
|
|
|
|
|
|
class PDFTrailerElement;
|
|
|
|
class PDFObjectElement;
|
2016-10-14 15:38:57 +02:00
|
|
|
class PDFHexStringElement;
|
2016-10-13 10:37:02 +02:00
|
|
|
|
|
|
|
/// A byte range in a PDF file.
|
|
|
|
class PDFElement
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool Read(SvStream& rStream) = 0;
|
|
|
|
virtual ~PDFElement() { }
|
|
|
|
};
|
|
|
|
|
2016-10-25 11:33:21 +02:00
|
|
|
/**
|
|
|
|
* In-memory representation of an on-disk PDF document.
|
|
|
|
*
|
|
|
|
* The PDF element list is not meant to be saved back to disk, but some
|
|
|
|
* elements remember their source offset / length, and based on that it's
|
|
|
|
* possible to modify the input file.
|
|
|
|
*/
|
2016-10-13 10:37:02 +02:00
|
|
|
class XMLSECURITY_DLLPUBLIC PDFDocument
|
|
|
|
{
|
|
|
|
/// This vector owns all elements.
|
|
|
|
std::vector< std::unique_ptr<PDFElement> > m_aElements;
|
|
|
|
// List of object offsets we know.
|
|
|
|
std::vector<size_t> m_aXRef;
|
2016-10-21 14:33:36 +02:00
|
|
|
/// List of xref offsets we know.
|
|
|
|
std::vector<size_t> m_aStartXRefs;
|
2016-10-21 16:00:58 +02:00
|
|
|
/// List of EOF offsets we know.
|
|
|
|
std::vector<size_t> m_aEOFs;
|
2016-10-13 10:37:02 +02:00
|
|
|
PDFTrailerElement* m_pTrailer;
|
2016-10-18 09:21:05 +02:00
|
|
|
/// All editing takes place in this buffer, if it happens.
|
|
|
|
SvMemoryStream m_aEditBuffer;
|
2016-10-13 10:37:02 +02:00
|
|
|
|
|
|
|
static int AsHex(char ch);
|
2016-10-14 15:38:57 +02:00
|
|
|
/// Decode a hex dump.
|
|
|
|
static std::vector<unsigned char> DecodeHexString(PDFHexStringElement* pElement);
|
2016-10-13 10:37:02 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
PDFDocument();
|
|
|
|
PDFDocument& operator=(const PDFDocument&) = delete;
|
|
|
|
PDFDocument(const PDFDocument&) = delete;
|
|
|
|
static OString ReadKeyword(SvStream& rStream);
|
|
|
|
static size_t FindStartXRef(SvStream& rStream);
|
|
|
|
void ReadXRef(SvStream& rStream);
|
|
|
|
static void SkipWhitespace(SvStream& rStream);
|
|
|
|
size_t GetObjectOffset(size_t nIndex) const;
|
|
|
|
const std::vector< std::unique_ptr<PDFElement> >& GetElements();
|
|
|
|
std::vector<PDFObjectElement*> GetPages();
|
2016-10-21 16:00:58 +02:00
|
|
|
/// Remember the end location of an EOF token.
|
|
|
|
void PushBackEOF(size_t nOffset);
|
2016-10-13 10:37:02 +02:00
|
|
|
|
|
|
|
bool Read(SvStream& rStream);
|
2016-10-18 09:21:05 +02:00
|
|
|
/// Sign the read document with xCertificate in the edit buffer.
|
2016-10-20 17:09:04 +02:00
|
|
|
bool Sign(const css::uno::Reference<css::security::XCertificate>& xCertificate, const OUString& rDescription);
|
2016-10-18 09:21:05 +02:00
|
|
|
/// Serializes the contents of the edit buffer.
|
|
|
|
bool Write(SvStream& rStream);
|
2016-10-13 10:37:02 +02:00
|
|
|
std::vector<PDFObjectElement*> GetSignatureWidgets();
|
2016-10-13 21:07:55 +02:00
|
|
|
/// Return value is about if we can determine a result, rInformation is about the actual result.
|
|
|
|
static bool ValidateSignature(SvStream& rStream, PDFObjectElement* pSignature, SignatureInformation& rInformation);
|
2016-10-21 16:00:58 +02:00
|
|
|
/// Remove the nth signature from read document in the edit buffer.
|
|
|
|
bool RemoveSignature(size_t nPosition);
|
2016-10-13 10:37:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace pdfio
|
|
|
|
} // namespace xmlsecurity
|
|
|
|
|
|
|
|
#endif // INCLUDED_XMLSECURITY_INC_PDFIO_PDFDOCUMENT_HXX
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|