PoDoFo 1.2.0
Loading...
Searching...
No Matches
PdfSignature.h
1// SPDX-FileCopyrightText: 2011 Dominik Seichter <domseichter@web.de>
2// SPDX-FileCopyrightText: 2011 Petr Pytelka
3// SPDX-FileCopyrightText: 2020 Francesco Pretto <ceztko@gmail.com>
4// SPDX-License-Identifier: LGPL-2.0-or-later OR MPL-2.0
5
6#ifndef PDF_SIGNATURE_H
7#define PDF_SIGNATURE_H
8
9#include "PdfDeclarations.h"
10
11#include "PdfAnnotation.h"
12#include "PdfField.h"
13#include "PdfDate.h"
14#include "PdfData.h"
15#include <podofo/auxiliary/InputDevice.h>
16#include <podofo/auxiliary/OutputDevice.h>
17
18namespace PoDoFo {
19
20class PdfAcroForm;
21
22enum class PdfCertPermission : uint8_t
23{
24 NoPerms = 1,
25 FormFill = 2,
26 Annotations = 3,
27};
28
29struct PdfSignatureBeacons final
30{
31 PdfSignatureBeacons();
32 charbuff ContentsBeacon;
33 charbuff ByteRangeBeacon;
34 std::shared_ptr<size_t> ContentsOffset;
35 std::shared_ptr<size_t> ByteRangeOffset;
36};
37
39{
42 Indeterminate = 0,
43
46 Invalid,
47
52
55 CryptoVerified,
56};
57
58class PODOFO_API PdfSignature final : public PdfField
59{
60 friend class PdfField;
61 friend class PdfSigningContext;
62 friend class PdfDocument;
63
64private:
65 PdfSignature(PdfAcroForm& acroform, std::shared_ptr<PdfField>&& parent);
66
67 PdfSignature(PdfAnnotationWidget& widget, std::shared_ptr<PdfField>&& parent);
68
69 PdfSignature(PdfObject& obj, PdfAcroForm* acroform);
70
71public:
80 bool TryVerifySignature(InputStreamDevice& input, PdfSignatureVerifyStatus& status) const;
81
85 void SetSignerName(nullable<const PdfString&> text);
86
90 void SetSignatureReason(nullable<const PdfString&> text);
91
95 void SetSignatureLocation(nullable<const PdfString&> text);
96
97 [[deprecated("Use the SetCreatingApplication method instead")]]
98 void SetSignatureCreator(nullable<const PdfString&> creator);
99
103 void SetCreatingApplication(nullable<const PdfName&> application);
104
106 void SetSignatureDate(nullable<const PdfDate&> sigDate);
107
111 void AddCertificationReference(PdfCertPermission perm = PdfCertPermission::NoPerms);
112
116 nullable<const PdfString&> GetSignerName() const;
117
121 nullable<const PdfString&> GetSignatureReason() const;
122
126 nullable<const PdfString&> GetSignatureLocation() const;
127
131 nullable<PdfDate> GetSignatureDate() const;
132
137 void EnsureValueObject();
138
139 PdfSignature* GetParent();
140 const PdfSignature* GetParent() const;
141
145 bool TryGetPreviousRevision(InputStreamDevice& input, OutputStreamDevice& output) const;
146
147protected:
148 PdfObject* getValueObject() const override;
149
150private:
163 void PrepareForSigning(const std::string_view& filter,
164 const std::string_view& subFilter,
165 const std::string_view& type,
166 const PdfSignatureBeacons& beacons);
167
168 // To be called by SignDocument()
169 void SetContentsByteRangeNoDirtySet(const bufferview& contents, PdfArray&& byteRange);
170
171 // To be called by PdfDocument
176 nullable<std::array<size_t, 4>> GetByteRangeBounds() const;
177
178 void ensureValueObject();
179private:
180 void init(PdfAcroForm& acroForm);
181
182private:
183 PdfObject* m_ValueObj;
184};
185
186}
187
188#endif // PDF_SIGNATURE_H
This file should be included as the FIRST file in every header of PoDoFo lib.
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition basetypes.h:30
All classes, functions, types and enums of PoDoFo are members of these namespace.
Definition basetypes.h:13
@ Indeterminate
Indeterminate map type, such as non standard identity encodings.
PdfSignatureVerifyStatus
Definition PdfSignature.h:39
@ Invalid
The CMS signature is cryptographically valid over the signed bytes, but the /ByteRange doesn't reach ...
@ CryptoVerifiedPartialCoverage
The CMS signature is cryptographically valid and the /ByteRange covers the whole input.