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

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 KGPGSIGNTEXT_H
0007 #define KGPGSIGNTEXT_H
0008 
0009 #include "kgpgtextorfiletransaction.h"
0010 
0011 #include <QUrl>
0012 #include <QObject>
0013 #include <QString>
0014 #include <QStringList>
0015 
0016 /**
0017  * @brief sign the given text or files
0018  */
0019 class KGpgSignText: public KGpgTextOrFileTransaction {
0020     Q_OBJECT
0021 
0022     Q_DISABLE_COPY(KGpgSignText)
0023     KGpgSignText() = delete;
0024 public:
0025     enum SignOption {
0026         DefaultSignature = 0,       ///< use whatever GnuPGs defaults are
0027         AsciiArmored = 0x1,     ///< output the data as printable ASCII as opposed to binary data
0028         DetachedSignature = 0x2,    ///< save the signature in a separate file
0029     };
0030         Q_DECLARE_FLAGS(SignOptions, SignOption)
0031 
0032     /**
0033      * @brief sign given text
0034      * @param parent parent object
0035      * @param signId the key to use for signing
0036      * @param text text to sign
0037      * @param options signing options
0038      * @param extraOptions extra signing options
0039      */
0040     KGpgSignText(QObject *parent, const QString &signId, const QString &text = QString(), const SignOptions &options = AsciiArmored, const QStringList &extraOptions = QStringList());
0041 
0042     /**
0043      * @brief sign file
0044      * @param parent parent object
0045      * @param signId the key to use for signing
0046      * @param files list of file locations to sign (must only be 1 file)
0047      * @param options signing options
0048      * @param extraOptions extra signing options
0049      *
0050      * @warning GnuPG can currently handle only one file per invocation for
0051      * signing, so files may only contain one single file.
0052      */
0053     KGpgSignText(QObject *parent, const QString &signId, const QList<QUrl> &files, const SignOptions &options = DefaultSignature, const QStringList &extraOptions = QStringList());
0054 
0055     /**
0056      * @brief destructor
0057      */
0058     ~KGpgSignText() override = default;
0059 
0060     /**
0061      * @brief get signing result
0062      * @return signed text
0063      */
0064     QStringList signedText() const;
0065 
0066 protected:
0067     QStringList command() const override;
0068 
0069 private:
0070     int m_fileIndex;
0071     const SignOptions m_options;
0072     const QString m_signId;
0073     QStringList m_extraOptions;
0074 };
0075 
0076 Q_DECLARE_OPERATORS_FOR_FLAGS(KGpgSignText::SignOptions)
0077 
0078 #endif // KGPGSIGNTEXT_H