35 #include "objecttreeparser_p.h"
37 #include <kleo/decryptverifyjob.h>
38 #include <kleo/verifydetachedjob.h>
39 #include <kleo/verifyopaquejob.h>
40 #include <kleo/keylistjob.h>
42 #include <gpgmepp/keylistresult.h>
45 #include <tqstringlist.h>
49 using namespace KMail;
51 using namespace GpgME;
53 CryptoBodyPartMemento::CryptoBodyPartMemento()
55 Interface::BodyPartMemento(),
62 CryptoBodyPartMemento::~CryptoBodyPartMemento() {}
64 void CryptoBodyPartMemento::setAuditLog(
const GpgME::Error & err,
const TQString & log ) {
65 m_auditLogError = err;
69 void CryptoBodyPartMemento::setRunning(
bool running ) {
73 DecryptVerifyBodyPartMemento::DecryptVerifyBodyPartMemento( DecryptVerifyJob * job,
const TQByteArray & cipherText )
74 : CryptoBodyPartMemento(),
75 m_cipherText( cipherText ),
81 DecryptVerifyBodyPartMemento::~DecryptVerifyBodyPartMemento() {
86 bool DecryptVerifyBodyPartMemento::start() {
88 if (
const GpgME::Error err = m_job->start( m_cipherText ) ) {
89 m_dr = DecryptionResult( err );
92 connect( m_job, TQ_SIGNAL(result(
const GpgME::DecryptionResult&,
const GpgME::VerificationResult&,
const TQByteArray&)),
93 this, TQ_SLOT(slotResult(
const GpgME::DecryptionResult&,
const GpgME::VerificationResult&,
const TQByteArray&)) );
98 void DecryptVerifyBodyPartMemento::exec() {
100 TQByteArray plainText;
102 const std::pair<DecryptionResult,VerificationResult> p = m_job->exec( m_cipherText, plainText );
103 saveResult( p.first, p.second, plainText );
104 m_job->deleteLater();
108 void DecryptVerifyBodyPartMemento::saveResult(
const DecryptionResult & dr,
109 const VerificationResult & vr,
110 const TQByteArray & plainText )
116 m_plainText = plainText;
117 setAuditLog( m_job->auditLogError(), m_job->auditLogAsHtml() );
120 void DecryptVerifyBodyPartMemento::slotResult(
const DecryptionResult & dr,
121 const VerificationResult & vr,
122 const TQByteArray & plainText )
124 saveResult( dr, vr, plainText );
132 VerifyDetachedBodyPartMemento::VerifyDetachedBodyPartMemento( VerifyDetachedJob * job,
134 const TQByteArray & signature,
135 const TQByteArray & plainText )
136 : CryptoBodyPartMemento(),
137 m_signature( signature ),
138 m_plainText( plainText ),
145 VerifyDetachedBodyPartMemento::~VerifyDetachedBodyPartMemento() {
149 m_keylistjob->slotCancel();
152 bool VerifyDetachedBodyPartMemento::start() {
154 if (
const GpgME::Error err = m_job->start( m_signature, m_plainText ) ) {
155 m_vr = VerificationResult( err );
158 connect( m_job, TQ_SIGNAL(result(
const GpgME::VerificationResult&)),
159 this, TQ_SLOT(slotResult(
const GpgME::VerificationResult&)) );
164 void VerifyDetachedBodyPartMemento::exec() {
167 saveResult( m_job->exec( m_signature, m_plainText ) );
168 m_job->deleteLater();
170 if ( canStartKeyListJob() ) {
171 std::vector<GpgME::Key> keys;
172 m_keylistjob->exec( keyListPattern(),
false, keys );
177 m_keylistjob->deleteLater();
182 bool VerifyDetachedBodyPartMemento::canStartKeyListJob()
const
186 const char *
const fpr = m_vr.signature( 0 ).fingerprint();
190 TQStringList VerifyDetachedBodyPartMemento::keyListPattern()
const
192 assert( canStartKeyListJob() );
193 return TQStringList( TQString::fromLatin1( m_vr.signature( 0 ).fingerprint() ) );
196 void VerifyDetachedBodyPartMemento::saveResult(
const VerificationResult & vr )
200 setAuditLog( m_job->auditLogError(), m_job->auditLogAsHtml() );
203 void VerifyDetachedBodyPartMemento::slotResult(
const VerificationResult & vr )
207 if ( canStartKeyListJob() && startKeyListJob() )
210 m_keylistjob->deleteLater();
216 bool VerifyDetachedBodyPartMemento::startKeyListJob()
218 assert( canStartKeyListJob() );
219 if (
const GpgME::Error err = m_keylistjob->start( keyListPattern() ) )
221 connect( m_keylistjob, TQ_SIGNAL(done()),
this, TQ_SLOT(slotKeyListJobDone()) );
222 connect( m_keylistjob, TQ_SIGNAL(nextKey(
const GpgME::Key&)),
223 this, TQ_SLOT(slotNextKey(
const GpgME::Key&)) );
227 void VerifyDetachedBodyPartMemento::slotNextKey(
const GpgME::Key & key )
232 void VerifyDetachedBodyPartMemento::slotKeyListJobDone()
240 VerifyOpaqueBodyPartMemento::VerifyOpaqueBodyPartMemento( VerifyOpaqueJob * job,
242 const TQByteArray & signature )
243 : CryptoBodyPartMemento(),
244 m_signature( signature ),
251 VerifyOpaqueBodyPartMemento::~VerifyOpaqueBodyPartMemento() {
255 m_keylistjob->slotCancel();
258 bool VerifyOpaqueBodyPartMemento::start() {
260 if (
const GpgME::Error err = m_job->start( m_signature ) ) {
261 m_vr = VerificationResult( err );
264 connect( m_job, TQ_SIGNAL(result(
const GpgME::VerificationResult&,
const TQByteArray&)),
265 this, TQ_SLOT(slotResult(
const GpgME::VerificationResult&,
const TQByteArray&)) );
270 void VerifyOpaqueBodyPartMemento::exec() {
273 TQByteArray plainText;
274 saveResult( m_job->exec( m_signature, plainText ), plainText );
275 m_job->deleteLater();
277 if ( canStartKeyListJob() ) {
278 std::vector<GpgME::Key> keys;
279 m_keylistjob->exec( keyListPattern(),
false, keys );
284 m_keylistjob->deleteLater();
289 bool VerifyOpaqueBodyPartMemento::canStartKeyListJob()
const
293 const char *
const fpr = m_vr.signature( 0 ).fingerprint();
297 TQStringList VerifyOpaqueBodyPartMemento::keyListPattern()
const
299 assert( canStartKeyListJob() );
300 return TQStringList( TQString::fromLatin1( m_vr.signature( 0 ).fingerprint() ) );
303 void VerifyOpaqueBodyPartMemento::saveResult(
const VerificationResult & vr,
304 const TQByteArray & plainText )
308 m_plainText = plainText;
309 setAuditLog( m_job->auditLogError(), m_job->auditLogAsHtml() );
312 void VerifyOpaqueBodyPartMemento::slotResult(
const VerificationResult & vr,
313 const TQByteArray & plainText )
315 saveResult( vr, plainText );
317 if ( canStartKeyListJob() && startKeyListJob() )
320 m_keylistjob->deleteLater();
326 bool VerifyOpaqueBodyPartMemento::startKeyListJob()
328 assert( canStartKeyListJob() );
329 if (
const GpgME::Error err = m_keylistjob->start( keyListPattern() ) )
331 connect( m_keylistjob, TQ_SIGNAL(done()),
this, TQ_SLOT(slotKeyListJobDone()) );
332 connect( m_keylistjob, TQ_SIGNAL(nextKey(
const GpgME::Key&)),
333 this, TQ_SLOT(slotNextKey(
const GpgME::Key&)) );
337 void VerifyOpaqueBodyPartMemento::slotNextKey(
const GpgME::Key & key )
342 void VerifyOpaqueBodyPartMemento::slotKeyListJobDone()
350 #include "objecttreeparser_p.moc"