1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 #include <rtl/ustring.hxx>
17 struct PDFEncryptionProperties
;
20 namespace com::sun::star::beans
22 class XMaterialHolder
;
24 namespace com::sun::star::uno
26 template <typename
> class Reference
;
31 /** Interface for encrypting the PDF content
33 * This interface makes it possible to have multiple versions and
34 * revisions of PDF encryption, but all using the same interface,
35 * so the implementation details are hidden from the outside. This
36 * also makes it easier to add new implementations in the future as
37 * we only need to write a new implementation of this interface.
42 /* set to true if the following stream must be encrypted, used inside writeBuffer() */
43 bool m_bEncryptThisStream
= false;
46 virtual ~IPDFEncryptor() {}
48 /** PDF encryption version */
49 virtual sal_Int32
getVersion() = 0;
50 /** PDF encryption revision */
51 virtual sal_Int32
getRevision() = 0;
53 /** the numerical value of the access permissions, according to PDF spec, must be signed */
54 virtual sal_Int32
getAccessPermissions() = 0;
55 virtual bool isMetadataEncrypted() = 0;
57 /** Encrypted access permission
59 * Depending on the encryption revision this may not be available. In that
60 * case we can expect empty content.
62 virtual std::vector
<sal_uInt8
> getEncryptedAccessPermissions(std::vector
<sal_uInt8
>& /*rKey*/)
64 return std::vector
<sal_uInt8
>();
67 /** Length of the key in bits (i.e. 256 = 256bits) */
68 virtual sal_Int32
getKeyLength() = 0;
70 /** Prepares the encryption when the password is entered */
71 virtual bool prepareEncryption(
72 const css::uno::Reference
<css::beans::XMaterialHolder
>& xEncryptionMaterialHolder
,
73 PDFEncryptionProperties
& rProperties
)
76 /** Set up the keys and does a sanity check */
77 virtual void setupKeysAndCheck(PDFEncryptionProperties
& rProperties
) = 0;
79 /** Setup before we start encrypting - remembers the key */
80 virtual void setupEncryption(std::vector
<sal_uInt8
>& rEncryptionKey
, sal_Int32 nObject
) = 0;
82 /** Calculate the size of the output (by default the same as input) */
83 virtual sal_uInt64
calculateSizeIncludingHeader(sal_uInt64 nSize
) { return nSize
; }
85 /** Encrypts the input and stores into the output */
86 virtual void encrypt(const void* pInput
, sal_uInt64 nInputSize
, std::vector
<sal_uInt8
>& rOutput
,
87 sal_uInt64 nOutputSize
)
90 void enableStreamEncryption() { m_bEncryptThisStream
= true; }
91 void disableStreamEncryption() { m_bEncryptThisStream
= false; }
92 bool isStreamEncryptionEnabled() { return m_bEncryptThisStream
; }
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */