PoDoFo 1.2.0
Loading...
Searching...
No Matches
PdfSignerDocTimeStamp.h
1// SPDX-FileCopyrightText: 2026 Francesco Pretto <ceztko@gmail.com>
2// SPDX-License-Identifier: LGPL-2.0-or-later OR MPL-2.0
3
4#ifndef PDF_SIGNER_DOC_TIMESTAMP_H
5#define PDF_SIGNER_DOC_TIMESTAMP_H
6
7#include "PdfSigner.h"
8
9extern "C"
10{
11 // OpenSSL forward declaration
12 struct evp_md_ctx_st;
13 // libxml2 forward declaration
14 typedef struct _xmlNode xmlNode;
15 typedef xmlNode* xmlNodePtr;
16}
17
18namespace PoDoFo
19{
26
28 {
29 None = 0,
34 };
35
36 struct PODOFO_API PdfSignerDocTimeStampParams final
37 {
38 PdfHashingAlgorithm Hashing = PdfHashingAlgorithm::SHA256;
40 PdfTimeStampService TimeStampService;
44 unsigned ReservedSize = 0;
45 PdfSignerDocTimeStampFlags Flags = PdfSignerDocTimeStampFlags::None;
46 };
47
52 class PODOFO_API PdfSignerDocTimeStamp : public PdfSigner
53 {
54 friend class PdfSigningContext;
55 public:
57 static constexpr unsigned DefaultReservedSize = 8192;
58
59 public:
60 PdfSignerDocTimeStamp(const PdfSignerDocTimeStampParams& parameters = { });
61
63
64 public:
65 void Reset() override;
66 void AppendData(const bufferview& data) override;
67 void ComputeSignature(charbuff& contents, bool dryrun) override;
68 void FetchIntermediateResult(charbuff& result) override;
69 void ComputeSignatureDeferred(const bufferview& processedResult, charbuff& contents, bool dryrun) override;
70 std::string GetSignatureSubFilter() const override;
71 std::string GetSignatureType() const override;
72
73 public:
74 const PdfSignerDocTimeStampParams& GetParameters() const { return m_parameters; }
75
76 private:
77 // Called by PdfSigningContext
78 void Dump(xmlNodePtr signerElem, std::string& temp);
79 void Restore(xmlNodePtr signerElem, charbuff& temp);
80 private:
81 void ensureEventBasedTimestamping();
82 void ensureDeferredTimestamping();
83 void ensureDigestInitialized();
84 void resetDigest();
85 void ensureHashComputed();
86 void setContents(const bufferview& timeStamp, charbuff& contents);
87 bool shouldVerify() const;
88 private:
89 nullable<bool> m_deferredTimestamping;
90 PdfSignerDocTimeStampParams m_parameters;
91 struct evp_md_ctx_st* m_digestCtx;
92 // The document digest, empty until computed
93 charbuff m_hash;
94
95 // Temporary buffer variables
96 // NOTE: Don't clear it in Reset() override
97 charbuff m_timeStamp;
98 };
99}
100
101ENABLE_BITMASK_OPERATORS(PoDoFo::PdfSignerDocTimeStampFlags);
102
103#endif // PDF_SIGNER_DOC_TIMESTAMP_H
This class computes a document timestamp (/Type /DocTimeStamp) with a RFC 3161 timestamp token,...
Definition PdfSignerDocTimeStamp.h:53
A context that can be used to customize the signing process.
Definition PdfSigningContext.h:64
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
PdfSignerDocTimeStampFlags
Definition PdfSignerDocTimeStamp.h:28
@ None
Do not add a default appearance.
cspan< char > bufferview
Convenient read-only char buffer span.
Definition basetypes.h:15
@ SkipVerification
Skip the validation of the signature date against the validity period of the supplied certificate.
std::function< void(bufferview hash, bool dryrun, charbuff &timeStamp)> PdfTimeStampService
A service that obtains a RFC 3161 timestamp for the given document digest.
Definition PdfSignerDocTimeStamp.h:25