Debian Codegraph @

qt6/src/poppler-form.h

raw
1 /* poppler-form.h: qt interface to poppler
2 * Copyright (C) 2007-2008, Pino Toscano <[email protected]>
3 * Copyright (C) 2008, 2011, 2016, 2017, 2019-2022, Albert Astals Cid <[email protected]>
4 * Copyright (C) 2012, Adam Reichold <[email protected]>
5 * Copyright (C) 2016, Hanno Meyer-Thurow <[email protected]>
6 * Copyright (C) 2017, Hans-Ulrich Jüttner <[email protected]>
7 * Copyright (C) 2017, Tobias C. Berner <[email protected]>
8 * Copyright (C) 2018, Andre Heinecke <[email protected]>
9 * Copyright (C) 2018, Chinmoy Ranjan Pradhan <[email protected]>
10 * Copyright (C) 2018, 2021 Oliver Sander <[email protected]>
11 * Copyright (C) 2019 João Netto <[email protected]>
12 * Copyright (C) 2019, Adrian Johnson <[email protected]>
13 * Copyright (C) 2020, Thorsten Behrens <[email protected]>
14 * Copyright (C) 2020, Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]>. Work sponsored by Technische Universität Dresden
15 * Copyright (C) 2021, Theofilos Intzoglou <[email protected]>
16 * Copyright (C) 2023-2025, g10 Code GmbH, Author: Sune Stolborg Vuorela <[email protected]>
17 * Copyright (C) 2024, Pratham Gandhi <[email protected]>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2, or (at your option)
22 * any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
32 */
33
34 #ifndef _POPPLER_QT6_FORM_H_
35 #define _POPPLER_QT6_FORM_H_
36
37 #include <functional>
38 #include <memory>
39 #include <ctime>
40 #include <optional>
41 #include <QtCore/QDateTime>
42 #include <QtCore/QVector>
43 #include <QtCore/QList>
44 #include <QtCore/QRectF>
45 #include <QtCore/QStringList>
46 #include <QtCore/QSharedPointer>
47 #include "poppler-export.h"
48 #include "poppler-annotation.h"
49 #include "poppler-qt6.h"
50
51 class Object;
52 class Page;
53 class FormWidget;
54 class FormWidgetButton;
55 class FormWidgetText;
56 class FormWidgetChoice;
57 class FormWidgetSignature;
58
59 namespace Poppler {
60
61 class DocumentData;
62 class Link;
63
64 class FormFieldData;
65 class FormFieldIconData;
66
67 /**
68 The class containing the appearance information
69 */
70
71 class POPPLER_QT6_EXPORT FormFieldIcon
72 {
73
74 friend class FormFieldIconData;
75
76 public:
77 explicit FormFieldIcon(FormFieldIconData *data);
78 FormFieldIcon(const FormFieldIcon &ffIcon);
79 ~FormFieldIcon();
80
81 FormFieldIcon &operator=(const FormFieldIcon &ffIcon);
82
83 private:
84 FormFieldIconData *d_ptr;
85 };
86 /**
87 The base class representing a form field.
88 */
89 class POPPLER_QT6_EXPORT FormField
90 {
91
92 friend class FormFieldData;
93
94 public:
95 /**
96 The different types of form field.
97 */
98 enum FormType
99 {
100 FormButton, ///< A button field. See \ref Poppler::FormFieldButton::ButtonType "ButtonType"
101 FormText, ///< A text field. See \ref Poppler::FormFieldText::TextType "TextType"
102 FormChoice, ///< A single choice field. See \ref Poppler::FormFieldChoice::ChoiceType "ChoiceType"
103 FormSignature ///< A signature field.
104 };
105
106 virtual ~FormField();
107
108 /**
109 The type of the field.
110 */
111 virtual FormType type() const = 0;
112
113 /**
114 \return The size of the field, in normalized coordinates, i.e.
115 [0..1] with regard to the dimensions (cropbox) of the page
116 */
117 QRectF rect() const;
118
119 /**
120 The ID of the field.
121 */
122 int id() const;
123
124 /**
125 The internal name (T) of the field.
126 */
127 QString name() const;
128
129 /**
130 Sets the internal name (T) of the field.
131 */
132 void setName(const QString &name) const;
133
134 /**
135 The internal fully qualified name of the field.
136 */
137 QString fullyQualifiedName() const;
138
139 /**
140 The name of the field to be used in user interface (eg messages to
141 the user).
142 */
143 QString uiName() const;
144
145 /**
146 Whether this form field is read-only.
147 */
148 bool isReadOnly() const;
149
150 /**
151 Set whether this form field is read-only.
152 */
153 void setReadOnly(bool value);
154
155 /**
156 Whether this form field is visible.
157 */
158 bool isVisible() const;
159
160 /**
161 Set whether this form field is visible.
162 */
163 void setVisible(bool value);
164
165 /**
166 Whether this field is printable.
167 */
168 bool isPrintable() const;
169
170 /**
171 Set whether this field is printable.
172 */
173 void setPrintable(bool value);
174
175 /**
176 The activation action of this form field.
177
178 \note It may be null.
179 */
180 std::unique_ptr<Link> activationAction() const;
181
182 /**
183 * Describes the flags from the form 'AA' dictionary.
184 */
185 enum AdditionalActionType
186 {
187 FieldModified, ///< A JavaScript action to be performed when the user modifies the field
188 FormatField, ///< A JavaScript action to be performed before the field is formatted to display its value
189 ValidateField, ///< A JavaScript action to be performed when the field value changes
190 CalculateField, ///< A JavaScript action to be performed when the field needs to be recalculated
191 };
192 /**
193 * Returns a given form additional action
194 */
195 std::unique_ptr<Link> additionalAction(AdditionalActionType type) const;
196
197 /**
198 * Returns a given widget annotation additional action
199 */
200 std::unique_ptr<Link> additionalAction(Annotation::AdditionalActionType type) const;
201
202 protected:
203 /// \cond PRIVATE
204 explicit FormField(std::unique_ptr<FormFieldData> dd);
205
206 std::unique_ptr<FormFieldData> m_formData;
207 /// \endcond
208
209 private:
210 Q_DISABLE_COPY(FormField)
211 };
212
213 /**
214 A form field that represents a "button".
215 */
216 class POPPLER_QT6_EXPORT FormFieldButton : public FormField
217 {
218 public:
219 /**
220 * The types of button field.
221 */
222 enum ButtonType
223 {
224 Push, ///< A simple push button.
225 CheckBox, ///< A check box.
226 Radio ///< A radio button.
227 };
228
229 /// \cond PRIVATE
230 FormFieldButton(DocumentData *doc, ::Page *p, ::FormWidgetButton *w);
231 /// \endcond
232 ~FormFieldButton() override;
233
234 FormType type() const override;
235
236 /**
237 The particular type of the button field.
238 */
239 ButtonType buttonType() const;
240
241 /**
242 * The caption to be used for the button.
243 */
244 QString caption() const;
245
246 /**
247 * Gets the icon used by the button
248 */
249 FormFieldIcon icon() const;
250
251 /**
252 * Sets a new icon for the button, it has to be a icon
253 * returned by FormFieldButton::icon.
254 */
255 void setIcon(const FormFieldIcon &icon);
256
257 /**
258 The state of the button.
259 */
260 bool state() const;
261
262 /**
263 Sets the state of the button to the new \p state .
264 */
265 void setState(bool state);
266
267 /**
268 The list with the IDs of siblings (ie, buttons belonging to the same
269 group as the current one.
270
271 Valid only for \ref Radio buttons, an empty list otherwise.
272 */
273 QList<int> siblings() const;
274
275 private:
276 Q_DISABLE_COPY(FormFieldButton)
277 };
278
279 /**
280 A form field that represents a text input.
281 */
282 class POPPLER_QT6_EXPORT FormFieldText : public FormField
283 {
284 public:
285 /**
286 The particular type of this text field.
287 */
288 enum TextType
289 {
290 Normal, ///< A simple singleline text field.
291 Multiline, ///< A multiline text field.
292 FileSelect ///< An input field to select the path of a file on disk.
293 };
294
295 /// \cond PRIVATE
296 FormFieldText(DocumentData *doc, ::Page *p, ::FormWidgetText *w);
297 /// \endcond
298 ~FormFieldText() override;
299
300 FormType type() const override;
301
302 /**
303 The text type of the text field.
304 */
305 TextType textType() const;
306
307 /**
308 The text associated with the text field.
309 */
310 QString text() const;
311
312 /**
313 Sets the text associated with the text field to the specified
314 \p text.
315 */
316 void setText(const QString &text);
317
318 /**
319 Sets the text inside the Appearance Stream to the specified
320 \p text
321 */
322 void setAppearanceText(const QString &text);
323
324 /**
325 Whether this text field is a password input, eg its text \b must be
326 replaced with asterisks.
327
328 Always false for \ref FileSelect text fields.
329 */
330 bool isPassword() const;
331
332 /**
333 Whether this text field should allow rich text.
334 */
335 bool isRichText() const;
336
337 /**
338 The maximum length for the text of this field, or -1 if not set.
339 */
340 int maximumLength() const;
341
342 /**
343 The horizontal alignment for the text of this text field.
344 */
345 Qt::Alignment textAlignment() const;
346
347 /**
348 Whether the text inserted manually in the field (where possible)
349 can be spell-checked.
350 */
351 bool canBeSpellChecked() const;
352
353 /**
354 The font size of the text in the form field
355 */
356 double getFontSize() const;
357
358 /**
359 Set the font size of the text in the form field (currently only as integer)
360 */
361 void setFontSize(int fontSize);
362
363 private:
364 Q_DISABLE_COPY(FormFieldText)
365 };
366
367 /**
368 A form field that represents a choice field.
369 */
370 class POPPLER_QT6_EXPORT FormFieldChoice : public FormField
371 {
372 public:
373 /**
374 The particular type of this choice field.
375 */
376 enum ChoiceType
377 {
378 ComboBox, ///< A simple singleline text field.
379 ListBox ///< A multiline text field.
380 };
381
382 /// \cond PRIVATE
383 FormFieldChoice(DocumentData *doc, ::Page *p, ::FormWidgetChoice *w);
384 /// \endcond
385 ~FormFieldChoice() override;
386
387 FormType type() const override;
388
389 /**
390 The choice type of the choice field.
391 */
392 ChoiceType choiceType() const;
393
394 /**
395 The possible choices of the choice field.
396 */
397 QStringList choices() const;
398
399 /**
400 The possible choices of the choice field.
401 The first value of the pair is the display name of the choice,
402 The second value is the export value (i.e. for use in javascript, etc) of the choice
403 */
404 QVector<QPair<QString, QString>> choicesWithExportValues() const;
405
406 /**
407 Whether this FormFieldChoice::ComboBox is editable, i.e. the user
408 can type in a custom value.
409
410 Always false for the other types of choices.
411 */
412 bool isEditable() const;
413
414 /**
415 Whether more than one choice of this FormFieldChoice::ListBox
416 can be selected at the same time.
417
418 Always false for the other types of choices.
419 */
420 bool multiSelect() const;
421
422 /**
423 The currently selected choices.
424 */
425 QList<int> currentChoices() const;
426
427 /**
428 Sets the selected choices to \p choice.
429 */
430 void setCurrentChoices(const QList<int> &choice);
431
432 /**
433 The text entered into an editable combo box choice field. Otherwise a null string.
434 */
435 QString editChoice() const;
436
437 /**
438 Sets the text entered into an editable combo box choice field. Otherwise does nothing.
439 */
440 void setEditChoice(const QString &text);
441
442 /**
443 The horizontal alignment for the text of this text field.
444 */
445 Qt::Alignment textAlignment() const;
446
447 /**
448 Whether the text inserted manually in the field (where possible)
449 can be spell-checked.
450
451 Returns false if the field is not an editable text field.
452 */
453 bool canBeSpellChecked() const;
454
455 /**
456 Sets the text inside the Appearance Stream to the specified
457 \p text
458
459 \since 24.08
460 */
461 void setAppearanceChoiceText(const QString &text);
462
463 private:
464 Q_DISABLE_COPY(FormFieldChoice)
465 };
466
467 /**
468 A helper class to store x509 certificate information.
469 */
470 class CertificateInfoPrivate;
471 class POPPLER_QT6_EXPORT CertificateInfo
472 {
473 public:
474 /**
475 The algorithm of public key.
476 */
477 enum PublicKeyType
478 {
479 RsaKey,
480 DsaKey,
481 EcKey,
482 OtherKey
483 };
484
485 /**
486 Certificate key usage extensions.
487 */
488 enum KeyUsageExtension
489 {
490 KuDigitalSignature = 0x80,
491 KuNonRepudiation = 0x40,
492 KuKeyEncipherment = 0x20,
493 KuDataEncipherment = 0x10,
494 KuKeyAgreement = 0x08,
495 KuKeyCertSign = 0x04,
496 KuClrSign = 0x02,
497 KuEncipherOnly = 0x01,
498 KuNone = 0x00
499 };
500 Q_DECLARE_FLAGS(KeyUsageExtensions, KeyUsageExtension)
501
502 /**
503 Predefined keys for elements in an entity's distinguished name.
504 */
505 enum EntityInfoKey
506 {
507 CommonName,
508 DistinguishedName,
509 EmailAddress,
510 Organization,
511 };
512
513 /**
514 * The type of the certificate
515 *
516 * \since 25.03
517 */
518 enum class CertificateType
519 {
520 X509,
521 PGP
522 };
523
524 /** A signing key can be located in different places
525 sometimes. For the user, it might be easier to pick
526 the key located on a card if it has some visual
527 indicator that it is somehow removable.
528
529 \note a keylocation for a certificate without a private
530 key (cannot be used for signing) will likely be "Unknown"
531
532 \since 23.09
533 */
534 enum class KeyLocation
535 {
536 Unknown, /** We don't know the location */
537 Other, /** We know the location, but it is somehow not covered by this enum */
538 Computer, /** The key is on this computer */
539 HardwareToken /** The key is on a dedicated hardware token, either a smartcard or a dedicated usb token (e.g. gnuk, nitrokey or yubikey) */
540 };
541
542 CertificateInfo();
543 explicit CertificateInfo(CertificateInfoPrivate *priv);
544 ~CertificateInfo();
545
546 /**
547 Returns true if certificate has no contents; otherwise returns false
548 */
549 bool isNull() const;
550
551 /**
552 The certificate version string.
553 */
554 int version() const;
555
556 /**
557 The certificate serial number.
558 */
559 QByteArray serialNumber() const;
560
561 /**
562 Information about the issuer.
563 */
564 QString issuerInfo(EntityInfoKey key) const;
565
566 /**
567 Information about the subject
568 */
569 QString subjectInfo(EntityInfoKey key) const;
570
571 /**
572 The certificate internal database nickname
573
574 \since 21.01
575 */
576 QString nickName() const;
577
578 /**
579 The date-time when certificate becomes valid.
580 */
581 QDateTime validityStart() const;
582
583 /**
584 The date-time when certificate expires.
585 */
586 QDateTime validityEnd() const;
587
588 /**
589 The uses allowed for the certificate.
590 */
591 KeyUsageExtensions keyUsageExtensions() const;
592
593 /**
594 The public key value.
595 */
596 QByteArray publicKey() const;
597
598 /**
599 The public key type.
600 */
601 PublicKeyType publicKeyType() const;
602
603 /**
604 The strength of public key in bits.
605 */
606 int publicKeyStrength() const;
607
608 /**
609 Returns true if certificate is self-signed otherwise returns false.
610 */
611 bool isSelfSigned() const;
612
613 /**
614 * Can be used to do qualified electronic signatures (legally binding)
615 *
616 * https://en.wikipedia.org/wiki/Qualified_electronic_signature
617 */
618 bool isQualified() const;
619
620 /**
621 * \return certificate type
622 *
623 * \since 25.03
624 */
625 CertificateType certificateType() const;
626
627 /**
628 The DER encoded certificate.
629 */
630 QByteArray certificateData() const;
631
632 /**
633 Checks if the given password is the correct one for this certificate
634
635 \since 21.01
636 */
637 bool checkPassword(const QString &password) const;
638
639 /**
640 The storage location for this key
641
642 \since 23.09
643 */
644 KeyLocation keyLocation() const;
645
646 CertificateInfo(const CertificateInfo &other);
647 CertificateInfo &operator=(const CertificateInfo &other);
648
649 private:
650 Q_DECLARE_PRIVATE(CertificateInfo)
651
652 QSharedPointer<CertificateInfoPrivate> d_ptr;
653 };
654 Q_DECLARE_OPERATORS_FOR_FLAGS(CertificateInfo::KeyUsageExtensions)
655
656 /**
657 A signature validation info helper class.
658 */
659 class SignatureValidationInfoPrivate;
660 class POPPLER_QT6_EXPORT SignatureValidationInfo
661 {
662 public:
663 /**
664 The verification result of the signature.
665 */
666 enum SignatureStatus
667 {
668 SignatureValid, ///< The signature is cryptographically valid.
669 SignatureInvalid, ///< The signature is cryptographically invalid.
670 SignatureDigestMismatch, ///< The document content was changed after the signature was applied.
671 SignatureDecodingError, ///< The signature CMS/PKCS7 structure is malformed.
672 SignatureGenericError, ///< The signature could not be verified.
673 SignatureNotFound, ///< The requested signature is not present in the document.
674 SignatureNotVerified ///< The signature is not yet verified.
675 };
676
677 /**
678 The verification result of the certificate.
679 */
680 enum CertificateStatus
681 {
682 CertificateTrusted, ///< The certificate is considered trusted.
683 CertificateUntrustedIssuer, ///< The issuer of this certificate has been marked as untrusted by the user.
684 CertificateUnknownIssuer, ///< The certificate trust chain has not finished in a trusted root certificate.
685 CertificateRevoked, ///< The certificate was revoked by the issuing certificate authority.
686 CertificateExpired, ///< The signing time is outside the validity bounds of this certificate.
687 CertificateGenericError, ///< The certificate could not be verified.
688 CertificateNotVerified, ///< The certificate is not yet verified.
689 CertificateVerificationInProgress ///< The certificate is not yet verified but is in progress in the background. See \ref validateAsync \since 24.05
690 };
691
692 /**
693 The hash algorithm of the signature
694 */
695 enum HashAlgorithm
696 {
697 HashAlgorithmUnknown,
698 HashAlgorithmMd2,
699 HashAlgorithmMd5,
700 HashAlgorithmSha1,
701 HashAlgorithmSha256,
702 HashAlgorithmSha384,
703 HashAlgorithmSha512,
704 HashAlgorithmSha224
705 };
706
707 /// \cond PRIVATE
708 explicit SignatureValidationInfo(SignatureValidationInfoPrivate *priv);
709 /// \endcond
710 ~SignatureValidationInfo();
711
712 /**
713 The signature status of the signature.
714 */
715 SignatureStatus signatureStatus() const;
716
717 /**
718 The certificate status of the signature.
719 */
720 CertificateStatus certificateStatus() const;
721
722 /**
723 The signer name associated with the signature.
724 */
725 QString signerName() const;
726
727 /**
728 The signer subject distinguished name associated with the signature.
729 */
730 QString signerSubjectDN() const;
731
732 /**
733 Get signing location.
734 */
735 QString location() const;
736
737 /**
738 Get signing reason.
739 */
740 QString reason() const;
741
742 /**
743 The hash algorithm used for the signature.
744 */
745 HashAlgorithm hashAlgorithm() const;
746
747 /**
748 The signing time associated with the signature.
749 */
750 time_t signingTime() const;
751
752 /**
753 Get the signature binary data.
754 */
755 QByteArray signature() const;
756
757 /**
758 Get the bounds of the ranges of the document which are signed.
759 */
760 QList<qint64> signedRangeBounds() const;
761
762 /**
763 Checks whether the signature authenticates the total document
764 except for the signature itself.
765 */
766 bool signsTotalDocument() const;
767
768 /**
769 The signer certificate info.
770 */
771 CertificateInfo certificateInfo() const;
772
773 SignatureValidationInfo(const SignatureValidationInfo &other);
774 SignatureValidationInfo &operator=(const SignatureValidationInfo &other);
775
776 private:
777 Q_DECLARE_PRIVATE(SignatureValidationInfo)
778 friend class FormFieldSignature;
779 QSharedPointer<SignatureValidationInfoPrivate> d_ptr;
780 };
781
782 /**
783 * Object help waiting for some async event
784 *
785 * \since 24.05
786 */
787 class AsyncObjectPrivate;
788 class POPPLER_QT6_EXPORT AsyncObject : public QObject // clazy:exclude=ctor-missing-parent-argument
789 {
790 Q_OBJECT
791 public:
792 /* Constructor. On purpose not having a QObject parameter
793 It will be returned by shared_ptr or unique_ptr
794 */
795 AsyncObject();
796 ~AsyncObject() override;
797 Q_SIGNALS:
798 void done();
799
800 private:
801 std::unique_ptr<AsyncObjectPrivate> d;
802 };
803
804 /**
805 A form field that represents a signature.
806 */
807 class POPPLER_QT6_EXPORT FormFieldSignature : public FormField
808 {
809 public:
810 /**
811 The types of signature fields.
812 */
813 enum SignatureType
814 {
815 UnknownSignatureType,
816 AdbePkcs7sha1,
817 AdbePkcs7detached,
818 EtsiCAdESdetached,
819 UnsignedSignature, ///< \since 22.02
820 G10cPgpSignatureDetached, ///< nonstandardized signature type \since 25.01
821 };
822
823 /**
824 The validation options of this signature.
825 */
826 enum ValidateOptions
827 {
828 ValidateVerifyCertificate = 1, ///< Validate the certificate.
829 ValidateForceRevalidation = 2, ///< Force revalidation of the certificate.
830 ValidateWithoutOCSPRevocationCheck = 4, ///< Do not contact OCSP servers to check for certificate revocation status \since 21.10
831 ValidateUseAIACertFetch = 8 ///< Use the AIA extension for certificate fetching \since 21.10
832 };
833
834 /// \cond PRIVATE
835 FormFieldSignature(DocumentData *doc, ::Page *p, ::FormWidgetSignature *w);
836 /// \endcond
837 ~FormFieldSignature() override;
838
839 FormType type() const override;
840
841 /**
842 The signature type
843 */
844 SignatureType signatureType() const;
845
846 /**
847 Validate the signature with now as validation time.
848
849 Reset signature validatation info of scoped instance.
850
851 \note depending on the backend, some options are only
852 partially respected. In case of the NSS backend, the two options
853 requiring network access, AIAFetch and OCSP,
854 can be toggled individually. In case of the GPG backend, if either
855 OCSP is used or AIAFetch is used, the other one is also used.
856
857 \deprecated Please rewrite to the async version, that allows the network traffic part of fetching to happen in the background
858 */
859 POPPLER_QT6_DEPRECATED SignatureValidationInfo validate(ValidateOptions opt) const;
860
861 /**
862 Validate the signature with @p validationTime as validation time.
863
864 Reset signature validatation info of scoped instance.
865
866 \note depending on the backend, some options are only
867 partially respected. In case of the NSS backend, the two options
868 requiring network access, AIAFetch and OCSP,
869 can be toggled individually. In case of the GPG backend, if either
870 OCSP is used or AIAFetch is used, the other one is also used.
871
872 \deprecated Please rewrite to the async version, that allows the network traffic part of fetching to happen in the background
873 */
874 POPPLER_QT6_DEPRECATED SignatureValidationInfo validate(int opt, const QDateTime &validationTime) const;
875
876 /**
877 Validate the signature with @p validationTime as validation time.
878
879 Reset signature validatation info of scoped instance.
880
881 \since 24.05
882
883 \note depending on the backend, some options are only
884 partially respected. In case of the NSS backend, the two options
885 requiring network access, AIAFetch and OCSP,
886 can be toggled individually. In case of the GPG backend, if either
887 OCSP is used or AIAFetch is used, the other one is also used.
888
889 \note certificate validation will have started when this function return. See \ref validateResult on how to get certifcate validation
890 \note connections to \ref AsyncObject must happen by the caller
891 before returning control to the event loop, else signals is not guaranteed to be delivered
892 */
893 std::pair<SignatureValidationInfo, std::shared_ptr<AsyncObject>> validateAsync(ValidateOptions opt, const QDateTime &validationTime = {}) const;
894
895 /**
896 * \return the updated signature validation info from validateAsync
897 * \note that this function will block if the result is not yet ready.
898 * Wait for the \ref AsyncObject::done signal to avoid this function blocking on an inconvenient time
899 *
900 * \since 24.05
901 */
902 SignatureValidationInfo::CertificateStatus validateResult() const;
903
904 /**
905 * For consumers, this enum will be extended. Unknown numbers should probably be
906 * treated as GenericSigningError
907 *
908 * \since 22.02
909 */
910 enum SigningResult
911 {
912 FieldAlreadySigned, ///< Trying to sign a field that is already signed \since 24.10
913 GenericSigningError, ///< Unclassified error \since 24.10
914 SigningSuccess, ///< No error \since 24.10
915 InternalError, ///< Unexpected error, likely a bug in poppler \since 24.12
916 KeyMissing, ///< Key not found (Either the input key is not from the list or the available keys has changed underneath \since 24.12)
917 WriteFailed, ///< Write failed (permissions, faulty disk, ...) \since 24.12
918 UserCancelled, ///< User cancelled the process \since 24.12
919 BadPassphrase, ///< Passphrase didn't work \since 25.03
920 };
921
922 /**
923 Signs a field of UnsignedSignature type.
924
925 Ignores data.page(), data.fieldPartialName() and data.boundingRectangle()
926
927 \since 22.02
928 */
929 SigningResult sign(const QString &outputFileName, const PDFConverter::NewSignatureData &data) const;
930
931 /**
932 * A string with a string that might offer more details of the signing result failure
933 * \note the string here is likely not super useful for end users, but might give more details to a trained supporter / bug triager
934 * \since 25.07
935 */
936
937 ErrorString lastSigningErrorDetails() const;
938
939 private:
940 Q_DISABLE_COPY(FormFieldSignature)
941 };
942 /**
943 * Possible compiled in backends for signature handling
944 *
945 * \since 23.06
946 */
947 enum class CryptoSignBackend
948 {
949 NSS,
950 GPG
951 };
952
953 /**
954 * The available compiled-in backends
955 *
956 * \since 23.06
957 */
958 QVector<CryptoSignBackend> POPPLER_QT6_EXPORT availableCryptoSignBackends();
959
960 /**
961 * Returns current active backend or nullopt if none is active
962 *
963 * \note there will always be an active backend if there is available backends
964 *
965 * \since 23.06
966 */
967 std::optional<CryptoSignBackend> POPPLER_QT6_EXPORT activeCryptoSignBackend();
968
969 /**
970 * Sets active backend
971 *
972 * \return true on success
973 *
974 * \since 23.06
975 */
976 bool POPPLER_QT6_EXPORT setActiveCryptoSignBackend(CryptoSignBackend backend);
977
978 enum class CryptoSignBackendFeature
979 {
980 /// If the backend itself out of band requests passwords
981 /// or if the host applicaion somehow must do it
982 BackendAsksPassphrase
983 };
984
985 /**
986 * Queries if a backend supports or not supports a given feature.
987 *
988 * \since 23.06
989 */
990 bool POPPLER_QT6_EXPORT hasCryptoSignBackendFeature(CryptoSignBackend, CryptoSignBackendFeature);
991
992 /**
993 Returns is poppler was compiled with NSS support
994
995 \deprecated Use availableBackends instead
996
997 \since 21.01
998 */
999 bool POPPLER_QT6_DEPRECATED POPPLER_QT6_EXPORT hasNSSSupport();
1000
1001 /**
1002 Return vector of suitable signing certificates
1003
1004 \since 21.01
1005 */
1006 QVector<CertificateInfo> POPPLER_QT6_EXPORT getAvailableSigningCertificates();
1007
1008 /**
1009 Gets the current NSS CertDB directory
1010
1011 \since 21.01
1012 */
1013 QString POPPLER_QT6_EXPORT getNSSDir();
1014
1015 /**
1016 Set a custom NSS CertDB directory. Needs to be called before doing any other signature operation
1017
1018 \since 21.01
1019 */
1020 void POPPLER_QT6_EXPORT setNSSDir(const QString &pathURL);
1021
1022 /**
1023 Sets the callback for NSS password requests
1024
1025 \since 21.01
1026 */
1027 void POPPLER_QT6_EXPORT setNSSPasswordCallback(const std::function<char *(const char *)> &f);
1028
1029 /**
1030 * Allow pgp signatures in pdf files (standard-extension, experimental)
1031 * Not supported for NSS backend
1032 *
1033 * \param allowed new value for pgp signatures allowed
1034 *
1035 * \since 25.03
1036 */
1037 void POPPLER_QT6_EXPORT setPgpSignaturesAllowed(bool allowed);
1038
1039 /**
1040 * \returns if pgp signatures are allowed.
1041 *
1042 * \since 25.03
1043 */
1044 bool POPPLER_QT6_EXPORT arePgpSignaturesAllowed();
1045 }
1046
1047 #endif