diff options
Diffstat (limited to 'framework/src/domain/mime/mimetreeparser/verifyopaquebodypartmemento.cpp')
-rw-r--r-- | framework/src/domain/mime/mimetreeparser/verifyopaquebodypartmemento.cpp | 179 |
1 files changed, 0 insertions, 179 deletions
diff --git a/framework/src/domain/mime/mimetreeparser/verifyopaquebodypartmemento.cpp b/framework/src/domain/mime/mimetreeparser/verifyopaquebodypartmemento.cpp deleted file mode 100644 index 99eb8b8e..00000000 --- a/framework/src/domain/mime/mimetreeparser/verifyopaquebodypartmemento.cpp +++ /dev/null | |||
@@ -1,179 +0,0 @@ | |||
1 | /* | ||
2 | Copyright (c) 2014-2017 Montel Laurent <montel@kde.org> | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU General Public License, version 2, as | ||
6 | published by the Free Software Foundation. | ||
7 | |||
8 | This program is distributed in the hope that it will be useful, but | ||
9 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
11 | General Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License along | ||
14 | with this program; if not, write to the Free Software Foundation, Inc., | ||
15 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
16 | */ | ||
17 | |||
18 | #include "verifyopaquebodypartmemento.h" | ||
19 | #include "mimetreeparser_debug.h" | ||
20 | |||
21 | #include <QGpgME/VerifyOpaqueJob> | ||
22 | #include <QGpgME/KeyListJob> | ||
23 | |||
24 | #include <gpgme++/keylistresult.h> | ||
25 | |||
26 | #include <qstringlist.h> | ||
27 | |||
28 | #include <cassert> | ||
29 | |||
30 | using namespace QGpgME; | ||
31 | using namespace GpgME; | ||
32 | using namespace MimeTreeParser; | ||
33 | |||
34 | VerifyOpaqueBodyPartMemento::VerifyOpaqueBodyPartMemento(VerifyOpaqueJob *job, | ||
35 | KeyListJob *klj, | ||
36 | const QByteArray &signature) | ||
37 | : CryptoBodyPartMemento(), | ||
38 | m_signature(signature), | ||
39 | m_job(job), | ||
40 | m_keylistjob(klj) | ||
41 | { | ||
42 | assert(m_job); | ||
43 | } | ||
44 | |||
45 | VerifyOpaqueBodyPartMemento::~VerifyOpaqueBodyPartMemento() | ||
46 | { | ||
47 | if (m_job) { | ||
48 | m_job->slotCancel(); | ||
49 | } | ||
50 | if (m_keylistjob) { | ||
51 | m_keylistjob->slotCancel(); | ||
52 | } | ||
53 | } | ||
54 | |||
55 | bool VerifyOpaqueBodyPartMemento::start() | ||
56 | { | ||
57 | assert(m_job); | ||
58 | #ifdef DEBUG_SIGNATURE | ||
59 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento started"; | ||
60 | #endif | ||
61 | if (const Error err = m_job->start(m_signature)) { | ||
62 | m_vr = VerificationResult(err); | ||
63 | #ifdef DEBUG_SIGNATURE | ||
64 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento stopped with error"; | ||
65 | #endif | ||
66 | return false; | ||
67 | } | ||
68 | connect(m_job, SIGNAL(result(GpgME::VerificationResult,QByteArray)), | ||
69 | this, SLOT(slotResult(GpgME::VerificationResult,QByteArray))); | ||
70 | setRunning(true); | ||
71 | return true; | ||
72 | } | ||
73 | |||
74 | void VerifyOpaqueBodyPartMemento::exec() | ||
75 | { | ||
76 | assert(m_job); | ||
77 | setRunning(true); | ||
78 | QByteArray plainText; | ||
79 | #ifdef DEBUG_SIGNATURE | ||
80 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento execed"; | ||
81 | #endif | ||
82 | saveResult(m_job->exec(m_signature, plainText), plainText); | ||
83 | #ifdef DEBUG_SIGNATURE | ||
84 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento after execed"; | ||
85 | #endif | ||
86 | m_job->deleteLater(); // exec'ed jobs don't delete themselves | ||
87 | m_job = nullptr; | ||
88 | if (canStartKeyListJob()) { | ||
89 | std::vector<GpgME::Key> keys; | ||
90 | m_keylistjob->exec(keyListPattern(), /*secretOnly=*/false, keys); | ||
91 | if (!keys.empty()) { | ||
92 | m_key = keys.back(); | ||
93 | } | ||
94 | } | ||
95 | if (m_keylistjob) { | ||
96 | m_keylistjob->deleteLater(); // exec'ed jobs don't delete themselves | ||
97 | } | ||
98 | m_keylistjob = nullptr; | ||
99 | setRunning(false); | ||
100 | } | ||
101 | |||
102 | bool VerifyOpaqueBodyPartMemento::canStartKeyListJob() const | ||
103 | { | ||
104 | if (!m_keylistjob) { | ||
105 | return false; | ||
106 | } | ||
107 | const char *const fpr = m_vr.signature(0).fingerprint(); | ||
108 | return fpr && *fpr; | ||
109 | } | ||
110 | |||
111 | QStringList VerifyOpaqueBodyPartMemento::keyListPattern() const | ||
112 | { | ||
113 | assert(canStartKeyListJob()); | ||
114 | return QStringList(QString::fromLatin1(m_vr.signature(0).fingerprint())); | ||
115 | } | ||
116 | |||
117 | void VerifyOpaqueBodyPartMemento::saveResult(const VerificationResult &vr, | ||
118 | const QByteArray &plainText) | ||
119 | { | ||
120 | assert(m_job); | ||
121 | #ifdef DEBUG_SIGNATURE | ||
122 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento::saveResult called"; | ||
123 | #endif | ||
124 | m_vr = vr; | ||
125 | m_plainText = plainText; | ||
126 | setAuditLog(m_job->auditLogError(), m_job->auditLogAsHtml()); | ||
127 | } | ||
128 | |||
129 | void VerifyOpaqueBodyPartMemento::slotResult(const VerificationResult &vr, | ||
130 | const QByteArray &plainText) | ||
131 | { | ||
132 | #ifdef DEBUG_SIGNATURE | ||
133 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento::slotResult called"; | ||
134 | #endif | ||
135 | saveResult(vr, plainText); | ||
136 | m_job = nullptr; | ||
137 | if (canStartKeyListJob() && startKeyListJob()) { | ||
138 | #ifdef DEBUG_SIGNATURE | ||
139 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento: canStartKeyListJob && startKeyListJob"; | ||
140 | #endif | ||
141 | return; | ||
142 | } | ||
143 | if (m_keylistjob) { | ||
144 | m_keylistjob->deleteLater(); | ||
145 | } | ||
146 | m_keylistjob = nullptr; | ||
147 | setRunning(false); | ||
148 | notify(); | ||
149 | } | ||
150 | |||
151 | bool VerifyOpaqueBodyPartMemento::startKeyListJob() | ||
152 | { | ||
153 | assert(canStartKeyListJob()); | ||
154 | if (const GpgME::Error err = m_keylistjob->start(keyListPattern())) { | ||
155 | return false; | ||
156 | } | ||
157 | connect(m_keylistjob, SIGNAL(done()), this, SLOT(slotKeyListJobDone())); | ||
158 | connect(m_keylistjob, SIGNAL(nextKey(GpgME::Key)), | ||
159 | this, SLOT(slotNextKey(GpgME::Key))); | ||
160 | return true; | ||
161 | } | ||
162 | |||
163 | void VerifyOpaqueBodyPartMemento::slotNextKey(const GpgME::Key &key) | ||
164 | { | ||
165 | #ifdef DEBUG_SIGNATURE | ||
166 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento::slotNextKey called"; | ||
167 | #endif | ||
168 | m_key = key; | ||
169 | } | ||
170 | |||
171 | void VerifyOpaqueBodyPartMemento::slotKeyListJobDone() | ||
172 | { | ||
173 | #ifdef DEBUG_SIGNATURE | ||
174 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyOpaqueBodyPartMemento::slotKeyListJobDone called"; | ||
175 | #endif | ||
176 | m_keylistjob = nullptr; | ||
177 | setRunning(false); | ||
178 | notify(); | ||
179 | } | ||