LCOV - code coverage report
Current view: top level - lang/qt/src - protocol_p.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 41 184 22.3 %
Date: 2016-09-12 13:07:23 Functions: 7 36 19.4 %

          Line data    Source code
       1             : /*
       2             :     protocol_p.h
       3             : 
       4             :     This file is part of qgpgme, the Qt API binding for gpgme
       5             :     Copyright (c) 2004,2005 Klarälvdalens Datakonsult AB
       6             :     Copyright (c) 2016 Intevation GmbH
       7             : 
       8             :     QGpgME is free software; you can redistribute it and/or
       9             :     modify it under the terms of the GNU General Public License as
      10             :     published by the Free Software Foundation; either version 2 of the
      11             :     License, or (at your option) any later version.
      12             : 
      13             :     QGpgME is distributed in the hope that it will be useful,
      14             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16             :     General Public License for more details.
      17             : 
      18             :     You should have received a copy of the GNU General Public License
      19             :     along with this program; if not, write to the Free Software
      20             :     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
      21             : 
      22             :     In addition, as a special exception, the copyright holders give
      23             :     permission to link the code of this program with any edition of
      24             :     the Qt library by Trolltech AS, Norway (or with modified versions
      25             :     of Qt that use the same license as Qt), and distribute linked
      26             :     combinations including the two.  You must obey the GNU General
      27             :     Public License in all respects for all of the code used other than
      28             :     Qt.  If you modify this file, you may extend this exception to
      29             :     your version of the file, but you are not obligated to do so.  If
      30             :     you do not wish to do so, delete this exception statement from
      31             :     your version.
      32             : */
      33             : #ifndef __QGPGME_PROTOCOL_P_H__
      34             : #define __QGPGME_PROTOCOL_P_H__
      35             : #include "qgpgmenewcryptoconfig.h"
      36             : 
      37             : #include "qgpgmekeygenerationjob.h"
      38             : #include "qgpgmekeylistjob.h"
      39             : #include "qgpgmelistallkeysjob.h"
      40             : #include "qgpgmedecryptjob.h"
      41             : #include "qgpgmedecryptverifyjob.h"
      42             : #include "qgpgmerefreshkeysjob.h"
      43             : #include "qgpgmedeletejob.h"
      44             : #include "qgpgmesecretkeyexportjob.h"
      45             : #include "qgpgmedownloadjob.h"
      46             : #include "qgpgmesignencryptjob.h"
      47             : #include "qgpgmeencryptjob.h"
      48             : #include "qgpgmesignjob.h"
      49             : #include "qgpgmesignkeyjob.h"
      50             : #include "qgpgmeexportjob.h"
      51             : #include "qgpgmeverifydetachedjob.h"
      52             : #include "qgpgmeimportjob.h"
      53             : #include "qgpgmeimportfromkeyserverjob.h"
      54             : #include "qgpgmeverifyopaquejob.h"
      55             : #include "qgpgmechangeexpiryjob.h"
      56             : #include "qgpgmechangeownertrustjob.h"
      57             : #include "qgpgmechangepasswdjob.h"
      58             : #include "qgpgmeadduseridjob.h"
      59             : #include "qgpgmekeyformailboxjob.h"
      60             : #include "qgpgmewkspublishjob.h"
      61             : 
      62             : namespace
      63             : {
      64             : 
      65           0 : class Protocol : public QGpgME::Protocol
      66             : {
      67             :     GpgME::Protocol mProtocol;
      68             : public:
      69           6 :     explicit Protocol(GpgME::Protocol proto) : mProtocol(proto) {}
      70             : 
      71           0 :     QString name() const Q_DECL_OVERRIDE
      72             :     {
      73           0 :         switch (mProtocol) {
      74           0 :         case GpgME::OpenPGP: return QStringLiteral("OpenPGP");
      75           0 :         case GpgME::CMS:     return QStringLiteral("SMIME");
      76           0 :         default:             return QString();
      77             :         }
      78             :     }
      79             : 
      80           0 :     QString displayName() const Q_DECL_OVERRIDE
      81             :     {
      82             :         // ah (2.4.16): Where is this used and isn't this inverted
      83             :         // with name
      84           0 :         switch (mProtocol) {
      85           0 :         case GpgME::OpenPGP: return QStringLiteral("gpg");
      86           0 :         case GpgME::CMS:     return QStringLiteral("gpgsm");
      87           0 :         default:             return QStringLiteral("unknown");
      88             :         }
      89             :     }
      90             : 
      91           0 :     QGpgME::SpecialJob *specialJob(const char *, const QMap<QString, QVariant> &) const Q_DECL_OVERRIDE
      92             :     {
      93           0 :         return 0;
      94             :     }
      95             : 
      96          10 :     QGpgME::KeyListJob *keyListJob(bool remote, bool includeSigs, bool validate) const Q_DECL_OVERRIDE
      97             :     {
      98          10 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
      99          10 :         if (!context) {
     100           0 :             return 0;
     101             :         }
     102             : 
     103          10 :         unsigned int mode = context->keyListMode();
     104          10 :         if (remote) {
     105           0 :             mode |= GpgME::Extern;
     106           0 :             mode &= ~GpgME::Local;
     107             :         } else {
     108          10 :             mode |= GpgME::Local;
     109          10 :             mode &= ~GpgME::Extern;
     110             :         }
     111          10 :         if (includeSigs) {
     112           3 :             mode |= GpgME::Signatures;
     113             :         }
     114          10 :         if (validate) {
     115           3 :             mode |= GpgME::Validate;
     116             :         }
     117          10 :         context->setKeyListMode(mode);
     118          10 :         return new QGpgME::QGpgMEKeyListJob(context);
     119             :     }
     120             : 
     121           0 :     QGpgME::ListAllKeysJob *listAllKeysJob(bool includeSigs, bool validate) const Q_DECL_OVERRIDE
     122             :     {
     123           0 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     124           0 :         if (!context) {
     125           0 :             return 0;
     126             :         }
     127             : 
     128           0 :         unsigned int mode = context->keyListMode();
     129           0 :         mode |= GpgME::Local;
     130           0 :         mode &= ~GpgME::Extern;
     131           0 :         if (includeSigs) {
     132           0 :             mode |= GpgME::Signatures;
     133             :         }
     134           0 :         if (validate) {
     135           0 :             mode |= GpgME::Validate;
     136             :             /* Setting the context to offline mode disables CRL / OCSP checks in
     137             :                this Job. Otherwise we would try to fetch the CRL's for all CMS
     138             :                keys in the users keyring because GpgME::Validate includes remote
     139             :                resources by default in the validity check.
     140             :                This setting only has any effect if gpgsm >= 2.1.6 is used.
     141             :                */
     142           0 :             context->setOffline(true);
     143             :         }
     144           0 :         context->setKeyListMode(mode);
     145           0 :         return new QGpgME::QGpgMEListAllKeysJob(context);
     146             :     }
     147             : 
     148           2 :     QGpgME::EncryptJob *encryptJob(bool armor, bool textmode) const Q_DECL_OVERRIDE
     149             :     {
     150           2 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     151           2 :         if (!context) {
     152           0 :             return 0;
     153             :         }
     154             : 
     155           2 :         context->setArmor(armor);
     156           2 :         context->setTextMode(textmode);
     157           2 :         return new QGpgME::QGpgMEEncryptJob(context);
     158             :     }
     159             : 
     160           0 :     QGpgME::DecryptJob *decryptJob() const Q_DECL_OVERRIDE
     161             :     {
     162           0 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     163           0 :         if (!context) {
     164           0 :             return 0;
     165             :         }
     166           0 :         return new QGpgME::QGpgMEDecryptJob(context);
     167             :     }
     168             : 
     169           0 :     QGpgME::SignJob *signJob(bool armor, bool textMode) const Q_DECL_OVERRIDE
     170             :     {
     171           0 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     172           0 :         if (!context) {
     173           0 :             return 0;
     174             :         }
     175             : 
     176           0 :         context->setArmor(armor);
     177           0 :         context->setTextMode(textMode);
     178           0 :         return new QGpgME::QGpgMESignJob(context);
     179             :     }
     180             : 
     181           0 :     QGpgME::VerifyDetachedJob *verifyDetachedJob(bool textMode) const Q_DECL_OVERRIDE
     182             :     {
     183           0 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     184           0 :         if (!context) {
     185           0 :             return 0;
     186             :         }
     187             : 
     188           0 :         context->setTextMode(textMode);
     189           0 :         return new QGpgME::QGpgMEVerifyDetachedJob(context);
     190             :     }
     191             : 
     192           9 :     QGpgME::VerifyOpaqueJob *verifyOpaqueJob(bool textMode) const Q_DECL_OVERRIDE
     193             :     {
     194           9 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     195           9 :         if (!context) {
     196           0 :             return 0;
     197             :         }
     198             : 
     199           9 :         context->setTextMode(textMode);
     200           9 :         return new QGpgME::QGpgMEVerifyOpaqueJob(context);
     201             :     }
     202             : 
     203           0 :     QGpgME::KeyGenerationJob *keyGenerationJob() const Q_DECL_OVERRIDE
     204             :     {
     205           0 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     206           0 :         if (!context) {
     207           0 :             return 0;
     208             :         }
     209           0 :         return new QGpgME::QGpgMEKeyGenerationJob(context);
     210             :     }
     211             : 
     212           0 :     QGpgME::ImportJob *importJob() const Q_DECL_OVERRIDE
     213             :     {
     214           0 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     215           0 :         if (!context) {
     216           0 :             return 0;
     217             :         }
     218           0 :         return new QGpgME::QGpgMEImportJob(context);
     219             :     }
     220             : 
     221           0 :     QGpgME::ImportFromKeyserverJob *importFromKeyserverJob() const Q_DECL_OVERRIDE
     222             :     {
     223           0 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     224           0 :         if (!context) {
     225           0 :             return 0;
     226             :         }
     227           0 :         return new QGpgME::QGpgMEImportFromKeyserverJob(context);
     228             :     }
     229             : 
     230           0 :     QGpgME::ExportJob *publicKeyExportJob(bool armor) const Q_DECL_OVERRIDE
     231             :     {
     232           0 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     233           0 :         if (!context) {
     234           0 :             return 0;
     235             :         }
     236             : 
     237           0 :         context->setArmor(armor);
     238           0 :         return new QGpgME::QGpgMEExportJob(context);
     239             :     }
     240             : 
     241           0 :     QGpgME::ExportJob *secretKeyExportJob(bool armor, const QString &charset) const Q_DECL_OVERRIDE
     242             :     {
     243           0 :         if (mProtocol != GpgME::CMS) { // fixme: add support for gpg, too
     244           0 :             return 0;
     245             :         }
     246             : 
     247             :         // this operation is not supported by gpgme, so we have to call gpgsm ourselves:
     248           0 :         return new QGpgME::QGpgMESecretKeyExportJob(armor, charset);
     249             :     }
     250             : 
     251           0 :     QGpgME::RefreshKeysJob *refreshKeysJob() const Q_DECL_OVERRIDE
     252             :     {
     253           0 :         if (mProtocol != GpgME::CMS) { // fixme: add support for gpg, too
     254           0 :             return 0;
     255             :         }
     256             : 
     257             :         // this operation is not supported by gpgme, so we have to call gpgsm ourselves:
     258           0 :         return new QGpgME::QGpgMERefreshKeysJob();
     259             :     }
     260             : 
     261           0 :     QGpgME::DownloadJob *downloadJob(bool armor) const Q_DECL_OVERRIDE
     262             :     {
     263           0 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     264           0 :         if (!context) {
     265           0 :             return 0;
     266             :         }
     267             : 
     268           0 :         context->setArmor(armor);
     269             :         // this is the hackish interface for downloading from keyserers currently:
     270           0 :         context->setKeyListMode(GpgME::Extern);
     271           0 :         return new QGpgME::QGpgMEDownloadJob(context);
     272             :     }
     273             : 
     274           0 :     QGpgME::DeleteJob *deleteJob() const Q_DECL_OVERRIDE
     275             :     {
     276           0 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     277           0 :         if (!context) {
     278           0 :             return 0;
     279             :         }
     280           0 :         return new QGpgME::QGpgMEDeleteJob(context);
     281             :     }
     282             : 
     283           0 :     QGpgME::SignEncryptJob *signEncryptJob(bool armor, bool textMode) const Q_DECL_OVERRIDE
     284             :     {
     285           0 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     286           0 :         if (!context) {
     287           0 :             return 0;
     288             :         }
     289             : 
     290           0 :         context->setArmor(armor);
     291           0 :         context->setTextMode(textMode);
     292           0 :         return new QGpgME::QGpgMESignEncryptJob(context);
     293             :     }
     294             : 
     295           0 :     QGpgME::DecryptVerifyJob *decryptVerifyJob(bool textMode) const Q_DECL_OVERRIDE
     296             :     {
     297           0 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     298           0 :         if (!context) {
     299           0 :             return 0;
     300             :         }
     301             : 
     302           0 :         context->setTextMode(textMode);
     303           0 :         return new QGpgME::QGpgMEDecryptVerifyJob(context);
     304             :     }
     305             : 
     306           0 :     QGpgME::ChangeExpiryJob *changeExpiryJob() const Q_DECL_OVERRIDE
     307             :     {
     308           0 :         if (mProtocol != GpgME::OpenPGP) {
     309           0 :             return 0;    // only supported by gpg
     310             :         }
     311             : 
     312           0 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     313           0 :         if (!context) {
     314           0 :             return 0;
     315             :         }
     316           0 :         return new QGpgME::QGpgMEChangeExpiryJob(context);
     317             :     }
     318             : 
     319           0 :     QGpgME::ChangePasswdJob *changePasswdJob() const Q_DECL_OVERRIDE
     320             :     {
     321           0 :         if (!GpgME::hasFeature(GpgME::PasswdFeature, 0)) {
     322           0 :             return 0;
     323             :         }
     324           0 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     325           0 :         if (!context) {
     326           0 :             return 0;
     327             :         }
     328           0 :         return new QGpgME::QGpgMEChangePasswdJob(context);
     329             :     }
     330             : 
     331           0 :     QGpgME::SignKeyJob *signKeyJob() const Q_DECL_OVERRIDE
     332             :     {
     333           0 :         if (mProtocol != GpgME::OpenPGP) {
     334           0 :             return 0;    // only supported by gpg
     335             :         }
     336             : 
     337           0 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     338           0 :         if (!context) {
     339           0 :             return 0;
     340             :         }
     341           0 :         return new QGpgME::QGpgMESignKeyJob(context);
     342             :     }
     343             : 
     344           2 :     QGpgME::ChangeOwnerTrustJob *changeOwnerTrustJob() const Q_DECL_OVERRIDE
     345             :     {
     346           2 :         if (mProtocol != GpgME::OpenPGP) {
     347           0 :             return 0;    // only supported by gpg
     348             :         }
     349             : 
     350           2 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     351           2 :         if (!context) {
     352           0 :             return 0;
     353             :         }
     354           2 :         return new QGpgME::QGpgMEChangeOwnerTrustJob(context);
     355             :     }
     356             : 
     357           0 :     QGpgME::AddUserIDJob *addUserIDJob() const Q_DECL_OVERRIDE
     358             :     {
     359           0 :         if (mProtocol != GpgME::OpenPGP) {
     360           0 :             return 0;    // only supported by gpg
     361             :         }
     362             : 
     363           0 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     364           0 :         if (!context) {
     365           0 :             return 0;
     366             :         }
     367           0 :         return new QGpgME::QGpgMEAddUserIDJob(context);
     368             :     }
     369             : 
     370           1 :     QGpgME::KeyListJob *locateKeysJob() const Q_DECL_OVERRIDE
     371             :     {
     372           1 :         if (mProtocol != GpgME::OpenPGP) {
     373           0 :             return Q_NULLPTR;
     374             :         }
     375           1 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     376           1 :         if (!context) {
     377           0 :             return Q_NULLPTR;
     378             :         }
     379           1 :         context->setKeyListMode(GpgME::Extern | GpgME::Local | GpgME::Signatures | GpgME::Validate);
     380           1 :         return new QGpgME::QGpgMEKeyListJob(context);
     381             :     }
     382             : 
     383           0 :     QGpgME::KeyForMailboxJob *keyForMailboxJob() const Q_DECL_OVERRIDE
     384             :     {
     385           0 :         GpgME::Context *context = GpgME::Context::createForProtocol(mProtocol);
     386           0 :         if (!context) {
     387           0 :             return Q_NULLPTR;
     388             :         }
     389           0 :         return new QGpgME::QGpgMEKeyForMailboxJob(context);
     390             :     }
     391             : 
     392           1 :     QGpgME::WKSPublishJob *wksPublishJob() const Q_DECL_OVERRIDE
     393             :     {
     394           1 :         if (mProtocol != GpgME::OpenPGP) {
     395           0 :             return Q_NULLPTR;
     396             :         }
     397           1 :         auto context = GpgME::Context::createForEngine(GpgME::SpawnEngine);
     398           1 :         if (!context) {
     399           0 :             return Q_NULLPTR;
     400             :         }
     401           1 :         return new QGpgME::QGpgMEWKSPublishJob(context.release());
     402             :     }
     403             : };
     404             : 
     405             : }
     406             : #endif

Generated by: LCOV version 1.11