File indexing completed on 2024-04-21 05:50:44
0001 /* 0002 SPDX-FileCopyrightText: 2012-2022 Rolf Eike Beer <kde@opensource.sf-tec.de> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef KGPGVERIFY_H 0007 #define KGPGVERIFY_H 0008 0009 #include "kgpgtextorfiletransaction.h" 0010 0011 #include <QObject> 0012 #include <QString> 0013 #include <QStringList> 0014 0015 #include <QUrl> 0016 0017 class KGpgItemModel; 0018 0019 /** 0020 * @brief verify the signature of the given text or files 0021 */ 0022 class KGpgVerify: public KGpgTextOrFileTransaction { 0023 Q_OBJECT 0024 0025 Q_DISABLE_COPY(KGpgVerify) 0026 KGpgVerify() = delete; 0027 public: 0028 enum ts_verify { 0029 TS_MISSING_KEY = KGpgTransaction::TS_COMMON_END + 1, ///< signing key not in keyring 0030 TS_BAD_SIGNATURE = TS_MISSING_KEY + 1 ///< the file is signed, but the signature is invalid 0031 }; 0032 0033 /** 0034 * @brief verify signature of given text 0035 * @param parent parent object 0036 * @param text text to verify 0037 */ 0038 explicit KGpgVerify(QObject *parent, const QString &text = QString()); 0039 0040 /** 0041 * @brief verify signatures of file(s) 0042 * @param parent parent object 0043 * @param files list of file locations to verify 0044 */ 0045 KGpgVerify(QObject *parent, const QList<QUrl> &files); 0046 0047 /** 0048 * @brief destructor 0049 */ 0050 ~KGpgVerify() override = default; 0051 0052 /** 0053 * @brief get verification report 0054 * @param log the log lines to scan 0055 * @param model key model to use for key lookups 0056 * @return verification report of GnuPG 0057 */ 0058 static QString getReport(const QStringList &log, const KGpgItemModel *model = nullptr); 0059 0060 /** 0061 * @brief get the missing key id 0062 * @return key id that signed the message 0063 * 0064 * This is only valid if the transaction returned with result 0065 * TS_MISSING_KEY. 0066 */ 0067 QString missingId() const; 0068 0069 protected: 0070 QStringList command() const override; 0071 bool nextLine(const QString &line) override; 0072 void finish() override; 0073 0074 private: 0075 int m_fileIndex; 0076 QString m_currentFile; 0077 QStringList m_report; 0078 QString m_missingId; 0079 }; 0080 0081 #endif // KGPGVERIFY_H