libkdenetwork Library API Documentation

context.cpp

00001 /* context.cpp - wraps a gpgme key context 00002 Copyright (C) 2003 Klarälvdalens Datakonsult AB 00003 00004 This file is part of GPGME++. 00005 00006 GPGME++ is free software; you can redistribute it and/or modify it 00007 under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 GPGME++ is distributed in the hope that it will be useful, but 00012 WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with GPGME++; if not, write to the Free Software Foundation, 00018 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA. */ 00019 00020 #ifdef HAVE_CONFIG_H 00021 #include <config.h> 00022 #endif 00023 00024 #include <gpgmepp/context.h> 00025 #include <gpgmepp/eventloopinteractor.h> 00026 #include <gpgmepp/trustitem.h> 00027 #include <gpgmepp/keylistresult.h> 00028 #include <gpgmepp/keygenerationresult.h> 00029 #include <gpgmepp/importresult.h> 00030 #include <gpgmepp/decryptionresult.h> 00031 #include <gpgmepp/verificationresult.h> 00032 #include <gpgmepp/signingresult.h> 00033 #include <gpgmepp/encryptionresult.h> 00034 #include <gpgmepp/engineinfo.h> 00035 00036 #include "callbacks.h" 00037 #include "data_p.h" 00038 #include "context_p.h" 00039 #include "util.h" 00040 00041 #include <gpgme.h> 00042 00043 //#include <string> 00044 //using std::string; 00045 #ifndef NDEBUG 00046 #include <iostream> 00047 using std::cerr; 00048 using std::endl; 00049 #endif 00050 00051 #include <cassert> 00052 00053 namespace GpgME { 00054 00055 const char * Error::source() const { 00056 return gpgme_strsource( (gpgme_error_t)mErr ); 00057 } 00058 00059 const char * Error::asString() const { 00060 return gpgme_strerror( (gpgme_error_t)mErr ); 00061 } 00062 00063 bool Error::isCanceled() const { 00064 return gpgme_err_code( mErr ) == GPG_ERR_CANCELED; 00065 } 00066 00067 Context::Context( gpgme_ctx_t ctx ) { 00068 d = new Private( ctx ); 00069 } 00070 00071 Context::~Context() { 00072 delete d; d = 0; 00073 } 00074 00075 Context * Context::createForProtocol( Protocol proto ) { 00076 gpgme_ctx_t ctx = 0; 00077 if ( gpgme_new ( &ctx ) != 0 ) 00078 return 0; 00079 00080 switch ( proto ) { 00081 case OpenPGP: 00082 if ( gpgme_set_protocol( ctx, GPGME_PROTOCOL_OpenPGP ) != 0 ) { 00083 gpgme_release( ctx ); 00084 return 0; 00085 } 00086 break; 00087 case CMS: 00088 if ( gpgme_set_protocol( ctx, GPGME_PROTOCOL_CMS ) != 0 ) { 00089 gpgme_release( ctx ); 00090 return 0; 00091 } 00092 break; 00093 default: 00094 return 0; 00095 } 00096 00097 return new Context( ctx ); 00098 } 00099 00100 // 00101 // 00102 // Context attributes: 00103 // 00104 // 00105 00106 Context::Protocol Context::protocol() const { 00107 gpgme_protocol_t p = gpgme_get_protocol( d->ctx ); 00108 switch ( p ) { 00109 case GPGME_PROTOCOL_OpenPGP: return OpenPGP; 00110 case GPGME_PROTOCOL_CMS: return CMS; 00111 default: return Unknown; 00112 } 00113 } 00114 00115 00116 void Context::setArmor( bool useArmor ) { 00117 gpgme_set_armor( d->ctx, int( useArmor ) ); 00118 } 00119 bool Context::armor() const { 00120 return gpgme_get_armor( d->ctx ); 00121 } 00122 00123 void Context::setTextMode( bool useTextMode ) { 00124 gpgme_set_textmode( d->ctx, int( useTextMode ) ); 00125 } 00126 bool Context::textMode() const { 00127 return gpgme_get_textmode( d->ctx ); 00128 } 00129 00130 void Context::setIncludeCertificates( int which ) { 00131 assert( which >= -2 ); 00132 gpgme_set_include_certs( d->ctx, which ); 00133 } 00134 00135 int Context::includeCertificates() const { 00136 return gpgme_get_include_certs( d->ctx ); 00137 } 00138 00139 void Context::setKeyListMode( unsigned int mode ) { 00140 gpgme_set_keylist_mode( d->ctx, add_to_gpgme_keylist_mode_t( 0, mode ) ); 00141 } 00142 00143 void Context::addKeyListMode( unsigned int mode ) { 00144 const unsigned int cur = gpgme_get_keylist_mode( d->ctx ); 00145 gpgme_set_keylist_mode( d->ctx, add_to_gpgme_keylist_mode_t( cur, mode ) ); 00146 } 00147 00148 00149 unsigned int Context::keyListMode() const { 00150 return convert_from_gpgme_keylist_mode_t( gpgme_get_keylist_mode( d->ctx ) ); 00151 } 00152 00153 void Context::setProgressProvider( ProgressProvider * provider ) { 00154 gpgme_set_progress_cb( d->ctx, provider ? &progress_callback : 0, provider ); 00155 } 00156 ProgressProvider * Context::progressProvider() const { 00157 void * pp = 0; 00158 gpgme_progress_cb_t pcb = &progress_callback; 00159 gpgme_get_progress_cb( d->ctx, &pcb, &pp ); 00160 return static_cast<ProgressProvider*>( pp ); 00161 } 00162 00163 void Context::setPassphraseProvider( PassphraseProvider * provider ) { 00164 gpgme_set_passphrase_cb( d->ctx, provider ? &passphrase_callback : 0, provider ); 00165 } 00166 00167 PassphraseProvider * Context::passphraseProvider() const { 00168 void * pp = 0; 00169 gpgme_passphrase_cb_t pcb = &passphrase_callback; 00170 gpgme_get_passphrase_cb( d->ctx, &pcb, &pp ); 00171 return static_cast<PassphraseProvider*>( pp ); 00172 } 00173 00174 void Context::setManagedByEventLoopInteractor( bool manage ) { 00175 if ( !EventLoopInteractor::instance() ) { 00176 #ifndef NDEBUG 00177 cerr << "Context::setManagedByEventLoopInteractor(): " 00178 "You must create an instance of EventLoopInteractor " 00179 "before using anything that needs one." << endl; 00180 #endif 00181 return; 00182 } 00183 if ( manage ) 00184 EventLoopInteractor::instance()->manage( this ); 00185 else 00186 EventLoopInteractor::instance()->unmanage( this ); 00187 } 00188 bool Context::managedByEventLoopInteractor() const { 00189 return d->iocbs != 0; 00190 } 00191 00192 00193 void Context::installIOCallbacks( gpgme_io_cbs * iocbs ) { 00194 if ( !iocbs ) { 00195 uninstallIOCallbacks(); 00196 return; 00197 } 00198 gpgme_set_io_cbs( d->ctx, iocbs ); 00199 delete d->iocbs; d->iocbs = iocbs; 00200 } 00201 00202 void Context::uninstallIOCallbacks() { 00203 static gpgme_io_cbs noiocbs = { 0, 0, 0, 0, 0 }; 00204 // io.add == 0 means disable io callbacks: 00205 gpgme_set_io_cbs( d->ctx, &noiocbs ); 00206 delete d->iocbs; d->iocbs = 0; 00207 } 00208 00209 Error Context::setLocale( int cat, const char * val ) { 00210 return d->lasterr = gpgme_set_locale( d->ctx, cat, val ); 00211 } 00212 00213 // 00214 // 00215 // Key Management 00216 // 00217 // 00218 00219 Error Context::startKeyListing( const char * pattern, bool secretOnly ) { 00220 d->lastop = Private::KeyList; 00221 return d->lasterr = gpgme_op_keylist_start( d->ctx, pattern, int( secretOnly ) ); 00222 } 00223 00224 Error Context::startKeyListing( const char * patterns[], bool secretOnly ) { 00225 d->lastop = Private::KeyList; 00226 return d->lasterr = gpgme_op_keylist_ext_start( d->ctx, patterns, int( secretOnly ), 0 ); 00227 } 00228 00229 Key Context::nextKey( GpgME::Error & e ) { 00230 d->lastop = Private::KeyList; 00231 gpgme_key_t key; 00232 e = d->lasterr = gpgme_op_keylist_next( d->ctx, &key ); 00233 return Key( key, false, keyListMode() ); 00234 } 00235 00236 KeyListResult Context::endKeyListing() { 00237 d->lasterr = gpgme_op_keylist_end( d->ctx ); 00238 return keyListResult(); 00239 } 00240 00241 KeyListResult Context::keyListResult() const { 00242 return KeyListResult( d->ctx, d->lasterr ); 00243 } 00244 00245 Key Context::key( const char * fingerprint, GpgME::Error & e , bool secret /*, bool forceUpdate*/ ) { 00246 d->lastop = Private::KeyList; 00247 gpgme_key_t key; 00248 e = d->lasterr = gpgme_get_key( d->ctx, fingerprint, &key, int( secret )/*, int( forceUpdate )*/ ); 00249 return Key( key, false, keyListMode() ); 00250 } 00251 00252 KeyGenerationResult Context::generateKey( const char * parameters, Data & pubKey ) { 00253 d->lastop = Private::KeyGen; 00254 Data::Private * dp = pubKey.impl(); 00255 d->lasterr = gpgme_op_genkey( d->ctx, parameters, dp ? dp->data : 0, 0 ); 00256 return KeyGenerationResult( d->ctx, d->lasterr ); 00257 } 00258 00259 Error Context::startKeyGeneration( const char * parameters, Data & pubKey ) { 00260 d->lastop = Private::KeyGen; 00261 Data::Private * dp = pubKey.impl(); 00262 return d->lasterr = gpgme_op_genkey_start( d->ctx, parameters, dp ? dp->data : 0, 0 ); 00263 } 00264 00265 KeyGenerationResult Context::keyGenerationResult() const { 00266 if ( d->lastop & Private::KeyGen ) 00267 return KeyGenerationResult( d->ctx, d->lasterr ); 00268 else 00269 return KeyGenerationResult(); 00270 } 00271 00272 Error Context::exportPublicKeys( const char * pattern, Data & keyData ) { 00273 d->lastop = Private::Export; 00274 Data::Private * dp = keyData.impl(); 00275 return d->lasterr = gpgme_op_export( d->ctx, pattern, 0, dp ? dp->data : 0 ); 00276 } 00277 00278 Error Context::exportPublicKeys( const char * patterns[], Data & keyData ) { 00279 d->lastop = Private::Export; 00280 Data::Private * dp = keyData.impl(); 00281 return d->lasterr = gpgme_op_export_ext( d->ctx, patterns, 0, dp ? dp->data : 0 ); 00282 } 00283 00284 Error Context::startPublicKeyExport( const char * pattern, Data & keyData ) { 00285 d->lastop = Private::Export; 00286 Data::Private * dp = keyData.impl(); 00287 return d->lasterr = gpgme_op_export_start( d->ctx, pattern, 0, dp ? dp->data : 0 ); 00288 } 00289 00290 Error Context::startPublicKeyExport( const char * patterns[], Data & keyData ) { 00291 d->lastop = Private::Export; 00292 Data::Private * dp = keyData.impl(); 00293 return d->lasterr = gpgme_op_export_ext_start( d->ctx, patterns, 0, dp ? dp->data : 0 ); 00294 } 00295 00296 00297 ImportResult Context::importKeys( const Data & data ) { 00298 d->lastop = Private::Import; 00299 Data::Private * dp = data.impl(); 00300 d->lasterr = gpgme_op_import( d->ctx, dp ? dp->data : 0 ); 00301 return ImportResult( d->ctx, d->lasterr ); 00302 } 00303 00304 Error Context::startKeyImport( const Data & data ) { 00305 d->lastop = Private::Import; 00306 Data::Private * dp = data.impl(); 00307 return d->lasterr = gpgme_op_import_start( d->ctx, dp ? dp->data : 0 ); 00308 } 00309 00310 ImportResult Context::importResult() const { 00311 if ( d->lastop & Private::Import ) 00312 return ImportResult( d->ctx, d->lasterr ); 00313 else 00314 return ImportResult(); 00315 } 00316 00317 Error Context::deleteKey( const Key & key, bool allowSecretKeyDeletion ) { 00318 d->lastop = Private::Delete; 00319 return d->lasterr = gpgme_op_delete( d->ctx, key.impl(), int( allowSecretKeyDeletion ) ); 00320 } 00321 00322 Error Context::startKeyDeletion( const Key & key, bool allowSecretKeyDeletion ) { 00323 d->lastop = Private::Delete; 00324 return d->lasterr = gpgme_op_delete_start( d->ctx, key.impl(), int( allowSecretKeyDeletion ) ); 00325 } 00326 00327 Error Context::startTrustItemListing( const char * pattern, int maxLevel ) { 00328 d->lastop = Private::TrustList; 00329 return d->lasterr = gpgme_op_trustlist_start( d->ctx, pattern, maxLevel ); 00330 } 00331 00332 TrustItem Context::nextTrustItem( Error & e ) { 00333 gpgme_trust_item_t ti = 0; 00334 e = d->lasterr = gpgme_op_trustlist_next( d->ctx, &ti ); 00335 return ti; 00336 } 00337 00338 Error Context::endTrustItemListing() { 00339 return d->lasterr = gpgme_op_trustlist_end( d->ctx ); 00340 } 00341 00342 DecryptionResult Context::decrypt( const Data & cipherText, Data & plainText ) { 00343 d->lastop = Private::Decrypt; 00344 Data::Private * cdp = cipherText.impl(); 00345 Data::Private * pdp = plainText.impl(); 00346 d->lasterr = gpgme_op_decrypt( d->ctx, cdp ? cdp->data : 0, pdp ? pdp->data : 0 ); 00347 return DecryptionResult( d->ctx, d->lasterr ); 00348 } 00349 00350 Error Context::startDecryption( const Data & cipherText, Data & plainText ) { 00351 d->lastop = Private::Decrypt; 00352 Data::Private * cdp = cipherText.impl(); 00353 Data::Private * pdp = plainText.impl(); 00354 return d->lasterr = gpgme_op_decrypt_start( d->ctx, cdp ? cdp->data : 0, pdp ? pdp->data : 0 ); 00355 } 00356 00357 DecryptionResult Context::decryptionResult() const { 00358 if ( d->lastop & Private::Decrypt ) 00359 return DecryptionResult( d->ctx, d->lasterr ); 00360 else 00361 return DecryptionResult(); 00362 } 00363 00364 00365 00366 VerificationResult Context::verifyDetachedSignature( const Data & signature, const Data & signedText ) { 00367 d->lastop = Private::Verify; 00368 Data::Private * sdp = signature.impl(); 00369 Data::Private * tdp = signedText.impl(); 00370 d->lasterr = gpgme_op_verify( d->ctx, sdp ? sdp->data : 0, tdp ? tdp->data : 0, 0 ); 00371 return VerificationResult( d->ctx, d->lasterr ); 00372 } 00373 00374 VerificationResult Context::verifyOpaqueSignature( const Data & signedData, Data & plainText ) { 00375 d->lastop = Private::Verify; 00376 Data::Private * sdp = signedData.impl(); 00377 Data::Private * pdp = plainText.impl(); 00378 d->lasterr = gpgme_op_verify( d->ctx, sdp ? sdp->data : 0, 0, pdp ? pdp->data : 0 ); 00379 return VerificationResult( d->ctx, d->lasterr ); 00380 } 00381 00382 Error Context::startDetachedSignatureVerification( const Data & signature, const Data & signedText ) { 00383 d->lastop = Private::Verify; 00384 Data::Private * sdp = signature.impl(); 00385 Data::Private * tdp = signedText.impl(); 00386 return d->lasterr = gpgme_op_verify_start( d->ctx, sdp ? sdp->data : 0, tdp ? tdp->data : 0, 0 ); 00387 } 00388 00389 Error Context::startOpaqueSignatureVerification( const Data & signedData, Data & plainText ) { 00390 d->lastop = Private::Verify; 00391 Data::Private * sdp = signedData.impl(); 00392 Data::Private * pdp = plainText.impl(); 00393 return d->lasterr = gpgme_op_verify_start( d->ctx, sdp ? sdp->data : 0, 0, pdp ? pdp->data : 0 ); 00394 } 00395 00396 VerificationResult Context::verificationResult() const { 00397 if ( d->lastop & Private::Verify ) 00398 return VerificationResult( d->ctx, d->lasterr ); 00399 else 00400 return VerificationResult(); 00401 } 00402 00403 00404 std::pair<DecryptionResult,VerificationResult> Context::decryptAndVerify( const Data & cipherText, Data & plainText ) { 00405 d->lastop = Private::DecryptAndVerify; 00406 Data::Private * cdp = cipherText.impl(); 00407 Data::Private * pdp = plainText.impl(); 00408 d->lasterr = gpgme_op_decrypt_verify( d->ctx, cdp ? cdp->data : 0, pdp ? pdp->data : 0 ); 00409 return std::make_pair( DecryptionResult( d->ctx, d->lasterr ), 00410 VerificationResult( d->ctx, d->lasterr ) ); 00411 } 00412 00413 Error Context::startCombinedDecryptionAndVerification( const Data & cipherText, Data & plainText ) { 00414 d->lastop = Private::DecryptAndVerify; 00415 Data::Private * cdp = cipherText.impl(); 00416 Data::Private * pdp = plainText.impl(); 00417 return d->lasterr = gpgme_op_decrypt_verify_start( d->ctx, cdp ? cdp->data : 0, pdp ? pdp->data : 0 ); 00418 } 00419 00420 00421 00422 00423 void Context::clearSigningKeys() { 00424 gpgme_signers_clear( d->ctx ); 00425 } 00426 00427 Error Context::addSigningKey( const Key & key ) { 00428 return d->lasterr = gpgme_signers_add( d->ctx, key.impl() ); 00429 } 00430 00431 Key Context::signingKey( unsigned int idx ) const { 00432 gpgme_key_t key = gpgme_signers_enum( d->ctx, idx ); 00433 return Key( key, false, keyListMode() ); 00434 } 00435 00436 00437 static gpgme_sig_mode_t sigmode2sigmode( Context::SignatureMode mode ) { 00438 switch ( mode ) { 00439 default: 00440 case Context::Normal: return GPGME_SIG_MODE_NORMAL; 00441 case Context::Detached: return GPGME_SIG_MODE_DETACH; 00442 case Context::Clearsigned: return GPGME_SIG_MODE_CLEAR; 00443 } 00444 } 00445 00446 SigningResult Context::sign( const Data & plainText, Data & signature, SignatureMode mode ) { 00447 d->lastop = Private::Sign; 00448 Data::Private * pdp = plainText.impl(); 00449 Data::Private * sdp = signature.impl(); 00450 d->lasterr = gpgme_op_sign( d->ctx, pdp ? pdp->data : 0, sdp ? sdp->data : 0, sigmode2sigmode( mode ) ); 00451 return SigningResult( d->ctx, d->lasterr ); 00452 } 00453 00454 00455 Error Context::startSigning( const Data & plainText, Data & signature, SignatureMode mode ) { 00456 d->lastop = Private::Sign; 00457 Data::Private * pdp = plainText.impl(); 00458 Data::Private * sdp = signature.impl(); 00459 return d->lasterr = gpgme_op_sign_start( d->ctx, pdp ? pdp->data : 0, sdp ? sdp->data : 0, sigmode2sigmode( mode ) ); 00460 } 00461 00462 SigningResult Context::signingResult() const { 00463 if ( d->lastop & Private::Sign ) 00464 return SigningResult( d->ctx, d->lasterr ); 00465 else 00466 return SigningResult(); 00467 } 00468 00469 00470 EncryptionResult Context::encrypt( const std::vector<Key> & recipients, const Data & plainText, Data & cipherText, EncryptionFlags flags ) { 00471 d->lastop = Private::Encrypt; 00472 Data::Private * pdp = plainText.impl(); 00473 Data::Private * cdp = cipherText.impl(); 00474 gpgme_key_t * keys = new gpgme_key_t[ recipients.size() + 1 ]; 00475 gpgme_key_t * keys_it = keys; 00476 for ( std::vector<Key>::const_iterator it = recipients.begin() ; it != recipients.end() ; ++it ) 00477 if ( it->impl() ) 00478 *keys_it++ = it->impl(); 00479 *keys_it++ = 0; 00480 d->lasterr = gpgme_op_encrypt( d->ctx, keys, 00481 flags & AlwaysTrust ? GPGME_ENCRYPT_ALWAYS_TRUST : (gpgme_encrypt_flags_t)0, 00482 pdp ? pdp->data : 0, cdp ? cdp->data : 0 ); 00483 delete[] keys; 00484 return EncryptionResult( d->ctx, d->lasterr ); 00485 } 00486 00487 Error Context::encryptSymmetrically( const Data & plainText, Data & cipherText ) { 00488 d->lastop = Private::Encrypt; 00489 Data::Private * pdp = plainText.impl(); 00490 Data::Private * cdp = cipherText.impl(); 00491 return d->lasterr = gpgme_op_encrypt( d->ctx, 0, (gpgme_encrypt_flags_t)0, 00492 pdp ? pdp->data : 0, cdp ? cdp->data : 0 ); 00493 } 00494 00495 Error Context::startEncryption( const std::vector<Key> & recipients, const Data & plainText, Data & cipherText, EncryptionFlags flags ) { 00496 d->lastop = Private::Encrypt; 00497 Data::Private * pdp = plainText.impl(); 00498 Data::Private * cdp = cipherText.impl(); 00499 gpgme_key_t * keys = new gpgme_key_t[ recipients.size() + 1 ]; 00500 gpgme_key_t * keys_it = keys; 00501 for ( std::vector<Key>::const_iterator it = recipients.begin() ; it != recipients.end() ; ++it ) 00502 if ( it->impl() ) 00503 *keys_it++ = it->impl(); 00504 *keys_it++ = 0; 00505 d->lasterr = gpgme_op_encrypt_start( d->ctx, keys, 00506 flags & AlwaysTrust ? GPGME_ENCRYPT_ALWAYS_TRUST : (gpgme_encrypt_flags_t)0, 00507 pdp ? pdp->data : 0, cdp ? cdp->data : 0 ); 00508 delete[] keys; 00509 return d->lasterr; 00510 } 00511 00512 EncryptionResult Context::encryptionResult() const { 00513 if ( d->lastop & Private::Encrypt ) 00514 return EncryptionResult( d->ctx, d->lasterr ); 00515 else 00516 return EncryptionResult(); 00517 } 00518 00519 std::pair<SigningResult,EncryptionResult> Context::signAndEncrypt( const std::vector<Key> & recipients, const Data & plainText, Data & cipherText, EncryptionFlags flags ) { 00520 d->lastop = Private::SignAndEncrypt; 00521 Data::Private * pdp = plainText.impl(); 00522 Data::Private * cdp = cipherText.impl(); 00523 gpgme_key_t * keys = new gpgme_key_t[ recipients.size() + 1 ]; 00524 gpgme_key_t * keys_it = keys; 00525 for ( std::vector<Key>::const_iterator it = recipients.begin() ; it != recipients.end() ; ++it ) 00526 if ( it->impl() ) 00527 *keys_it++ = it->impl(); 00528 *keys_it++ = 0; 00529 d->lasterr = gpgme_op_encrypt_sign( d->ctx, keys, 00530 flags & AlwaysTrust ? GPGME_ENCRYPT_ALWAYS_TRUST : (gpgme_encrypt_flags_t)0, 00531 pdp ? pdp->data : 0, cdp ? cdp->data : 0 ); 00532 delete[] keys; 00533 return std::make_pair( SigningResult( d->ctx, d->lasterr ), 00534 EncryptionResult( d->ctx, d->lasterr ) ); 00535 } 00536 00537 Error Context::startCombinedSigningAndEncryption( const std::vector<Key> & recipients, const Data & plainText, Data & cipherText, EncryptionFlags flags ) { 00538 d->lastop = Private::SignAndEncrypt; 00539 Data::Private * pdp = plainText.impl(); 00540 Data::Private * cdp = cipherText.impl(); 00541 gpgme_key_t * keys = new gpgme_key_t[ recipients.size() + 1 ]; 00542 gpgme_key_t * keys_it = keys; 00543 for ( std::vector<Key>::const_iterator it = recipients.begin() ; it != recipients.end() ; ++it ) 00544 if ( it->impl() ) 00545 *keys_it++ = it->impl(); 00546 *keys_it++ = 0; 00547 d->lasterr = gpgme_op_encrypt_sign_start( d->ctx, keys, 00548 flags & AlwaysTrust ? GPGME_ENCRYPT_ALWAYS_TRUST : (gpgme_encrypt_flags_t)0, 00549 pdp ? pdp->data : 0, cdp ? cdp->data : 0 ); 00550 delete[] keys; 00551 return d->lasterr; 00552 } 00553 00554 00555 Error Context::cancelPendingOperation() { 00556 #ifdef HAVE_GPGME_CANCEL 00557 return gpgme_cancel( d->ctx ); 00558 #else 00559 return 0; 00560 #endif 00561 } 00562 00563 bool Context::poll() { 00564 gpgme_error_t e = GPG_ERR_NO_ERROR; 00565 const bool finished = gpgme_wait( d->ctx, &e, 0 ); 00566 if ( finished ) 00567 d->lasterr = e; 00568 return finished; 00569 } 00570 00571 Error Context::wait() { 00572 gpgme_error_t e = GPG_ERR_NO_ERROR; 00573 gpgme_wait( d->ctx, &e, 1 ); 00574 return d->lasterr = e; 00575 } 00576 00577 Error Context::lastError() const { 00578 return d->lasterr; 00579 } 00580 00581 00582 } // namespace GpgME 00583 00584 GpgME::Error GpgME::setDefaultLocale( int cat, const char * val ) { 00585 return gpgme_set_locale( 0, cat, val ); 00586 } 00587 00588 GpgME::EngineInfo GpgME::engineInfo( Context::Protocol proto ) { 00589 gpgme_engine_info_t ei = 0; 00590 if ( gpgme_get_engine_info( &ei ) ) 00591 return EngineInfo(); 00592 00593 gpgme_protocol_t p = proto == Context::CMS ? GPGME_PROTOCOL_CMS : GPGME_PROTOCOL_OpenPGP ; 00594 00595 for ( gpgme_engine_info_t i = ei ; i ; i = i->next ) 00596 if ( i->protocol == p ) 00597 return EngineInfo( i ); 00598 00599 return EngineInfo(); 00600 } 00601 00602 GpgME::Error GpgME::checkEngine( Context::Protocol proto ) { 00603 gpgme_protocol_t p = proto == Context::CMS ? GPGME_PROTOCOL_CMS : GPGME_PROTOCOL_OpenPGP ; 00604 00605 return gpgme_engine_check_version( p ); 00606 } 00607
KDE Logo
This file is part of the documentation for libkdenetwork Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:16 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003