libkdenetwork Library API Documentation

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