File indexing completed on 2024-04-21 04:57:04

0001 /**************************************************************************
0002  *   Copyright (C) 2009-2011 Matthias Fuchs <mat69@gmx.net>                *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or modify  *
0005  *   it under the terms of the GNU General Public License as published by  *
0006  *   the Free Software Foundation; either version 2 of the License, or     *
0007  *   (at your option) any later version.                                   *
0008  *                                                                         *
0009  *   This program is distributed in the hope that it will be useful,       *
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0012  *   GNU General Public License for more details.                          *
0013  *                                                                         *
0014  *   You should have received a copy of the GNU General Public License     *
0015  *   along with this program; if not, write to the                         *
0016  *   Free Software Foundation, Inc.,                                       *
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
0018  ***************************************************************************/
0019 
0020 #ifndef KGET_SIGNATURE_H
0021 #define KGET_SIGNATURE_H
0022 
0023 #include "kget_export.h"
0024 
0025 #include <QObject>
0026 #include <QUrl>
0027 
0028 class QDomElement;
0029 
0030 #ifdef HAVE_QGPGME
0031 #include <gpgme++/verificationresult.h>
0032 #endif // HAVE_QGPGME
0033 
0034 /**
0035  * @class Signature
0036  *
0037  * @short Class to verify signatures
0038  */
0039 class KGET_EXPORT Signature : public QObject
0040 {
0041     Q_OBJECT
0042 
0043     friend class KeyDownloader;
0044     friend class SignatureThread;
0045 
0046     // TODO also support verification and decryption of files that contain the signature?
0047 public:
0048     explicit Signature(const QUrl &dest, QObject *object = nullptr);
0049     ~Signature() override;
0050 
0051     enum SignatureType {
0052         NoType = 0,
0053         AsciiDetached, //.asc
0054         BinaryDetached //.sig
0055     };
0056 
0057     enum VerificationStatus {
0058         NoResult, // either not tried, or not enough information
0059         NotWorked, // something during verification failed
0060         NotVerified,
0061         Verified,
0062         VerifiedInformation, // verified, though the there is some additional information
0063         VerifiedWarning // verified, though there is a warning
0064     };
0065 
0066     QUrl destination() const;
0067     void setDestination(const QUrl &destination);
0068 
0069     VerificationStatus status() const;
0070 #ifdef HAVE_QGPGME
0071     GpgME::VerificationResult verificationResult();
0072 #endif // HAVE_QGPGME
0073 
0074     void downloadKey(QString fingerprint);
0075     QByteArray signature();
0076     void setAsciiDetachedSignature(const QString &signature);
0077     void setSignature(const QByteArray &signature, SignatureType type);
0078 
0079     SignatureType type() const;
0080 
0081     /**
0082      * The fingerprint of the signature//TODO get even without verification??
0083      */
0084     QString fingerprint();
0085     bool isVerifyable();
0086     void verify();
0087 
0088     void save(const QDomElement &element);
0089     void load(const QDomElement &e);
0090 
0091 Q_SIGNALS:
0092     void verified(int verificationStatus);
0093 
0094 private Q_SLOTS:
0095 #ifdef HAVE_QGPGME
0096     void slotVerified(const GpgME::VerificationResult &result);
0097 #endif // HAVE_QGPGME
0098 
0099 private:
0100     class SignaturePrivate *d;
0101 
0102     friend class SignaturePrivate;
0103 };
0104 
0105 #endif