kpgpbase.h
00001 /* 00002 kpgpbase.h 00003 00004 Copyright (C) 2001,2002 the KPGP authors 00005 See file AUTHORS.kpgp for details 00006 00007 This file is part of KPGP, the KDE PGP/GnuPG support library. 00008 00009 KPGP is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; either version 2 of the License, or 00012 (at your option) any later version. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software Foundation, 00016 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00017 */ 00018 00019 #ifndef KPGPBASE_H 00020 #define KPGPBASE_H 00021 00022 #include <tqstring.h> 00023 #include <tqcstring.h> 00024 #include <tqstringlist.h> 00025 00026 #include "kpgpkey.h" 00027 #include "kpgpblock.h" 00028 00029 namespace Kpgp { 00030 00031 class Base 00032 { 00033 public: 00034 00036 Base(); 00037 virtual ~Base(); 00038 00039 00041 virtual int encrypt( Block& , const KeyIDList& ) { return OK; } 00042 00044 virtual int clearsign( Block& , const char *) { return OK; } 00045 00047 virtual int encsign( Block& , const KeyIDList& , 00048 const char * = 0) { return OK; } 00049 00051 virtual int decrypt( Block& , const char * = 0) { return OK; } 00052 00054 virtual int verify( Block& block ) { return decrypt( block, 0 ); } 00055 00056 00062 virtual Key* readPublicKey( const KeyID&, const bool = false, 00063 Key* = 0 ) 00064 { return 0; } 00065 00067 virtual KeyList publicKeys( const TQStringList & = TQStringList() ) 00068 { return KeyList(); } 00069 00071 virtual KeyList secretKeys( const TQStringList & = TQStringList() ) 00072 { return KeyList(); } 00073 00076 virtual TQCString getAsciiPublicKey(const KeyID& ) { return TQCString(); } 00077 00080 virtual int signKey(const KeyID& , const char *) { return OK; } 00081 00082 00085 virtual TQString lastErrorMessage() const; 00086 00087 00088 protected: 00089 virtual int run( const char *cmd, const char *passphrase = 0, 00090 bool onlyReadFromPGP = false ); 00091 virtual int runGpg( const char *cmd, const char *passphrase = 0, 00092 bool onlyReadFromGnuPG = false ); 00093 virtual void clear(); 00094 00095 TQCString addUserId(); 00096 00097 TQCString input; 00098 TQCString output; 00099 TQCString error; 00100 TQString errMsg; 00101 00102 TQCString mVersion; 00103 00104 int status; 00105 00106 }; 00107 00108 // --------------------------------------------------------------------------- 00109 00110 class Base2 : public Base 00111 { 00112 00113 public: 00114 Base2(); 00115 virtual ~Base2(); 00116 00117 virtual int encrypt( Block& block, const KeyIDList& recipients ); 00118 virtual int clearsign( Block& block, const char *passphrase ); 00119 virtual int encsign( Block& block, const KeyIDList& recipients, 00120 const char *passphrase = 0 ); 00121 virtual int decrypt( Block& block, const char *passphrase = 0 ); 00122 virtual int verify( Block& block ) { return decrypt( block, 0 ); } 00123 00124 virtual Key* readPublicKey( const KeyID& keyID, 00125 const bool readTrust = false, 00126 Key* key = 0 ); 00127 virtual KeyList publicKeys( const TQStringList & patterns = TQStringList() ); 00128 virtual KeyList secretKeys( const TQStringList & patterns = TQStringList() ); 00129 virtual TQCString getAsciiPublicKey( const KeyID& keyID ); 00130 virtual int signKey( const KeyID& keyID, const char *passphrase ); 00131 00132 protected: 00133 KeyList doGetPublicKeys( const TQCString & cmd, 00134 const TQStringList & patterns ); 00135 virtual KeyList parseKeyList( const TQCString&, bool ); 00136 00137 private: 00138 Key* parsePublicKeyData( const TQCString& output, Key* key = 0 ); 00139 void parseTrustDataForKey( Key* key, const TQCString& str ); 00140 }; 00141 00142 class BaseG : public Base 00143 { 00144 00145 public: 00146 BaseG(); 00147 virtual ~BaseG(); 00148 00149 virtual int encrypt( Block& block, const KeyIDList& recipients ); 00150 virtual int clearsign( Block& block, const char *passphrase ); 00151 virtual int encsign( Block& block, const KeyIDList& recipients, 00152 const char *passphrase = 0 ); 00153 virtual int decrypt( Block& block, const char *passphrase = 0 ); 00154 virtual int verify( Block& block ) { return decrypt( block, 0 ); } 00155 00156 virtual Key* readPublicKey( const KeyID& keyID, 00157 const bool readTrust = false, 00158 Key* key = 0 ); 00159 virtual KeyList publicKeys( const TQStringList & patterns = TQStringList() ); 00160 virtual KeyList secretKeys( const TQStringList & patterns = TQStringList() ); 00161 virtual TQCString getAsciiPublicKey( const KeyID& keyID ); 00162 virtual int signKey( const KeyID& keyID, const char *passphrase ); 00163 00164 private: 00165 Key* parseKeyData( const TQCString& output, int& offset, Key* key = 0 ); 00166 KeyList parseKeyList( const TQCString&, bool ); 00167 }; 00168 00169 00170 class Base5 : public Base 00171 { 00172 00173 public: 00174 Base5(); 00175 virtual ~Base5(); 00176 00177 virtual int encrypt( Block& block, const KeyIDList& recipients ); 00178 virtual int clearsign( Block& block, const char *passphrase ); 00179 virtual int encsign( Block& block, const KeyIDList& recipients, 00180 const char *passphrase = 0 ); 00181 virtual int decrypt( Block& block, const char *passphrase = 0 ); 00182 virtual int verify( Block& block ) { return decrypt( block, 0 ); } 00183 00184 virtual Key* readPublicKey( const KeyID& keyID, 00185 const bool readTrust = false, 00186 Key* key = 0 ); 00187 virtual KeyList publicKeys( const TQStringList & patterns = TQStringList() ); 00188 virtual KeyList secretKeys( const TQStringList & patterns = TQStringList() ); 00189 virtual TQCString getAsciiPublicKey( const KeyID& keyID ); 00190 virtual int signKey( const KeyID& keyID, const char *passphrase ); 00191 00192 private: 00193 Key* parseKeyData( const TQCString& output, int& offset, Key* key = 0 ); 00194 Key* parseSingleKey( const TQCString& output, Key* key = 0 ); 00195 KeyList parseKeyList( const TQCString& output, bool ); 00196 void parseTrustDataForKey( Key* key, const TQCString& str ); 00197 }; 00198 00199 00200 class Base6 : public Base2 00201 { 00202 00203 public: 00204 Base6(); 00205 virtual ~Base6(); 00206 00207 virtual int decrypt( Block& block, const char *passphrase = 0 ); 00208 virtual int verify( Block& block ) { return decrypt( block, 0 ); } 00209 00210 virtual Key* readPublicKey( const KeyID& keyID, 00211 const bool readTrust = false, 00212 Key* key = 0 ); 00213 virtual KeyList publicKeys( const TQStringList & patterns = TQStringList() ); 00214 virtual KeyList secretKeys( const TQStringList & patterns = TQStringList() ); 00215 00216 virtual int isVersion6(); 00217 00218 protected: 00219 virtual KeyList parseKeyList( const TQCString &, bool ); 00220 00221 private: 00222 Key* parseKeyData( const TQCString& output, int& offset, Key* key = 0 ); 00223 Key* parseSingleKey( const TQCString& output, Key* key = 0 ); 00224 void parseTrustDataForKey( Key* key, const TQCString& str ); 00225 }; 00226 00227 // --------------------------------------------------------------------------- 00228 // inlined functions 00229 00230 inline TQString 00231 Base::lastErrorMessage() const 00232 { 00233 return errMsg; 00234 } 00235 00236 00237 } // namespace Kpgp 00238 00239 #endif