1 /* 2 SPDX-FileCopyrightText: 2011, 2012, 2013 Rolf Eike Beer <kde@opensource.sf-tec.de> 3 SPDX-License-Identifier: GPL-2.0-or-later 4 */ 5 6 #ifndef KGPGENCRYPT_H 7 #define KGPGENCRYPT_H 8 9 #include <QObject> 10 #include <QString> 11 #include <QStringList> 12 13 #include <QUrl> 14 15 #include "kgpgtextorfiletransaction.h" 16 17 /** 18 * @brief encrypt the given text or files 19 */ 20 class KGpgEncrypt: public KGpgTextOrFileTransaction { 21 Q_OBJECT 22 23 Q_DISABLE_COPY(KGpgEncrypt) 24 KGpgEncrypt() = delete; 25 public: 26 enum EncryptOption { 27 DefaultEncryption = 0, ///< use whatever GnuPGs defaults are 28 AsciiArmored = 0x1, ///< output the data as printable ASCII as opposed to binary data 29 AllowUntrustedEncryption = 0x2, ///< allow encryption with untrusted keys, ignored for symmetric encryption 30 HideKeyId = 0x4 ///< remove anything that shows which key ids this data is encrypted to, ignored for symmetric encryption 31 }; 32 Q_DECLARE_FLAGS(EncryptOptions, EncryptOption) 33 34 /** 35 * @brief encrypt given text 36 * @param parent parent object 37 * @param userIds ids to encrypt to or empty list to use symmetric encryption with passphrase 38 * @param text text to encrypt 39 * @param options encryption options 40 * @param extraOptions extra encryption options 41 */ 42 explicit KGpgEncrypt(QObject *parent, const QStringList &userIds = QStringList(), const QString &text = QString(), const EncryptOptions &options = DefaultEncryption, const QStringList &extraOptions = QStringList()); 43 44 /** 45 * @brief encrypt file(s) 46 * @param parent parent object 47 * @param userIds ids to encrypt to or empty list to use symmetric encryption with passphrase 48 * @param files list of file locations to encrypt 49 * @param options encryption options 50 * @param extraOptions extra encryption options 51 */ 52 KGpgEncrypt(QObject *parent, const QStringList &userIds, const QList<QUrl> &files, const EncryptOptions &options = DefaultEncryption, const QStringList &extraOptions = QStringList()); 53 54 /** 55 * @brief destructor 56 */ 57 ~KGpgEncrypt() override; 58 59 /** 60 * @brief get decryption result 61 * @return decrypted text 62 */ 63 QStringList encryptedText() const; 64 65 /** 66 * @brief return the preferred extension for encrypted files 67 * @param ascii if the file is encrypted with ASCII armor 68 * @return the file extension with leading dot 69 */ 70 static QString encryptExtension(const bool ascii); 71 72 protected: 73 QStringList command() const override; 74 bool nextLine(const QString &line) override; 75 ts_boolanswer confirmOverwrite (QUrl ¤tFile) override; 76 77 private: 78 int m_fileIndex; 79 const EncryptOptions m_options; 80 const QStringList m_userIds; 81 QStringList m_extraOptions; 82 QString m_currentFile; 83 }; 84 85 Q_DECLARE_OPERATORS_FOR_FLAGS(KGpgEncrypt::EncryptOptions) 86 87 #endif // KGPGENCRYPT_H 88