File indexing completed on 2022-09-27 16:32:25

0001 /*
0002     SPDX-FileCopyrightText: 2011, 2012, 2013 Rolf Eike Beer <kde@opensource.sf-tec.de>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef KGPGENCRYPT_H
0007 #define KGPGENCRYPT_H
0008 
0009 #include <QObject>
0010 #include <QString>
0011 #include <QStringList>
0012 
0013 #include <QUrl>
0014 
0015 #include "kgpgtextorfiletransaction.h"
0016 
0017 /**
0018  * @brief encrypt the given text or files
0019  */
0020 class KGpgEncrypt: public KGpgTextOrFileTransaction {
0021     Q_OBJECT
0022 
0023     Q_DISABLE_COPY(KGpgEncrypt)
0024     KGpgEncrypt() = delete;
0025 public:
0026     enum EncryptOption {
0027         DefaultEncryption = 0,      ///< use whatever GnuPGs defaults are
0028         AsciiArmored = 0x1,     ///< output the data as printable ASCII as opposed to binary data
0029         AllowUntrustedEncryption = 0x2, ///< allow encryption with untrusted keys, ignored for symmetric encryption
0030         HideKeyId = 0x4         ///< remove anything that shows which key ids this data is encrypted to, ignored for symmetric encryption
0031     };
0032         Q_DECLARE_FLAGS(EncryptOptions, EncryptOption)
0033 
0034     /**
0035      * @brief encrypt given text
0036      * @param parent parent object
0037      * @param userIds ids to encrypt to or empty list to use symmetric encryption with passphrase
0038      * @param text text to encrypt
0039      * @param options encryption options
0040      * @param extraOptions extra encryption options
0041      */
0042     explicit KGpgEncrypt(QObject *parent, const QStringList &userIds = QStringList(), const QString &text = QString(), const EncryptOptions &options = DefaultEncryption, const QStringList &extraOptions = QStringList());
0043 
0044     /**
0045      * @brief encrypt file(s)
0046      * @param parent parent object
0047      * @param userIds ids to encrypt to or empty list to use symmetric encryption with passphrase
0048      * @param files list of file locations to encrypt
0049      * @param options encryption options
0050      * @param extraOptions extra encryption options
0051      */
0052     KGpgEncrypt(QObject *parent, const QStringList &userIds, const QList<QUrl> &files, const EncryptOptions &options = DefaultEncryption, const QStringList &extraOptions = QStringList());
0053 
0054     /**
0055      * @brief destructor
0056      */
0057     ~KGpgEncrypt() override;
0058 
0059     /**
0060      * @brief get decryption result
0061      * @return decrypted text
0062      */
0063     QStringList encryptedText() const;
0064 
0065     /**
0066      * @brief return the preferred extension for encrypted files
0067      * @param ascii if the file is encrypted with ASCII armor
0068      * @return the file extension with leading dot
0069      */
0070     static QString encryptExtension(const bool ascii);
0071 
0072 protected:
0073     QStringList command() const override;
0074     bool nextLine(const QString &line) override;
0075     ts_boolanswer confirmOverwrite (QUrl &currentFile) override;
0076 
0077 private:
0078     int m_fileIndex;
0079     const EncryptOptions m_options;
0080     const QStringList m_userIds;
0081     QStringList m_extraOptions;
0082     QString m_currentFile;
0083 };
0084 
0085 Q_DECLARE_OPERATORS_FOR_FLAGS(KGpgEncrypt::EncryptOptions)
0086 
0087 #endif // KGPGENCRYPT_H