libkdenetwork Library API Documentation

context.h

00001 /* context.h - 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 // -*- c++ -*- 00021 #ifndef __GPGMEPP_CONTEXT_H__ 00022 #define __GPGMEPP_CONTEXT_H__ 00023 00024 #include <gpgmepp/gpgmefw.h> 00025 00026 #include <vector> 00027 #include <utility> 00028 00029 namespace GpgME { 00030 00031 class Key; 00032 class Data; 00033 class TrustItem; 00034 class ProgressProvider; 00035 class PassphraseProvider; 00036 class EventLoopInteractor; 00037 00038 class KeyListResult; 00039 class KeyGenerationResult; 00040 class ImportResult; 00041 class DecryptionResult; 00042 class VerificationResult; 00043 class SigningResult; 00044 class EncryptionResult; 00045 00046 class EngineInfo; 00047 00048 class Error { 00049 public: 00050 Error( int e ) : mErr( e ) {} 00051 00052 const char * source() const; 00053 const char * asString() const; 00054 00055 bool isCanceled() const; 00056 00057 operator int() const { return mErr; } 00058 operator bool() const { return mErr && !isCanceled(); } 00059 private: 00060 int mErr; 00061 }; 00062 00063 class Context { 00064 Context( gpgme_ctx_t ); 00065 public: 00066 enum Protocol { OpenPGP, CMS, Unknown }; 00067 00068 // 00069 // Creation and destruction: 00070 // 00071 00072 static Context * createForProtocol( Protocol proto ); 00073 virtual ~Context(); 00074 00075 // 00076 // Context Attributes 00077 // 00078 00079 Protocol protocol() const; 00080 00081 void setArmor( bool useArmor ); 00082 bool armor() const; 00083 00084 void setTextMode( bool useTextMode ); 00085 bool textMode() const; 00086 00087 enum CertificateInclusion { 00088 AllCertificatesExceptRoot = -2, 00089 AllCertificates = -1, 00090 NoCertificates = 0, 00091 OnlySenderCertificate = 1 00092 }; 00093 void setIncludeCertificates( int which ); 00094 int includeCertificates() const; 00095 00096 enum KeyListMode { 00097 Local = 0x1, 00098 Extern = 0x2, 00099 Signatures = 0x4, 00100 Validate = 0x10 00101 }; 00102 void setKeyListMode( unsigned int keyListMode ); 00103 void addKeyListMode( unsigned int keyListMode ); 00104 unsigned int keyListMode() const; 00105 00106 void setPassphraseProvider( PassphraseProvider * provider ); 00107 PassphraseProvider * passphraseProvider() const; 00108 00109 void setProgressProvider( ProgressProvider * provider ); 00110 ProgressProvider * progressProvider() const; 00111 00112 void setManagedByEventLoopInteractor( bool managed ); 00113 bool managedByEventLoopInteractor() const; 00114 00115 GpgME::Error setLocale( int category, const char * value ); 00116 00117 private: 00118 friend class EventLoopInteractor; 00119 void installIOCallbacks( gpgme_io_cbs * iocbs ); 00120 void uninstallIOCallbacks(); 00121 00122 public: 00123 // 00124 // 00125 // Key Management 00126 // 00127 // 00128 00129 // 00130 // Key Listing 00131 // 00132 00133 GpgME::Error startKeyListing( const char * pattern=0, bool secretOnly=false ); 00134 GpgME::Error startKeyListing( const char * patterns[], bool secretOnly=false ); 00135 00136 Key nextKey( GpgME::Error & e ); 00137 00138 KeyListResult endKeyListing(); 00139 KeyListResult keyListResult() const; 00140 00141 Key key( const char * fingerprint, GpgME::Error & e, bool secret=false ); 00142 00143 // 00144 // Key Generation 00145 // 00146 00147 KeyGenerationResult generateKey( const char * parameters, Data & pubKey ); 00148 GpgME::Error startKeyGeneration( const char * parameters, Data & pubkey ); 00149 KeyGenerationResult keyGenerationResult() const; 00150 00151 // 00152 // Key Export 00153 // 00154 00155 GpgME::Error exportPublicKeys( const char * pattern, Data & keyData ); 00156 GpgME::Error exportPublicKeys( const char * pattern[], Data & keyData ); 00157 GpgME::Error startPublicKeyExport( const char * pattern, Data & keyData ); 00158 GpgME::Error startPublicKeyExport( const char * pattern[], Data & keyData ); 00159 00160 // 00161 // Key Import 00162 // 00163 00164 ImportResult importKeys( const Data & data ); 00165 GpgME::Error startKeyImport( const Data & data ); 00166 ImportResult importResult() const; 00167 00168 // 00169 // Key Deletion 00170 // 00171 00172 GpgME::Error deleteKey( const Key & key, bool allowSecretKeyDeletion=false ); 00173 GpgME::Error startKeyDeletion( const Key & key, bool allowSecretKeyDeletion=false ); 00174 00175 // 00176 // Trust Item Management 00177 // 00178 00179 GpgME::Error startTrustItemListing( const char * pattern, int maxLevel ); 00180 TrustItem nextTrustItem( GpgME::Error & e ); 00181 GpgME::Error endTrustItemListing(); 00182 00183 // 00184 // 00185 // Crypto Operations 00186 // 00187 // 00188 00189 // 00190 // Decryption 00191 // 00192 00193 DecryptionResult decrypt( const Data & cipherText, Data & plainText ); 00194 GpgME::Error startDecryption( const Data & cipherText, Data & plainText ); 00195 DecryptionResult decryptionResult() const; 00196 00197 // 00198 // Signature Verification 00199 // 00200 00201 VerificationResult verifyDetachedSignature( const Data & signature, const Data & signedText ); 00202 VerificationResult verifyOpaqueSignature( const Data & signedData, Data & plainText ); 00203 GpgME::Error startDetachedSignatureVerification( const Data & signature, const Data & signedText ); 00204 GpgME::Error startOpaqueSignatureVerification( const Data & signedData, Data & plainText ); 00205 VerificationResult verificationResult() const; 00206 00207 // 00208 // Combined Decryption and Signature Verification 00209 // 00210 00211 std::pair<DecryptionResult,VerificationResult> decryptAndVerify( const Data & cipherText, Data & plainText ); 00212 GpgME::Error startCombinedDecryptionAndVerification( const Data & cipherText, Data & plainText ); 00213 // use verificationResult() and decryptionResult() to retrieve the result objects... 00214 00215 // 00216 // Signing 00217 // 00218 00219 void clearSigningKeys(); 00220 GpgME::Error addSigningKey( const Key & signer ); 00221 Key signingKey( unsigned int index ) const; 00222 00223 enum SignatureMode { Normal, Detached, Clearsigned }; 00224 SigningResult sign( const Data & plainText, Data & signature, SignatureMode mode ); 00225 GpgME::Error startSigning( const Data & plainText, Data & signature, SignatureMode mode ); 00226 SigningResult signingResult() const; 00227 00228 // 00229 // Encryption 00230 // 00231 00232 enum EncryptionFlags { None=0, AlwaysTrust=1 }; 00233 EncryptionResult encrypt( const std::vector<Key> & recipients, const Data & plainText, Data & cipherText, EncryptionFlags flags ); 00234 GpgME::Error encryptSymmetrically( const Data & plainText, Data & cipherText ); 00235 GpgME::Error startEncryption( const std::vector<Key> & recipients, const Data & plainText, Data & cipherText, EncryptionFlags flags ); 00236 EncryptionResult encryptionResult() const; 00237 00238 // 00239 // Combined Signing and Encryption 00240 // 00241 00242 std::pair<SigningResult,EncryptionResult> signAndEncrypt( const std::vector<Key> & recipients, const Data & plainText, Data & cipherText, EncryptionFlags flags ); 00243 GpgME::Error startCombinedSigningAndEncryption( const std::vector<Key> & recipients, const Data & plainText, Data & cipherText, EncryptionFlags flags ); 00244 // use encryptionResult() and signingResult() to retrieve the result objects... 00245 00246 // 00247 // 00248 // Run Control 00249 // 00250 // 00251 00252 bool poll(); 00253 GpgME::Error wait(); 00254 GpgME::Error lastError() const; 00255 GpgME::Error cancelPendingOperation(); 00256 00257 class Private; 00258 Private * impl() const { return d; } 00259 private: 00260 Private * d; 00261 00262 private: // disable... 00263 Context( const Context & ); 00264 const Context & operator=( const Context & ); 00265 }; 00266 00267 // 00268 // 00269 // Globals 00270 // 00271 // 00272 00273 GpgME::Error setDefaultLocale( int category, const char * value ); 00274 00275 Context * wait( GpgME::Error & e, bool hang=true ); 00276 typedef void (*IdleFunction)(void); 00277 IdleFunction registerIdleFunction( IdleFunction idleFunction ); 00278 00279 typedef void (*IOCallback)( void * data, int fd ); 00280 00281 EngineInfo engineInfo( Context::Protocol proto ); 00282 00283 GpgME::Error checkEngine( Context::Protocol proto ); 00284 00285 } // namespace GpgME 00286 00287 #endif // __GPGMEPP_CONTEXT_H__
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