File indexing completed on 2024-09-15 05:07:50
0001 /* 0002 SPDX-FileCopyrightText: 2009-2022 Rolf Eike Beer <kde@opensource.sf-tec.de> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef KGPGEXPORT_H 0007 #define KGPGEXPORT_H 0008 0009 #include <QObject> 0010 #include <QStringList> 0011 0012 #include "kgpgtransaction.h" 0013 0014 class QProcess; 0015 0016 /** 0017 * @brief export one or more keys from keyring 0018 * 0019 * The exported keys can be written to a file or sent to standard input of another 0020 * QProcess. 0021 */ 0022 class KGpgExport: public KGpgTransaction { 0023 Q_OBJECT 0024 0025 KGpgExport(); // = delete C++0x 0026 Q_DISABLE_COPY(KGpgExport) 0027 public: 0028 /** 0029 * @brief export keys to QProcess 0030 * @param parent parent object 0031 * @param ids ids to export 0032 * @param outp process to write into 0033 * @param options additional options to pass to GnuPG (e.g. export ascii armored) 0034 * @param secret if secret key exporting is allowed 0035 */ 0036 KGpgExport(QObject *parent, const QStringList &ids, QProcess *outp, const QStringList &options = QStringList(), const bool secret = false); 0037 0038 /** 0039 * @brief export keys to KGpgTransaction 0040 * @param parent parent object 0041 * @param ids ids to export 0042 * @param outt transaction to write into 0043 * @param options additional options to pass to GnuPG (e.g. export ascii armored) 0044 * @param secret if secret key exporting is allowed 0045 */ 0046 KGpgExport(QObject *parent, const QStringList &ids, KGpgTransaction *outt, const QStringList &options = QStringList(), const bool secret = false); 0047 0048 /** 0049 * @brief export keys to file 0050 * @param parent parent object 0051 * @param ids ids to export 0052 * @param file filename to write into 0053 * @param options additional options to pass to GnuPG (e.g. export ascii armored) 0054 * @param secret if secret key exporting is allowed 0055 */ 0056 KGpgExport(QObject *parent, const QStringList &ids, const QString &file, const QStringList &options = QStringList(), const bool secret = false); 0057 0058 /** 0059 * @brief export keys to standard output 0060 * @param parent parent object 0061 * @param ids ids to export 0062 * @param options additional options to pass to GnuPG (e.g. export ascii armored) 0063 * @param secret if secret key exporting is allowed 0064 * 0065 * Only ascii-armored export is supported in standard output mode. If it is not 0066 * already set in the given option it will be added automatically. 0067 */ 0068 KGpgExport(QObject *parent, const QStringList &ids, const QStringList &options = QStringList(), const bool secret = false); 0069 0070 /** 0071 * @brief destructor 0072 */ 0073 ~KGpgExport() override = default; 0074 0075 /** 0076 * @brief set key id to export 0077 * @param id key fingerprint 0078 */ 0079 void setKeyId(const QString &id); 0080 /** 0081 * @brief set key ids to export 0082 * @param ids key fingerprints 0083 */ 0084 void setKeyIds(const QStringList &ids); 0085 /** 0086 * @brief return the key ids to export 0087 * @return list of key fingerprints 0088 */ 0089 const QStringList &getKeyIds() const; 0090 /** 0091 * @brief set the process the output is sent to 0092 * @param outp process to send output to 0093 */ 0094 void setOutputProcess(QProcess *outp); 0095 /** 0096 * @brief set the transaction the output is sent to 0097 * @param outt transaction to send output to 0098 */ 0099 void setOutputTransaction(KGpgTransaction *outt); 0100 /** 0101 * @brief set filename to send output to 0102 * @param filename file to send output to 0103 */ 0104 void setOutputFile(const QString &filename); 0105 /** 0106 * @brief return the output filename currently set 0107 * @return filename key will get written to 0108 */ 0109 const QString &getOutputFile() const; 0110 /** 0111 * @brief return the data read from standard output 0112 * @return standard output data 0113 */ 0114 const QByteArray &getOutputData() const; 0115 0116 protected: 0117 bool preStart() override; 0118 bool nextLine(const QString &line) override; 0119 0120 private: 0121 QStringList m_keyids; 0122 QProcess *m_outp; 0123 QString m_outf; 0124 QByteArray m_data; 0125 0126 enum OutputMode { 0127 ModeFile = 0, 0128 ModeProcess = 1, 0129 ModeStdout = 2, 0130 ModeTransaction = 3 0131 }; 0132 enum OutputMode m_outputmode; 0133 0134 void procSetup(const QStringList &options, const bool secret); 0135 }; 0136 0137 #endif // KGPGEXPORT_H