Messagelib

decryptverifybodypartmemento.cpp
1 /*
2  SPDX-FileCopyrightText: 2014-2023 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "decryptverifybodypartmemento.h"
8 
9 #include <QGpgME/DecryptVerifyJob>
10 
11 using namespace QGpgME;
12 using namespace GpgME;
13 using namespace MimeTreeParser;
14 
15 DecryptVerifyBodyPartMemento::DecryptVerifyBodyPartMemento(DecryptVerifyJob *job, const QByteArray &cipherText)
16  : CryptoBodyPartMemento()
17  , m_cipherText(cipherText)
18  , m_job(job)
19 {
20  Q_ASSERT(m_job);
21 }
22 
23 DecryptVerifyBodyPartMemento::~DecryptVerifyBodyPartMemento()
24 {
25  if (m_job) {
26  m_job->slotCancel();
27  }
28 }
29 
31 {
32  Q_ASSERT(m_job);
33  if (const Error err = m_job->start(m_cipherText)) {
34  m_dr = DecryptionResult(err);
35  return false;
36  }
37  connect(m_job.data(), &DecryptVerifyJob::result, this, &DecryptVerifyBodyPartMemento::slotResult);
38  setRunning(true);
39  return true;
40 }
41 
42 void DecryptVerifyBodyPartMemento::exec()
43 {
44  Q_ASSERT(m_job);
45  QByteArray plainText;
46  setRunning(true);
47  const std::pair<DecryptionResult, VerificationResult> p = m_job->exec(m_cipherText, plainText);
48  saveResult(p.first, p.second, plainText);
49  m_job->deleteLater(); // exec'ed jobs don't delete themselves
50  m_job = nullptr;
51 }
52 
53 void DecryptVerifyBodyPartMemento::saveResult(const DecryptionResult &dr, const VerificationResult &vr, const QByteArray &plainText)
54 {
55  Q_ASSERT(m_job);
56  setRunning(false);
57  m_dr = dr;
58  m_vr = vr;
59  m_plainText = plainText;
60  setAuditLog(m_job->auditLogError(), m_job->auditLogAsHtml());
61 }
62 
63 void DecryptVerifyBodyPartMemento::slotResult(const DecryptionResult &dr, const VerificationResult &vr, const QByteArray &plainText)
64 {
65  saveResult(dr, vr, plainText);
66  m_job = nullptr;
67  notify();
68 }
69 
70 #include "moc_decryptverifybodypartmemento.cpp"
Q_SCRIPTABLE Q_NOREPLY void start()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Oct 1 2023 03:53:34 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.