Messagelib

qgpgmejobexecutor.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "qgpgmejobexecutor.h"
8#include "mimetreeparser_debug.h"
9
10#include <QGpgME/DecryptVerifyJob>
11#include <QGpgME/ImportJob>
12#include <QGpgME/VerifyDetachedJob>
13#include <QGpgME/VerifyOpaqueJob>
14
15#include <QEventLoop>
16
17#include <cassert>
18
19using namespace GpgME;
20using namespace MimeTreeParser;
21
22QGpgMEJobExecutor::QGpgMEJobExecutor(QObject *parent)
23 : QObject(parent)
24 , mEventLoop(new QEventLoop(this))
25{
26 setObjectName(QLatin1StringView("KleoJobExecutor"));
27}
28
29GpgME::VerificationResult QGpgMEJobExecutor::exec(QGpgME::VerifyDetachedJob *job, const QByteArray &signature, const QByteArray &signedData)
30{
31 qCDebug(MIMETREEPARSER_LOG) << "Starting detached verification job";
32 connect(job, &QGpgME::VerifyDetachedJob::result, this, qOverload<const GpgME::VerificationResult &>(&QGpgMEJobExecutor::verificationResult));
33 GpgME::Error err = job->start(signature, signedData);
34 if (err) {
35 return VerificationResult(err);
36 }
38 return mVerificationResult;
39}
40
41GpgME::VerificationResult QGpgMEJobExecutor::exec(QGpgME::VerifyOpaqueJob *job, const QByteArray &signedData, QByteArray &plainText)
42{
43 qCDebug(MIMETREEPARSER_LOG) << "Starting opaque verification job";
44 connect(job,
45 &QGpgME::VerifyOpaqueJob::result,
46 this,
47 qOverload<const GpgME::VerificationResult &, const QByteArray &>(&QGpgMEJobExecutor::verificationResult));
48 GpgME::Error err = job->start(signedData);
49 if (err) {
50 plainText.clear();
51 return VerificationResult(err);
52 }
54 plainText = mData;
55 return mVerificationResult;
56}
57
58std::pair<GpgME::DecryptionResult, GpgME::VerificationResult>
59QGpgMEJobExecutor::exec(QGpgME::DecryptVerifyJob *job, const QByteArray &cipherText, QByteArray &plainText)
60{
61 qCDebug(MIMETREEPARSER_LOG) << "Starting decryption job";
62 connect(job, &QGpgME::DecryptVerifyJob::result, this, &QGpgMEJobExecutor::decryptResult);
63 GpgME::Error err = job->start(cipherText);
64 if (err) {
65 plainText.clear();
66 return std::make_pair(DecryptionResult(err), VerificationResult(err));
67 }
69 plainText = mData;
70 return std::make_pair(mDecryptResult, mVerificationResult);
71}
72
73GpgME::ImportResult QGpgMEJobExecutor::exec(QGpgME::ImportJob *job, const QByteArray &certData)
74{
75 connect(job, &QGpgME::AbstractImportJob::result, this, &QGpgMEJobExecutor::importResult);
76 GpgME::Error err = job->start(certData);
77 if (err) {
78 return ImportResult(err);
79 }
81 return mImportResult;
82}
83
84Error QGpgMEJobExecutor::auditLogError() const
85{
86 return mAuditLogError;
87}
88
89void QGpgMEJobExecutor::verificationResult(const GpgME::VerificationResult &result)
90{
91 qCDebug(MIMETREEPARSER_LOG) << "Detached verification job finished";
93 assert(job);
94 mVerificationResult = result;
95 mAuditLogError = job->auditLogError();
96 mAuditLog = job->auditLogAsHtml();
97 mEventLoop->quit();
98}
99
100void QGpgMEJobExecutor::verificationResult(const GpgME::VerificationResult &result, const QByteArray &plainText)
101{
102 qCDebug(MIMETREEPARSER_LOG) << "Opaque verification job finished";
104 assert(job);
105 mVerificationResult = result;
106 mData = plainText;
107 mAuditLogError = job->auditLogError();
108 mAuditLog = job->auditLogAsHtml();
109 mEventLoop->quit();
110}
111
112void QGpgMEJobExecutor::decryptResult(const GpgME::DecryptionResult &decryptionresult,
113 const GpgME::VerificationResult &verificationresult,
114 const QByteArray &plainText)
115{
116 qCDebug(MIMETREEPARSER_LOG) << "Decryption job finished";
118 assert(job);
119 mVerificationResult = verificationresult;
120 mDecryptResult = decryptionresult;
121 mData = plainText;
122 mAuditLogError = job->auditLogError();
123 mAuditLog = job->auditLogAsHtml();
124 mEventLoop->quit();
125}
126
127void QGpgMEJobExecutor::importResult(const GpgME::ImportResult &result)
128{
130 assert(job);
131 mImportResult = result;
132 mAuditLogError = job->auditLogError();
133 mAuditLog = job->auditLogAsHtml();
134 mEventLoop->quit();
135}
136
137QString QGpgMEJobExecutor::auditLogAsHtml() const
138{
139 return mAuditLog;
140}
141
142#include "moc_qgpgmejobexecutor.cpp"
void clear()
int exec(ProcessEventsFlags flags)
void quit()
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T qobject_cast(QObject *object)
QObject * sender() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.