• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

libkleo

  • sources
  • kde-4.12
  • kdepim
  • libkleo
  • backends
  • qgpgme
qgpgmesignjob.cpp
Go to the documentation of this file.
1 /*
2  qgpgmesignjob.cpp
3 
4  This file is part of libkleopatra, the KDE keymanagement library
5  Copyright (c) 2004,2007,2008 Klarälvdalens Datakonsult AB
6 
7  Libkleopatra is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of the
10  License, or (at your option) any later version.
11 
12  Libkleopatra is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License along
18  with this program; if not, write to the Free Software Foundation, Inc.,
19  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #include "qgpgmesignjob.h"
34 
35 #include "ui/messagebox.h"
36 
37 #include <qgpgme/dataprovider.h>
38 
39 #include <gpgme++/context.h>
40 #include <gpgme++/signingresult.h>
41 #include <gpgme++/data.h>
42 
43 #include <QBuffer>
44 
45 #include <boost/weak_ptr.hpp>
46 
47 #include <cassert>
48 
49 using namespace Kleo;
50 using namespace GpgME;
51 using namespace boost;
52 
53 QGpgMESignJob::QGpgMESignJob( Context * context )
54  : mixin_type( context ),
55  mOutputIsBase64Encoded( false )
56 {
57  lateInitialization();
58 }
59 
60 QGpgMESignJob::~QGpgMESignJob() {}
61 
62 void QGpgMESignJob::setOutputIsBase64Encoded( bool on ) {
63  mOutputIsBase64Encoded = on;
64 }
65 
66 static QGpgMESignJob::result_type sign( Context * ctx, QThread * thread,
67  const std::vector<Key> & signers,
68  const weak_ptr<QIODevice> & plainText_,
69  const weak_ptr<QIODevice> & signature_,
70  SignatureMode mode,
71  bool outputIsBsse64Encoded ) {
72 
73  const shared_ptr<QIODevice> plainText = plainText_.lock();
74  const shared_ptr<QIODevice> signature = signature_.lock();
75 
76  const _detail::ToThreadMover ptMover( plainText, thread );
77  const _detail::ToThreadMover sgMover( signature, thread );
78 
79  QGpgME::QIODeviceDataProvider in( plainText );
80  const Data indata( &in );
81 
82  ctx->clearSigningKeys();
83  Q_FOREACH( const Key & signer, signers )
84  if ( !signer.isNull() )
85  if ( const Error err = ctx->addSigningKey( signer ) )
86  return make_tuple( SigningResult( err ), QByteArray(), QString(), Error() );
87 
88  if ( !signature ) {
89  QGpgME::QByteArrayDataProvider out;
90  Data outdata( &out );
91 
92  if ( outputIsBsse64Encoded )
93  outdata.setEncoding( Data::Base64Encoding );
94 
95  const SigningResult res = ctx->sign( indata, outdata, mode );
96  Error ae;
97  const QString log = _detail::audit_log_as_html( ctx, ae );
98  return make_tuple( res, out.data(), log, ae );
99  } else {
100  QGpgME::QIODeviceDataProvider out( signature );
101  Data outdata( &out );
102 
103  if ( outputIsBsse64Encoded )
104  outdata.setEncoding( Data::Base64Encoding );
105 
106  const SigningResult res = ctx->sign( indata, outdata, mode );
107  Error ae;
108  const QString log = _detail::audit_log_as_html( ctx, ae );
109  return make_tuple( res, QByteArray(), log, ae );
110  }
111 
112 }
113 
114 static QGpgMESignJob::result_type sign_qba( Context * ctx,
115  const std::vector<Key> & signers,
116  const QByteArray & plainText,
117  SignatureMode mode,
118  bool outputIsBsse64Encoded ) {
119  const shared_ptr<QBuffer> buffer( new QBuffer );
120  buffer->setData( plainText );
121  if ( !buffer->open( QIODevice::ReadOnly ) )
122  assert( !"This should never happen: QBuffer::open() failed" );
123  return sign( ctx, 0, signers, buffer, shared_ptr<QIODevice>(), mode, outputIsBsse64Encoded );
124 }
125 
126 Error QGpgMESignJob::start( const std::vector<Key> & signers, const QByteArray & plainText, SignatureMode mode ) {
127  run( boost::bind( &sign_qba, _1, signers, plainText, mode, mOutputIsBase64Encoded ) );
128  return Error();
129 }
130 
131 void QGpgMESignJob::start( const std::vector<Key> & signers, const shared_ptr<QIODevice> & plainText, const shared_ptr<QIODevice> & signature, SignatureMode mode ) {
132  run( boost::bind( &sign, _1, _2, signers, _3, _4, mode, mOutputIsBase64Encoded ), plainText, signature );
133 }
134 
135 SigningResult QGpgMESignJob::exec( const std::vector<Key> & signers, const QByteArray & plainText, SignatureMode mode, QByteArray & signature ) {
136  const result_type r = sign_qba( context(), signers, plainText, mode, mOutputIsBase64Encoded );
137  signature = get<1>( r );
138  resultHook( r );
139  return mResult;
140 }
141 
142 void QGpgMESignJob::resultHook( const result_type & tuple ) {
143  mResult = get<0>( tuple );
144 }
145 
146 void QGpgMESignJob::showErrorDialog( QWidget * parent, const QString & caption ) const {
147  if ( mResult.error() && !mResult.error().isCanceled() )
148  MessageBox::error( parent, mResult, this, caption );
149 }
150 
151 #include "qgpgmesignjob.moc"
Kleo::QGpgMESignJob::QGpgMESignJob
QGpgMESignJob(GpgME::Context *context)
Definition: qgpgmesignjob.cpp:53
Kleo::_detail::ThreadedJobMixin< SignJob, boost::tuple< GpgME::SigningResult, QByteArray, QString, GpgME::Error > >::context
GpgME::Context * context() const
Definition: threadedjobmixin.h:176
Kleo::QGpgMESignJob::start
GpgME::Error start(const std::vector< GpgME::Key > &signers, const QByteArray &plainText, GpgME::SignatureMode mode)
QWidget
Kleo::MessageBox::error
static void error(QWidget *parent, const GpgME::SigningResult &result, const Kleo::Job *job, const QString &caption, KMessageBox::Options options=KMessageBox::Notify)
QString
sign
static QGpgMESignJob::result_type sign(Context *ctx, QThread *thread, const std::vector< Key > &signers, const weak_ptr< QIODevice > &plainText_, const weak_ptr< QIODevice > &signature_, SignatureMode mode, bool outputIsBsse64Encoded)
Definition: qgpgmesignjob.cpp:66
Kleo::QGpgMESignJob::resultHook
void resultHook(const result_type &r)
Definition: qgpgmesignjob.cpp:142
Kleo::QGpgMESignJob::setOutputIsBase64Encoded
void setOutputIsBase64Encoded(bool on)
Definition: qgpgmesignjob.cpp:62
boost::shared_ptr
Definition: checksumdefinition.h:46
Kleo::_detail::ToThreadMover
Definition: threadedjobmixin.h:75
Kleo::_detail::ThreadedJobMixin< SignJob, boost::tuple< GpgME::SigningResult, QByteArray, QString, GpgME::Error > >::lateInitialization
void lateInitialization()
Definition: threadedjobmixin.h:144
Kleo::_detail::audit_log_as_html
QString audit_log_as_html(GpgME::Context *ctx, GpgME::Error &err)
sign_qba
static QGpgMESignJob::result_type sign_qba(Context *ctx, const std::vector< Key > &signers, const QByteArray &plainText, SignatureMode mode, bool outputIsBsse64Encoded)
Definition: qgpgmesignjob.cpp:114
messagebox.h
qgpgmesignjob.h
Kleo::QGpgMESignJob::~QGpgMESignJob
~QGpgMESignJob()
Definition: qgpgmesignjob.cpp:60
Kleo::_detail::ThreadedJobMixin< SignJob, boost::tuple< GpgME::SigningResult, QByteArray, QString, GpgME::Error > >::result_type
boost::tuple< GpgME::SigningResult, QByteArray, QString, GpgME::Error > result_type
Definition: threadedjobmixin.h:115
Kleo::_detail::ThreadedJobMixin< SignJob, boost::tuple< GpgME::SigningResult, QByteArray, QString, GpgME::Error > >::run
void run(const T_binder &func)
Definition: threadedjobmixin.h:151
Kleo::QGpgMESignJob::showErrorDialog
void showErrorDialog(QWidget *parent, const QString &caption) const
Definition: qgpgmesignjob.cpp:146
Kleo::QGpgMESignJob::exec
GpgME::SigningResult exec(const std::vector< GpgME::Key > &signers, const QByteArray &plainText, GpgME::SignatureMode mode, QByteArray &signature)
Definition: qgpgmesignjob.cpp:135
Kleo::_detail::ThreadedJobMixin< SignJob, boost::tuple< GpgME::SigningResult, QByteArray, QString, GpgME::Error > >
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:57:49 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkleo

Skip menu "libkleo"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal