LCOV - code coverage report
Current view: top level - lang/qt/src - qgpgmedecryptverifyjob.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 49 0.0 %
Date: 2016-11-29 15:07:43 Functions: 0 9 0.0 %

          Line data    Source code
       1             : /*
       2             :     qgpgmedecryptverifyjob.cpp
       3             : 
       4             :     This file is part of qgpgme, the Qt API binding for gpgme
       5             :     Copyright (c) 2004,2008 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 along
      19             :     with this program; if not, write to the Free Software Foundation, Inc.,
      20             :     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             : 
      34             : #ifdef HAVE_CONFIG_H
      35             :  #include "config.h"
      36             : #endif
      37             : 
      38             : #include "qgpgmedecryptverifyjob.h"
      39             : 
      40             : #include "dataprovider.h"
      41             : 
      42             : #include "context.h"
      43             : #include "decryptionresult.h"
      44             : #include "verificationresult.h"
      45             : #include "data.h"
      46             : 
      47             : #include <QDebug>
      48             : #include "gpgme_backend_debug.h"
      49             : 
      50             : #include <QBuffer>
      51             : 
      52             : #include <cassert>
      53             : 
      54             : using namespace QGpgME;
      55             : using namespace GpgME;
      56             : 
      57           0 : QGpgMEDecryptVerifyJob::QGpgMEDecryptVerifyJob(Context *context)
      58           0 :     : mixin_type(context)
      59             : {
      60           0 :     lateInitialization();
      61           0 : }
      62             : 
      63           0 : QGpgMEDecryptVerifyJob::~QGpgMEDecryptVerifyJob() {}
      64             : 
      65           0 : static QGpgMEDecryptVerifyJob::result_type decrypt_verify(Context *ctx, QThread *thread,
      66             :                                                           const std::weak_ptr<QIODevice> &cipherText_,
      67             :                                                           const std::weak_ptr<QIODevice> &plainText_)
      68             : {
      69             : 
      70           0 :     qCDebug(GPGPME_BACKEND_LOG);
      71             : 
      72           0 :     const std::shared_ptr<QIODevice> cipherText = cipherText_.lock();
      73           0 :     const std::shared_ptr<QIODevice> plainText = plainText_.lock();
      74             : 
      75           0 :     const _detail::ToThreadMover ctMover(cipherText, thread);
      76           0 :     const _detail::ToThreadMover ptMover(plainText,  thread);
      77             : 
      78           0 :     QGpgME::QIODeviceDataProvider in(cipherText);
      79           0 :     const Data indata(&in);
      80             : 
      81           0 :     if (!plainText) {
      82           0 :         QGpgME::QByteArrayDataProvider out;
      83           0 :         Data outdata(&out);
      84             : 
      85           0 :         const std::pair<DecryptionResult, VerificationResult> res = ctx->decryptAndVerify(indata, outdata);
      86           0 :         Error ae;
      87           0 :         const QString log = _detail::audit_log_as_html(ctx, ae);
      88           0 :         qCDebug(GPGPME_BACKEND_LOG) << "End no plainText. Error: " << ae;
      89           0 :         return std::make_tuple(res.first, res.second, out.data(), log, ae);
      90             :     } else {
      91           0 :         QGpgME::QIODeviceDataProvider out(plainText);
      92           0 :         Data outdata(&out);
      93             : 
      94           0 :         const std::pair<DecryptionResult, VerificationResult> res = ctx->decryptAndVerify(indata, outdata);
      95           0 :         Error ae;
      96           0 :         const QString log = _detail::audit_log_as_html(ctx, ae);
      97           0 :         qCDebug(GPGPME_BACKEND_LOG) << "End plainText. Error: " << ae;
      98           0 :         return std::make_tuple(res.first, res.second, QByteArray(), log, ae);
      99           0 :     }
     100             : 
     101             : }
     102             : 
     103           0 : static QGpgMEDecryptVerifyJob::result_type decrypt_verify_qba(Context *ctx, const QByteArray &cipherText)
     104             : {
     105           0 :     const std::shared_ptr<QBuffer> buffer(new QBuffer);
     106           0 :     buffer->setData(cipherText);
     107           0 :     if (!buffer->open(QIODevice::ReadOnly)) {
     108           0 :         assert(!"This should never happen: QBuffer::open() failed");
     109             :     }
     110           0 :     return decrypt_verify(ctx, 0, buffer, std::shared_ptr<QIODevice>());
     111             : }
     112             : 
     113           0 : Error QGpgMEDecryptVerifyJob::start(const QByteArray &cipherText)
     114             : {
     115           0 :     run(std::bind(&decrypt_verify_qba, std::placeholders::_1, cipherText));
     116           0 :     return Error();
     117             : }
     118             : 
     119           0 : void QGpgMEDecryptVerifyJob::start(const std::shared_ptr<QIODevice> &cipherText, const std::shared_ptr<QIODevice> &plainText)
     120             : {
     121           0 :     run(std::bind(&decrypt_verify, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4), cipherText, plainText);
     122           0 : }
     123             : 
     124             : std::pair<GpgME::DecryptionResult, GpgME::VerificationResult>
     125           0 : QGpgME::QGpgMEDecryptVerifyJob::exec(const QByteArray &cipherText, QByteArray &plainText)
     126             : {
     127           0 :     const result_type r = decrypt_verify_qba(context(), cipherText);
     128           0 :     plainText = std::get<2>(r);
     129           0 :     resultHook(r);
     130           0 :     return mResult;
     131             : }
     132             : 
     133             : //PENDING(marc) implement showErrorDialog()
     134             : 
     135           0 : void QGpgMEDecryptVerifyJob::resultHook(const result_type &tuple)
     136             : {
     137           0 :     mResult = std::make_pair(std::get<0>(tuple), std::get<1>(tuple));
     138           0 : }
     139             : #include "qgpgmedecryptverifyjob.moc"

Generated by: LCOV version 1.11