File indexing completed on 2024-04-28 09:46:04
0001 /* 0002 SPDX-FileCopyrightText: 2008-2022 Rolf Eike Beer <kde@opensource.sf-tec.de> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef KGPGGENERATEKEY_H 0007 #define KGPGGENERATEKEY_H 0008 0009 #include "kgpgtransaction.h" 0010 0011 #include "core/kgpgkey.h" 0012 0013 #include <QObject> 0014 #include <QString> 0015 #include <QStringList> 0016 0017 /** 0018 * @brief generate a new key pair 0019 */ 0020 class KGpgGenerateKey: public KGpgTransaction { 0021 Q_OBJECT 0022 0023 Q_DISABLE_COPY(KGpgGenerateKey) 0024 KGpgGenerateKey() = delete; 0025 public: 0026 enum ts_generatekey { 0027 TS_INVALID_NAME = TS_COMMON_END + 1 ///< the owners name is not accepted by GnuPG 0028 }; 0029 0030 /** 0031 * @brief KGpgGenerateKey's constructor 0032 * @param parent parent object 0033 * @param name the name of the key, it is also the user's name. 0034 * @param email email MUST be a valid email address or an empty string. 0035 * @param comment is a comment, it can be an empty string 0036 * @param algorithm this is the type of the key, RSA or DSA & ELGAMAL (\see Kgpg::KeyAlgo ). 0037 * @param size this is the length of the key (1024, 2048, ...) 0038 * @param expire defines the key expiry time together with \em expireunit, 0 for unlimited key lifetime 0039 * @param expireunit is the unit of the number given as \em expire. Valid units are 'd', 'w', 'm' and 'y'. The unit is ignored if expire is 0. 0040 * @param capabilities capabilities for the primary key 0041 */ 0042 KGpgGenerateKey(QObject *parent, const QString &name, const QString &email, const QString &comment, 0043 const KgpgCore::KgpgKeyAlgo algorithm, const uint size, const unsigned int expire = 0, 0044 const char expireunit = 'd', const KgpgCore::KgpgSubKeyType capabilities = {}); 0045 ~KGpgGenerateKey() override = default; 0046 0047 QString getName() const; 0048 QString getEmail() const; 0049 0050 /** 0051 * @brief return the fingerprint of the generated key 0052 */ 0053 QString getFingerprint() const; 0054 0055 /** 0056 * @brief get error output of GnuPG 0057 * @return the messages GnuPG printed to standard error 0058 * 0059 * This will only return data after the done() signal has been emitted. 0060 */ 0061 QString gpgErrorMessage() const; 0062 0063 protected: 0064 bool preStart() override; 0065 void postStart() override; 0066 bool nextLine(const QString &line) override; 0067 void finish() override; 0068 void newPassphraseEntered() override; 0069 0070 private: 0071 const QString m_name; 0072 const QString m_email; 0073 const QString m_comment; 0074 const KgpgCore::KgpgKeyAlgo m_algorithm; 0075 const KgpgCore::KgpgSubKeyType m_capabilities; 0076 const unsigned int m_size; 0077 const unsigned int m_expire; 0078 const unsigned int m_expireunit; 0079 QString m_fingerprint; 0080 QStringList m_errorOutput; 0081 }; 0082 0083 #endif // KGPGGENERATEKEY_H