File indexing completed on 2024-06-23 05:13:52
0001 /* crypto/gui/signencryptwidget.h 0002 0003 This file is part of Kleopatra, the KDE keymanager 0004 SPDX-FileCopyrightText: 2016 Bundesamt für Sicherheit in der Informationstechnik 0005 SPDX-FileContributor: Intevation GmbH 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #pragma once 0010 0011 #include <QList> 0012 #include <QWidget> 0013 0014 #include <gpgme++/global.h> 0015 0016 #include <memory> 0017 0018 namespace GpgME 0019 { 0020 class Key; 0021 } 0022 0023 namespace Kleo 0024 { 0025 class CertificateLineEdit; 0026 class KeyGroup; 0027 0028 class SignEncryptWidget : public QWidget 0029 { 0030 Q_OBJECT 0031 public: 0032 enum Operation { NoOperation = 0x00, Sign = 0x01, Encrypt = 0x02, SignAndEncrypt = Sign | Encrypt }; 0033 Q_DECLARE_FLAGS(Operations, Operation) 0034 0035 /** If cmsSigEncExclusive is true CMS operations can be 0036 * done only either as sign or as encrypt */ 0037 explicit SignEncryptWidget(QWidget *parent = nullptr, bool cmsSigEncExclusive = false); 0038 0039 ~SignEncryptWidget() override; 0040 0041 /** Overwrite default text with custom text, e.g. with a character marked 0042 * as shortcut key. */ 0043 void setSignAsText(const QString &text); 0044 void setEncryptForMeText(const QString &text); 0045 void setEncryptForOthersText(const QString &text); 0046 void setEncryptWithPasswordText(const QString &text); 0047 0048 /** Returns the list of recipients selected in the dialog 0049 * or an empty list if encryption is disabled */ 0050 std::vector<GpgME::Key> recipients() const; 0051 0052 /** Returns the selected signing key or a null key if signing 0053 * is disabled. */ 0054 GpgME::Key signKey() const; 0055 0056 /** Returns the selected encrypt to self key or a null key if 0057 * encrypt to self is disabled. */ 0058 GpgME::Key selfKey() const; 0059 0060 /** Returns the operation based on the current selection. */ 0061 Operations currentOp() const; 0062 0063 /** Whether or not symmetric encryption should also be used. */ 0064 bool encryptSymmetric() const; 0065 0066 /** Save the currently selected signing and encrypt to self keys. */ 0067 void saveOwnKeys() const; 0068 0069 /** Return whether or not all keys involved in the operation are 0070 compliant with CO_DE_VS, and all keys are valid (i.e. all 0071 userIDs have Validity >= Full). */ 0072 bool isDeVsAndValid() const; 0073 0074 /** Set whether or not signing group should be checked */ 0075 void setSigningChecked(bool value); 0076 0077 /** Set whether or not encryption group should be checked */ 0078 void setEncryptionChecked(bool value); 0079 0080 /** Filter for a specific protocol. Use UnknownProtocol for both 0081 * S/MIME and OpenPGP */ 0082 void setProtocol(GpgME::Protocol protocol); 0083 0084 /** Add a recipient with the key key */ 0085 void addRecipient(const GpgME::Key &key); 0086 0087 /** Add a group of recipients */ 0088 void addRecipient(const Kleo::KeyGroup &group); 0089 0090 /** Add a placehoder for an unknown key */ 0091 void addUnknownRecipient(const char *keyId); 0092 0093 /** Remove all Recipients added by keyId or by key. */ 0094 void clearAddedRecipients(); 0095 0096 /** Remove a Recipient key */ 0097 void removeRecipient(const GpgME::Key &key); 0098 0099 /** Remove a recipient group */ 0100 void removeRecipient(const Kleo::KeyGroup &group); 0101 0102 /** Returns true if all required information has been entered. */ 0103 bool isComplete() const; 0104 0105 /** Returns true if all recipients have been resolved. Otherwise, shows 0106 an error message and returns false. */ 0107 bool validate(); 0108 0109 protected Q_SLOTS: 0110 void updateOp(); 0111 void recipientsChanged(); 0112 void certificateSelectionRequested(CertificateLineEdit *w); 0113 0114 protected: 0115 void loadKeys(); 0116 0117 Q_SIGNALS: 0118 /* Emitted when the certificate selection changed the operation 0119 * with that selection. e.g. "Sign" or "Sign/Encrypt". 0120 * If no crypto operation is selected this returns a null string. */ 0121 void operationChanged(Operations op); 0122 0123 /* Emitted when the certificate selection might be changed. */ 0124 void keysChanged(); 0125 0126 private: 0127 class Private; 0128 const std::unique_ptr<Private> d; 0129 }; 0130 0131 Q_DECLARE_OPERATORS_FOR_FLAGS(SignEncryptWidget::Operations) 0132 0133 } // namespace Kleo