Blame lang/qt/src/qgpgmeverifydetachedjob.cpp

Packit Service 672cf4
/*
Packit Service 672cf4
    qgpgmeverifydetachedjob.cpp
Packit Service 672cf4
Packit Service 672cf4
    This file is part of qgpgme, the Qt API binding for gpgme
Packit Service 672cf4
    Copyright (c) 2004,2007,2008 Klarälvdalens Datakonsult AB
Packit Service 672cf4
    Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik
Packit Service 672cf4
    Software engineering by Intevation GmbH
Packit Service 672cf4
Packit Service 672cf4
    QGpgME is free software; you can redistribute it and/or
Packit Service 672cf4
    modify it under the terms of the GNU General Public License as
Packit Service 672cf4
    published by the Free Software Foundation; either version 2 of the
Packit Service 672cf4
    License, or (at your option) any later version.
Packit Service 672cf4
Packit Service 672cf4
    QGpgME is distributed in the hope that it will be useful,
Packit Service 672cf4
    but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 672cf4
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 672cf4
    General Public License for more details.
Packit Service 672cf4
Packit Service 672cf4
    You should have received a copy of the GNU General Public License along
Packit Service 672cf4
    with this program; if not, write to the Free Software Foundation, Inc.,
Packit Service 672cf4
    51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit Service 672cf4
Packit Service 672cf4
    In addition, as a special exception, the copyright holders give
Packit Service 672cf4
    permission to link the code of this program with any edition of
Packit Service 672cf4
    the Qt library by Trolltech AS, Norway (or with modified versions
Packit Service 672cf4
    of Qt that use the same license as Qt), and distribute linked
Packit Service 672cf4
    combinations including the two.  You must obey the GNU General
Packit Service 672cf4
    Public License in all respects for all of the code used other than
Packit Service 672cf4
    Qt.  If you modify this file, you may extend this exception to
Packit Service 672cf4
    your version of the file, but you are not obligated to do so.  If
Packit Service 672cf4
    you do not wish to do so, delete this exception statement from
Packit Service 672cf4
    your version.
Packit Service 672cf4
*/
Packit Service 672cf4
Packit Service 672cf4
#ifdef HAVE_CONFIG_H
Packit Service 672cf4
 #include "config.h"
Packit Service 672cf4
#endif
Packit Service 672cf4
Packit Service 672cf4
#include "qgpgmeverifydetachedjob.h"
Packit Service 672cf4
Packit Service 672cf4
#include "dataprovider.h"
Packit Service 672cf4
Packit Service 672cf4
#include "context.h"
Packit Service 672cf4
#include "verificationresult.h"
Packit Service 672cf4
#include "data.h"
Packit Service 672cf4
Packit Service 672cf4
#include <cassert>
Packit Service 672cf4
Packit Service 672cf4
Packit Service 672cf4
using namespace QGpgME;
Packit Service 672cf4
using namespace GpgME;
Packit Service 672cf4
Packit Service 672cf4
QGpgMEVerifyDetachedJob::QGpgMEVerifyDetachedJob(Context *context)
Packit Service 672cf4
    : mixin_type(context)
Packit Service 672cf4
{
Packit Service 672cf4
    lateInitialization();
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
QGpgMEVerifyDetachedJob::~QGpgMEVerifyDetachedJob() {}
Packit Service 672cf4
Packit Service 672cf4
static QGpgMEVerifyDetachedJob::result_type verify_detached(Context *ctx, QThread *thread, const std::weak_ptr<QIODevice> &signature_, const std::weak_ptr<QIODevice> &signedData_)
Packit Service 672cf4
{
Packit Service 672cf4
    const std::shared_ptr<QIODevice> signature = signature_.lock();
Packit Service 672cf4
    const std::shared_ptr<QIODevice> signedData = signedData_.lock();
Packit Service 672cf4
Packit Service 672cf4
    const _detail::ToThreadMover sgMover(signature,  thread);
Packit Service 672cf4
    const _detail::ToThreadMover sdMover(signedData, thread);
Packit Service 672cf4
Packit Service 672cf4
    QGpgME::QIODeviceDataProvider sigDP(signature);
Packit Service 672cf4
    Data sig(&sigDP);
Packit Service 672cf4
Packit Service 672cf4
    QGpgME::QIODeviceDataProvider dataDP(signedData);
Packit Service 672cf4
    Data data(&dataDP);
Packit Service 672cf4
Packit Service 672cf4
    const VerificationResult res = ctx->verifyDetachedSignature(sig, data);
Packit Service 672cf4
    Error ae;
Packit Service 672cf4
    const QString log = _detail::audit_log_as_html(ctx, ae);
Packit Service 672cf4
Packit Service 672cf4
    return std::make_tuple(res, log, ae);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
static QGpgMEVerifyDetachedJob::result_type verify_detached_qba(Context *ctx, const QByteArray &signature, const QByteArray &signedData)
Packit Service 672cf4
{
Packit Service 672cf4
    QGpgME::QByteArrayDataProvider sigDP(signature);
Packit Service 672cf4
    Data sig(&sigDP);
Packit Service 672cf4
Packit Service 672cf4
    QGpgME::QByteArrayDataProvider dataDP(signedData);
Packit Service 672cf4
    Data data(&dataDP);
Packit Service 672cf4
Packit Service 672cf4
    const VerificationResult res = ctx->verifyDetachedSignature(sig, data);
Packit Service 672cf4
    Error ae;
Packit Service 672cf4
    const QString log = _detail::audit_log_as_html(ctx, ae);
Packit Service 672cf4
Packit Service 672cf4
    return std::make_tuple(res, log, ae);
Packit Service 672cf4
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
Error QGpgMEVerifyDetachedJob::start(const QByteArray &signature, const QByteArray &signedData)
Packit Service 672cf4
{
Packit Service 672cf4
    run(std::bind(&verify_detached_qba, std::placeholders::_1, signature, signedData));
Packit Service 672cf4
    return Error();
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
void QGpgMEVerifyDetachedJob::start(const std::shared_ptr<QIODevice> &signature, const std::shared_ptr<QIODevice> &signedData)
Packit Service 672cf4
{
Packit Service 672cf4
    run(std::bind(&verify_detached, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4), signature, signedData);
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
GpgME::VerificationResult QGpgME::QGpgMEVerifyDetachedJob::exec(const QByteArray &signature,
Packit Service 672cf4
        const QByteArray &signedData)
Packit Service 672cf4
{
Packit Service 672cf4
    const result_type r = verify_detached_qba(context(), signature, signedData);
Packit Service 672cf4
    resultHook(r);
Packit Service 672cf4
    return mResult;
Packit Service 672cf4
}
Packit Service 672cf4
Packit Service 672cf4
//PENDING(marc) implement showErrorDialog()
Packit Service 672cf4
Packit Service 672cf4
void QGpgME::QGpgMEVerifyDetachedJob::resultHook(const result_type &tuple)
Packit Service 672cf4
{
Packit Service 672cf4
    mResult = std::get<0>(tuple);
Packit Service 672cf4
}
Packit Service 672cf4
#include "qgpgmeverifydetachedjob.moc"