kpgpblock.h
00001 /* 00002 kpgpblock.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 KPGPBLOCK_H 00020 #define KPGPBLOCK_H 00021 00022 #include <tqcstring.h> 00023 #include <tqstring.h> 00024 #include <tqstrlist.h> 00025 00026 #include <kdepimmacros.h> 00027 00028 //#include <tqstringlist.h> 00029 class TQStringList; 00030 00031 #include "kpgp.h" 00032 00033 namespace Kpgp { 00034 00035 typedef enum { 00036 UnknownBlock = -1, // BEGIN PGP ??? 00037 NoPgpBlock = 0, 00038 PgpMessageBlock = 1, // BEGIN PGP MESSAGE 00039 MultiPgpMessageBlock = 2, // BEGIN PGP MESSAGE, PART X[/Y] 00040 SignatureBlock = 3, // BEGIN PGP SIGNATURE 00041 ClearsignedBlock = 4, // BEGIN PGP SIGNED MESSAGE 00042 PublicKeyBlock = 5, // BEGIN PGP PUBLIC KEY BLOCK 00043 PrivateKeyBlock = 6 // BEGIN PGP PRIVATE KEY BLOCK (PGP 2.x: ...SECRET...) 00044 } BlockType; 00045 00046 typedef enum { 00047 OK = 0x0000, 00048 CLEARTEXT = 0x0000, 00049 RUN_ERR = 0x0001, 00050 ERROR = 0x0001, 00051 ENCRYPTED = 0x0002, 00052 SIGNED = 0x0004, 00053 GOODSIG = 0x0008, 00054 ERR_SIGNING = 0x0010, 00055 UNKNOWN_SIG = 0x0020, 00056 BADPHRASE = 0x0040, 00057 BADKEYS = 0x0080, 00058 NO_SEC_KEY = 0x0100, 00059 MISSINGKEY = 0x0200, 00060 CANCEL = 0x8000 00061 } MessageStatus; 00062 00063 class Base; 00064 class Module; 00065 00066 /* 00067 * BEGIN PGP MESSAGE 00068 * Used for signed, encrypted, or compressed files. 00069 * 00070 * BEGIN PGP PUBLIC KEY BLOCK 00071 * Used for armoring public keys 00072 * 00073 * BEGIN PGP PRIVATE KEY BLOCK (PGP 2.x: BEGIN PGP SECRET KEY BLOCK) 00074 * Used for armoring private keys 00075 * 00076 * BEGIN PGP MESSAGE, PART X/Y 00077 * Used for multi-part messages, where the armor is split amongst Y 00078 * parts, and this is the Xth part out of Y. 00079 * 00080 * BEGIN PGP MESSAGE, PART X 00081 * Used for multi-part messages, where this is the Xth part of an 00082 * unspecified number of parts. Requires the MESSAGE-ID Armor 00083 * Header to be used. 00084 * 00085 * BEGIN PGP SIGNATURE 00086 * Used for detached signatures, OpenPGP/MIME signatures, and 00087 * signatures following clearsigned messages. Note that PGP 2.x 00088 * uses BEGIN PGP MESSAGE for detached signatures. 00089 * 00090 * BEGIN PGP SIGNED MESSAGE 00091 * Used for cleartext signed messages. 00092 */ 00093 class KDE_EXPORT Block 00094 { 00095 public: 00096 00097 Block( const TQCString& str = TQCString() ); 00098 ~Block(); 00099 00100 TQCString text() const; 00101 void setText( const TQCString& str ); 00102 00103 void setProcessedText( const TQCString& str ); 00104 00105 int status() const; 00106 void setStatus( const int status ); 00107 00108 BlockType type(); 00109 00111 bool isEncrypted() const; 00112 00114 bool isSigned() const; 00115 00117 bool goodSignature() const; 00118 00121 TQString signatureUserId() const; 00122 void setSignatureUserId( const TQString& userId ); 00123 00125 TQCString signatureKeyId() const; 00126 void setSignatureKeyId( const TQCString& keyId ); 00127 00130 TQCString signatureDate() const; 00131 void setSignatureDate( const TQCString& date ); 00132 00134 const TQStrList encryptedFor() const; 00135 00138 TQString requiredKey() const; 00139 void setRequiredKey( const TQCString& keyId ); 00140 00141 TQString requiredUserId() const; 00142 void setRequiredUserId( const TQString& userId ); 00143 00144 TQCString error() const; 00145 void setError( const TQCString& str ); 00146 00148 void reset(); 00149 00152 bool decrypt(); 00153 00155 bool verify(); 00156 00163 Kpgp::Result clearsign( const TQCString& keyId, 00164 const TQCString& charset = TQCString() ); 00165 00172 Kpgp::Result encrypt( const TQStringList& receivers, const TQCString& keyId, 00173 const bool sign, const TQCString& charset = TQCString() ); 00174 00175 private: 00176 void clear(); 00177 00178 BlockType determineType() const; 00179 00180 TQCString mText; 00181 TQCString mProcessedText; 00182 TQCString mError; 00183 TQString mSignatureUserId; 00184 TQCString mSignatureKeyId; 00185 TQCString mSignatureDate; 00186 TQCString mRequiredKey; 00187 TQString mRequiredUserId; 00188 TQStrList mEncryptedFor; 00189 int mStatus; 00190 bool mHasBeenProcessed; 00191 BlockType mType; 00192 }; 00193 00194 // -- inlined member functions --------------------------------------------- 00195 00196 inline TQCString 00197 Block::text() const 00198 { 00199 if( mHasBeenProcessed ) 00200 return mProcessedText; 00201 else 00202 return mText; 00203 } 00204 00205 inline void 00206 Block::setText( const TQCString& str ) 00207 { 00208 clear(); 00209 mText = str; 00210 } 00211 00212 inline void 00213 Block::setProcessedText( const TQCString& str ) 00214 { 00215 mProcessedText = str; 00216 mHasBeenProcessed = true; 00217 } 00218 00219 inline TQCString 00220 Block::error() const 00221 { 00222 return mError; 00223 } 00224 00225 inline void 00226 Block::setError( const TQCString& str ) 00227 { 00228 mError = str; 00229 } 00230 00231 inline int 00232 Block::status() const 00233 { 00234 return mStatus; 00235 } 00236 00237 inline void 00238 Block::setStatus( const int status ) 00239 { 00240 mStatus = status; 00241 } 00242 00243 inline BlockType 00244 Block::type() 00245 { 00246 if( mType == NoPgpBlock ) 00247 mType = determineType(); 00248 return mType; 00249 } 00250 00251 inline TQString 00252 Block::signatureUserId() const 00253 { 00254 return mSignatureUserId; 00255 } 00256 00257 inline void 00258 Block::setSignatureUserId( const TQString& userId ) 00259 { 00260 mSignatureUserId = userId; 00261 } 00262 00263 inline TQCString 00264 Block::signatureKeyId() const 00265 { 00266 return mSignatureKeyId; 00267 } 00268 00269 inline void 00270 Block::setSignatureKeyId( const TQCString& keyId ) 00271 { 00272 mSignatureKeyId = keyId; 00273 } 00274 00275 inline TQCString 00276 Block::signatureDate() const 00277 { 00278 return mSignatureDate; 00279 } 00280 00281 inline void 00282 Block::setSignatureDate( const TQCString& date ) 00283 { 00284 mSignatureDate = date; 00285 } 00286 00287 inline TQString 00288 Block::requiredKey() const 00289 { 00290 return mRequiredKey; 00291 } 00292 00293 inline void 00294 Block::setRequiredKey( const TQCString& keyId ) 00295 { 00296 mRequiredKey = keyId; 00297 } 00298 00299 inline TQString 00300 Block::requiredUserId() const 00301 { 00302 return mRequiredUserId; 00303 } 00304 00305 inline void 00306 Block::setRequiredUserId( const TQString& userId ) 00307 { 00308 mRequiredUserId = userId; 00309 } 00310 00311 inline const TQStrList 00312 Block::encryptedFor() const 00313 { 00314 return mEncryptedFor; 00315 } 00316 00317 inline bool 00318 Block::isEncrypted() const 00319 { 00320 if( mStatus & ENCRYPTED ) 00321 return true; 00322 return false; 00323 } 00324 00325 inline bool 00326 Block::isSigned() const 00327 { 00328 if( mStatus & SIGNED ) 00329 return true; 00330 return false; 00331 } 00332 00333 inline bool 00334 Block::goodSignature() const 00335 { 00336 if( mStatus & GOODSIG ) 00337 return true; 00338 return false; 00339 } 00340 00341 /* 00342 inline bool 00343 Block::unknownSigner() const 00344 { 00345 if( mStatus & UNKNOWN_SIG ) 00346 return true; 00347 return false; 00348 } 00349 */ 00350 00351 // ------------------------------------------------------------------------- 00352 00353 } // namespace Kpgp 00354 00355 #endif 00356