File indexing completed on 2024-04-14 05:43:28

0001 /*
0002     SPDX-FileCopyrightText: 2010-2022 Rolf Eike Beer <kde@opensource.sf-tec.de>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef KGPGDECRYPT_H
0007 #define KGPGDECRYPT_H
0008 
0009 #include <QObject>
0010 
0011 #include <QUrl>
0012 #include <QStringList>
0013 #include "kgpgtextorfiletransaction.h"
0014 
0015 /**
0016  * @brief decrypt the given text or files
0017  */
0018 class KGpgDecrypt: public KGpgTextOrFileTransaction {
0019     Q_OBJECT
0020 
0021     Q_DISABLE_COPY(KGpgDecrypt)
0022     KGpgDecrypt() = delete;
0023 public:
0024     /**
0025      * @brief decrypt given text
0026      * @param parent parent object
0027      * @param text text to decrypt
0028      */
0029     explicit KGpgDecrypt(QObject *parent, const QString &text = QString());
0030 
0031     /**
0032      * @brief decrypt file(s)
0033      * @param parent parent object
0034      * @param files list of file locations to decrypt
0035      */
0036     KGpgDecrypt(QObject *parent, const QList<QUrl> &files);
0037 
0038     /**
0039      * @brief decrypt file to given output filename
0040      * @param parent parent object
0041      * @param infile name of file to decrypt
0042      * @param outfile name of file to write output to (will be overwritten)
0043      */
0044     KGpgDecrypt(QObject *parent, const QUrl &infile, const QUrl &outfile);
0045 
0046     /**
0047      * @brief destructor
0048      */
0049     ~KGpgDecrypt() override = default;
0050 
0051     /**
0052      * @brief get decryption result
0053      * @return decrypted text
0054      */
0055     QStringList decryptedText() const;
0056 
0057     /**
0058      * @brief check if the given text contains an encoded message
0059      * @param text text to check
0060      * @param startPos if not nullptr start offset of encoded text will be returned here
0061      * @param endPos if not nullptr end offset of encoded text will be returned here
0062      */
0063     static bool isEncryptedText(const QString &text, int *startPos = nullptr, int *endPos = nullptr);
0064 
0065 protected:
0066     QStringList command() const override;
0067     bool nextLine(const QString &line) override;
0068     void finish() override;
0069     bool closeInputAfterText() const override;
0070 
0071 private:
0072     int m_fileIndex;
0073     int m_plainLength;  ///< length of decrypted plain text if given by GnuPG
0074     const QString m_outFilename;    ///< name of file to write output to
0075     bool decryptSuccess = false; //< flag to determine if decryption succeeded
0076 };
0077 
0078 #endif // KGPGDECRYPT_H