certmanager/lib
qgpgmesignencryptjob.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifdef HAVE_CONFIG_H
00034 #include <config.h>
00035 #endif
00036
00037 #include "qgpgmesignencryptjob.h"
00038
00039 #include "ui/messagebox.h"
00040
00041 #include <qgpgme/eventloopinteractor.h>
00042 #include <qgpgme/dataprovider.h>
00043
00044 #include <gpgmepp/context.h>
00045 #include <gpgmepp/data.h>
00046 #include <gpgmepp/key.h>
00047
00048 #include <klocale.h>
00049
00050 #include <assert.h>
00051
00052 Kleo::QGpgMESignEncryptJob::QGpgMESignEncryptJob( GpgME::Context * context )
00053 : SignEncryptJob( QGpgME::EventLoopInteractor::instance(), "Kleo::QGpgMESignEncryptJob" ),
00054 QGpgMEJob( this, context )
00055 {
00056 assert( context );
00057 }
00058
00059 Kleo::QGpgMESignEncryptJob::~QGpgMESignEncryptJob() {
00060 }
00061
00062 GpgME::Error Kleo::QGpgMESignEncryptJob::setup( const std::vector<GpgME::Key> & signers,
00063 const QByteArray & plainText ) {
00064 assert( !mInData );
00065 assert( !mOutData );
00066
00067 createInData( plainText );
00068 createOutData();
00069
00070 return setSigningKeys( signers );
00071 }
00072
00073 GpgME::Error Kleo::QGpgMESignEncryptJob::start( const std::vector<GpgME::Key> & signers,
00074 const std::vector<GpgME::Key> & recipients,
00075 const QByteArray & plainText, bool alwaysTrust ) {
00076 if ( const GpgME::Error error = setup( signers, plainText ) ) {
00077 deleteLater();
00078 return error;
00079 }
00080
00081 hookupContextToEventLoopInteractor();
00082
00083 const GpgME::Context::EncryptionFlags flags =
00084 alwaysTrust ? GpgME::Context::AlwaysTrust : GpgME::Context::None ;
00085 const GpgME::Error err = mCtx->startCombinedSigningAndEncryption( recipients, *mInData, *mOutData, flags );
00086
00087 if ( err )
00088 deleteLater();
00089 mResult.first = GpgME::SigningResult( err );
00090 mResult.second = GpgME::EncryptionResult( err );
00091 return err;
00092 }
00093
00094 std::pair<GpgME::SigningResult,GpgME::EncryptionResult>
00095 Kleo::QGpgMESignEncryptJob::exec( const std::vector<GpgME::Key> & signers,
00096 const std::vector<GpgME::Key> & recipients,
00097 const QByteArray & plainText, bool alwaysTrust,
00098 QByteArray & cipherText ) {
00099 if ( GpgME::Error err = setup( signers, plainText ) )
00100 return std::make_pair( GpgME::SigningResult( 0, err ), GpgME::EncryptionResult() );
00101 const GpgME::Context::EncryptionFlags flags =
00102 alwaysTrust ? GpgME::Context::AlwaysTrust : GpgME::Context::None ;
00103 mResult = mCtx->signAndEncrypt( recipients, *mInData, *mOutData, flags );
00104 cipherText = mOutDataDataProvider->data();
00105 getAuditLog();
00106 return mResult;
00107 }
00108
00109 void Kleo::QGpgMESignEncryptJob::doOperationDoneEvent( const GpgME::Error & ) {
00110 mResult.first = mCtx->signingResult();
00111 mResult.second = mCtx->encryptionResult();
00112 const QByteArray cipherText = mOutDataDataProvider->data();
00113 getAuditLog();
00114 emit result( mResult.first, mResult.second, cipherText );
00115 }
00116
00117 void Kleo::QGpgMESignEncryptJob::showErrorDialog( QWidget * parent, const QString & caption ) const {
00118 if ( mResult.first.error() && !mResult.first.error().isCanceled() ||
00119 mResult.second.error() && !mResult.second.error().isCanceled() )
00120 Kleo::MessageBox::error( parent, mResult.first, mResult.second, this, caption );
00121 }
00122
00123 #include "qgpgmesignencryptjob.moc"
|