/src/libreoffice/vcl/inc/pdf/IPDFEncryptor.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | */ |
9 | | |
10 | | #pragma once |
11 | | |
12 | | #include <rtl/ustring.hxx> |
13 | | #include <vector> |
14 | | |
15 | | namespace vcl |
16 | | { |
17 | | struct PDFEncryptionProperties; |
18 | | } |
19 | | |
20 | | namespace com::sun::star::beans |
21 | | { |
22 | | class XMaterialHolder; |
23 | | } |
24 | | namespace com::sun::star::uno |
25 | | { |
26 | | template <typename> class Reference; |
27 | | } |
28 | | |
29 | | namespace vcl::pdf |
30 | | { |
31 | | /** Interface for encrypting the PDF content |
32 | | * |
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. |
38 | | */ |
39 | | class IPDFEncryptor |
40 | | { |
41 | | private: |
42 | | /* set to true if the following stream must be encrypted, used inside writeBuffer() */ |
43 | | bool m_bEncryptThisStream = false; |
44 | | |
45 | | public: |
46 | 0 | virtual ~IPDFEncryptor() {} |
47 | | |
48 | | /** PDF encryption version */ |
49 | | virtual sal_Int32 getVersion() = 0; |
50 | | /** PDF encryption revision */ |
51 | | virtual sal_Int32 getRevision() = 0; |
52 | | |
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; |
56 | | |
57 | | /** Encrypted access permission |
58 | | * |
59 | | * Depending on the encryption revision this may not be available. In that |
60 | | * case we can expect empty content. |
61 | | */ |
62 | | virtual std::vector<sal_uInt8> getEncryptedAccessPermissions(std::vector<sal_uInt8>& /*rKey*/) |
63 | 0 | { |
64 | 0 | return std::vector<sal_uInt8>(); |
65 | 0 | } |
66 | | |
67 | | /** Length of the key in bits (i.e. 256 = 256bits) */ |
68 | | virtual sal_Int32 getKeyLength() = 0; |
69 | | |
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) |
74 | | = 0; |
75 | | |
76 | | /** Set up the keys and does a sanity check */ |
77 | | virtual void setupKeysAndCheck(PDFEncryptionProperties& rProperties) = 0; |
78 | | |
79 | | /** Setup before we start encrypting - remembers the key */ |
80 | | virtual void setupEncryption(std::vector<sal_uInt8>& rEncryptionKey, sal_Int32 nObject) = 0; |
81 | | |
82 | | /** Calculate the size of the output (by default the same as input) */ |
83 | 0 | virtual sal_uInt64 calculateSizeIncludingHeader(sal_uInt64 nSize) { return nSize; } |
84 | | |
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) |
88 | | = 0; |
89 | | |
90 | 0 | void enableStreamEncryption() { m_bEncryptThisStream = true; } |
91 | 0 | void disableStreamEncryption() { m_bEncryptThisStream = false; } |
92 | 0 | bool isStreamEncryptionEnabled() { return m_bEncryptThisStream; } |
93 | | }; |
94 | | } |
95 | | |
96 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |