LCOV - code coverage report
Current view: top level - lang/qt/src - qgpgmedecryptverifyjob.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 48 0.0 %
Date: 2018-11-14 16:53:58 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 by Bundesamt für Sicherheit in der Informationstechnik
       7             :     Software engineering by Intevation GmbH
       8             : 
       9             :     QGpgME is free software; you can redistribute it and/or
      10             :     modify it under the terms of the GNU General Public License as
      11             :     published by the Free Software Foundation; either version 2 of the
      12             :     License, or (at your option) any later version.
      13             : 
      14             :     QGpgME is distributed in the hope that it will be useful,
      15             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17             :     General Public License for more details.
      18             : 
      19             :     You should have received a copy of the GNU General Public License along
      20             :     with this program; if not, write to the Free Software Foundation, Inc.,
      21             :     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
      22             : 
      23             :     In addition, as a special exception, the copyright holders give
      24             :     permission to link the code of this program with any edition of
      25             :     the Qt library by Trolltech AS, Norway (or with modified versions
      26             :     of Qt that use the same license as Qt), and distribute linked
      27             :     combinations including the two.  You must obey the GNU General
      28             :     Public License in all respects for all of the code used other than
      29             :     Qt.  If you modify this file, you may extend this exception to
      30             :     your version of the file, but you are not obligated to do so.  If
      31             :     you do not wish to do so, delete this exception statement from
      32             :     your version.
      33             : */
      34             : 
      35             : #ifdef HAVE_CONFIG_H
      36             :  #include "config.h"
      37             : #endif
      38             : 
      39             : #include "qgpgmedecryptverifyjob.h"
      40             : 
      41             : #include "dataprovider.h"
      42             : 
      43             : #include "context.h"
      44             : #include "decryptionresult.h"
      45             : #include "verificationresult.h"
      46             : #include "data.h"
      47             : 
      48             : #include <QDebug>
      49             : #include "gpgme_backend_debug.h"
      50             : 
      51             : #include <QBuffer>
      52             : 
      53             : #include <cassert>
      54             : 
      55             : using namespace QGpgME;
      56             : using namespace GpgME;
      57             : 
      58           0 : QGpgMEDecryptVerifyJob::QGpgMEDecryptVerifyJob(Context *context)
      59           0 :     : mixin_type(context)
      60             : {
      61           0 :     lateInitialization();
      62           0 : }
      63             : 
      64           0 : QGpgMEDecryptVerifyJob::~QGpgMEDecryptVerifyJob() {}
      65             : 
      66           0 : static QGpgMEDecryptVerifyJob::result_type decrypt_verify(Context *ctx, QThread *thread,
      67             :                                                           const std::weak_ptr<QIODevice> &cipherText_,
      68             :                                                           const std::weak_ptr<QIODevice> &plainText_)
      69             : {
      70             : 
      71           0 :     qCDebug(GPGPME_BACKEND_LOG);
      72             : 
      73           0 :     const std::shared_ptr<QIODevice> cipherText = cipherText_.lock();
      74           0 :     const std::shared_ptr<QIODevice> plainText = plainText_.lock();
      75             : 
      76           0 :     const _detail::ToThreadMover ctMover(cipherText, thread);
      77           0 :     const _detail::ToThreadMover ptMover(plainText,  thread);
      78             : 
      79           0 :     QGpgME::QIODeviceDataProvider in(cipherText);
      80           0 :     const Data indata(&in);
      81             : 
      82           0 :     if (!plainText) {
      83           0 :         QGpgME::QByteArrayDataProvider out;
      84           0 :         Data outdata(&out);
      85             : 
      86           0 :         const std::pair<DecryptionResult, VerificationResult> res = ctx->decryptAndVerify(indata, outdata);
      87           0 :         Error ae;
      88           0 :         const QString log = _detail::audit_log_as_html(ctx, ae);
      89           0 :         qCDebug(GPGPME_BACKEND_LOG) << "End no plainText. Error: " << ae;
      90           0 :         return std::make_tuple(res.first, res.second, out.data(), log, ae);
      91             :     } else {
      92           0 :         QGpgME::QIODeviceDataProvider out(plainText);
      93           0 :         Data outdata(&out);
      94             : 
      95           0 :         const std::pair<DecryptionResult, VerificationResult> res = ctx->decryptAndVerify(indata, outdata);
      96           0 :         Error ae;
      97           0 :         const QString log = _detail::audit_log_as_html(ctx, ae);
      98           0 :         qCDebug(GPGPME_BACKEND_LOG) << "End plainText. Error: " << ae;
      99           0 :         return std::make_tuple(res.first, res.second, QByteArray(), log, ae);
     100             :     }
     101             : 
     102             : }
     103             : 
     104           0 : static QGpgMEDecryptVerifyJob::result_type decrypt_verify_qba(Context *ctx, const QByteArray &cipherText)
     105             : {
     106           0 :     const std::shared_ptr<QBuffer> buffer(new QBuffer);
     107           0 :     buffer->setData(cipherText);
     108           0 :     if (!buffer->open(QIODevice::ReadOnly)) {
     109           0 :         assert(!"This should never happen: QBuffer::open() failed");
     110             :     }
     111           0 :     return decrypt_verify(ctx, 0, buffer, std::shared_ptr<QIODevice>());
     112             : }
     113             : 
     114           0 : Error QGpgMEDecryptVerifyJob::start(const QByteArray &cipherText)
     115             : {
     116           0 :     run(std::bind(&decrypt_verify_qba, std::placeholders::_1, cipherText));
     117           0 :     return Error();
     118             : }
     119             : 
     120           0 : void QGpgMEDecryptVerifyJob::start(const std::shared_ptr<QIODevice> &cipherText, const std::shared_ptr<QIODevice> &plainText)
     121             : {
     122           0 :     run(std::bind(&decrypt_verify, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4), cipherText, plainText);
     123           0 : }
     124             : 
     125             : std::pair<GpgME::DecryptionResult, GpgME::VerificationResult>
     126           0 : QGpgME::QGpgMEDecryptVerifyJob::exec(const QByteArray &cipherText, QByteArray &plainText)
     127             : {
     128           0 :     const result_type r = decrypt_verify_qba(context(), cipherText);
     129           0 :     plainText = std::get<2>(r);
     130           0 :     resultHook(r);
     131           0 :     return mResult;
     132             : }
     133             : 
     134             : //PENDING(marc) implement showErrorDialog()
     135             : 
     136           0 : void QGpgMEDecryptVerifyJob::resultHook(const result_type &tuple)
     137             : {
     138           0 :     mResult = std::make_pair(std::get<0>(tuple), std::get<1>(tuple));
     139           0 : }
     140             : #include "qgpgmedecryptverifyjob.moc"

Generated by: LCOV version 1.13