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

Generated by: LCOV version 1.11