diff options
Diffstat (limited to 'framework/src/domain/mime/mimetreeparser/verifydetachedbodypartmemento.cpp')
-rw-r--r-- | framework/src/domain/mime/mimetreeparser/verifydetachedbodypartmemento.cpp | 177 |
1 files changed, 0 insertions, 177 deletions
diff --git a/framework/src/domain/mime/mimetreeparser/verifydetachedbodypartmemento.cpp b/framework/src/domain/mime/mimetreeparser/verifydetachedbodypartmemento.cpp deleted file mode 100644 index 56c1d1a7..00000000 --- a/framework/src/domain/mime/mimetreeparser/verifydetachedbodypartmemento.cpp +++ /dev/null | |||
@@ -1,177 +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 "verifydetachedbodypartmemento.h" | ||
19 | #include "mimetreeparser_debug.h" | ||
20 | |||
21 | #include <QGpgME/VerifyDetachedJob> | ||
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 | VerifyDetachedBodyPartMemento::VerifyDetachedBodyPartMemento(VerifyDetachedJob *job, | ||
35 | KeyListJob *klj, | ||
36 | const QByteArray &signature, | ||
37 | const QByteArray &plainText) | ||
38 | : CryptoBodyPartMemento(), | ||
39 | m_signature(signature), | ||
40 | m_plainText(plainText), | ||
41 | m_job(job), | ||
42 | m_keylistjob(klj) | ||
43 | { | ||
44 | assert(m_job); | ||
45 | } | ||
46 | |||
47 | VerifyDetachedBodyPartMemento::~VerifyDetachedBodyPartMemento() | ||
48 | { | ||
49 | if (m_job) { | ||
50 | m_job->slotCancel(); | ||
51 | } | ||
52 | if (m_keylistjob) { | ||
53 | m_keylistjob->slotCancel(); | ||
54 | } | ||
55 | } | ||
56 | |||
57 | bool VerifyDetachedBodyPartMemento::start() | ||
58 | { | ||
59 | assert(m_job); | ||
60 | #ifdef DEBUG_SIGNATURE | ||
61 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento started"; | ||
62 | #endif | ||
63 | connect(m_job, SIGNAL(result(GpgME::VerificationResult)), | ||
64 | this, SLOT(slotResult(GpgME::VerificationResult))); | ||
65 | if (const Error err = m_job->start(m_signature, m_plainText)) { | ||
66 | m_vr = VerificationResult(err); | ||
67 | #ifdef DEBUG_SIGNATURE | ||
68 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento stopped with error"; | ||
69 | #endif | ||
70 | return false; | ||
71 | } | ||
72 | setRunning(true); | ||
73 | return true; | ||
74 | } | ||
75 | |||
76 | void VerifyDetachedBodyPartMemento::exec() | ||
77 | { | ||
78 | assert(m_job); | ||
79 | setRunning(true); | ||
80 | #ifdef DEBUG_SIGNATURE | ||
81 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento execed"; | ||
82 | #endif | ||
83 | saveResult(m_job->exec(m_signature, m_plainText)); | ||
84 | m_job->deleteLater(); // exec'ed jobs don't delete themselves | ||
85 | m_job = nullptr; | ||
86 | #ifdef DEBUG_SIGNATURE | ||
87 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento after execed"; | ||
88 | #endif | ||
89 | if (canStartKeyListJob()) { | ||
90 | std::vector<GpgME::Key> keys; | ||
91 | m_keylistjob->exec(keyListPattern(), /*secretOnly=*/false, keys); | ||
92 | if (!keys.empty()) { | ||
93 | m_key = keys.back(); | ||
94 | } | ||
95 | } | ||
96 | if (m_keylistjob) { | ||
97 | m_keylistjob->deleteLater(); // exec'ed jobs don't delete themselves | ||
98 | } | ||
99 | m_keylistjob = nullptr; | ||
100 | setRunning(false); | ||
101 | } | ||
102 | |||
103 | bool VerifyDetachedBodyPartMemento::canStartKeyListJob() const | ||
104 | { | ||
105 | if (!m_keylistjob) { | ||
106 | return false; | ||
107 | } | ||
108 | const char *const fpr = m_vr.signature(0).fingerprint(); | ||
109 | return fpr && *fpr; | ||
110 | } | ||
111 | |||
112 | QStringList VerifyDetachedBodyPartMemento::keyListPattern() const | ||
113 | { | ||
114 | assert(canStartKeyListJob()); | ||
115 | return QStringList(QString::fromLatin1(m_vr.signature(0).fingerprint())); | ||
116 | } | ||
117 | |||
118 | void VerifyDetachedBodyPartMemento::saveResult(const VerificationResult &vr) | ||
119 | { | ||
120 | assert(m_job); | ||
121 | #ifdef DEBUG_SIGNATURE | ||
122 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento::saveResult called"; | ||
123 | #endif | ||
124 | m_vr = vr; | ||
125 | setAuditLog(m_job->auditLogError(), m_job->auditLogAsHtml()); | ||
126 | } | ||
127 | |||
128 | void VerifyDetachedBodyPartMemento::slotResult(const VerificationResult &vr) | ||
129 | { | ||
130 | #ifdef DEBUG_SIGNATURE | ||
131 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento::slotResult called"; | ||
132 | #endif | ||
133 | saveResult(vr); | ||
134 | m_job = nullptr; | ||
135 | if (canStartKeyListJob() && startKeyListJob()) { | ||
136 | #ifdef DEBUG_SIGNATURE | ||
137 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento: canStartKeyListJob && startKeyListJob"; | ||
138 | #endif | ||
139 | return; | ||
140 | } | ||
141 | if (m_keylistjob) { | ||
142 | m_keylistjob->deleteLater(); | ||
143 | } | ||
144 | m_keylistjob = nullptr; | ||
145 | setRunning(false); | ||
146 | notify(); | ||
147 | } | ||
148 | |||
149 | bool VerifyDetachedBodyPartMemento::startKeyListJob() | ||
150 | { | ||
151 | assert(canStartKeyListJob()); | ||
152 | if (const GpgME::Error err = m_keylistjob->start(keyListPattern())) { | ||
153 | return false; | ||
154 | } | ||
155 | connect(m_keylistjob, SIGNAL(done()), this, SLOT(slotKeyListJobDone())); | ||
156 | connect(m_keylistjob, SIGNAL(nextKey(GpgME::Key)), | ||
157 | this, SLOT(slotNextKey(GpgME::Key))); | ||
158 | return true; | ||
159 | } | ||
160 | |||
161 | void VerifyDetachedBodyPartMemento::slotNextKey(const GpgME::Key &key) | ||
162 | { | ||
163 | #ifdef DEBUG_SIGNATURE | ||
164 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento::slotNextKey called"; | ||
165 | #endif | ||
166 | m_key = key; | ||
167 | } | ||
168 | |||
169 | void VerifyDetachedBodyPartMemento::slotKeyListJobDone() | ||
170 | { | ||
171 | #ifdef DEBUG_SIGNATURE | ||
172 | qCDebug(MIMETREEPARSER_LOG) << "tokoe: VerifyDetachedBodyPartMemento::slotKeyListJobDone called"; | ||
173 | #endif | ||
174 | m_keylistjob = nullptr; | ||
175 | setRunning(false); | ||
176 | notify(); | ||
177 | } | ||