libkpgp

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 <qcstring.h>
00023 #include <qstring.h>
00024 #include <qstrlist.h>
00025 
00026 #include <kdepimmacros.h>
00027 
00028 //#include <qstringlist.h>
00029 class QStringList;
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 QCString& str = QCString() );
00098   ~Block();
00099 
00100   QCString text() const;
00101   void setText( const QCString& str );
00102 
00103   void setProcessedText( const QCString& 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   QString signatureUserId() const;
00122   void setSignatureUserId( const QString& userId );
00123 
00125   QCString signatureKeyId() const;
00126   void setSignatureKeyId( const QCString& keyId );
00127 
00130   QCString signatureDate() const;
00131   void setSignatureDate( const QCString& date );
00132 
00134   const QStrList encryptedFor() const;
00135 
00138   QString requiredKey() const;
00139   void setRequiredKey( const QCString& keyId );
00140 
00141   QString requiredUserId() const;
00142   void setRequiredUserId( const QString& userId );
00143 
00144   QCString error() const;
00145   void setError( const QCString& str );
00146 
00148   void reset();
00149 
00152   bool decrypt();
00153 
00155   bool verify();
00156 
00163   Kpgp::Result clearsign( const QCString& keyId,
00164                   const QCString& charset = QCString() );
00165 
00172   Kpgp::Result encrypt( const QStringList& receivers, const QCString& keyId,
00173                 const bool sign, const QCString& charset = QCString() );
00174 
00175  private:
00176   void clear();
00177 
00178   BlockType determineType() const;
00179 
00180   QCString mText;
00181   QCString mProcessedText;
00182   QCString mError;
00183   QString mSignatureUserId;
00184   QCString mSignatureKeyId;
00185   QCString mSignatureDate;
00186   QCString mRequiredKey;
00187   QString mRequiredUserId;
00188   QStrList mEncryptedFor;
00189   int mStatus;
00190   bool mHasBeenProcessed;
00191   BlockType mType;
00192 };
00193 
00194 // -- inlined member functions ---------------------------------------------
00195 
00196 inline QCString
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 QCString& str )
00207 {
00208   clear();
00209   mText = str;
00210 }
00211 
00212 inline void
00213 Block::setProcessedText( const QCString& str )
00214 {
00215   mProcessedText = str;
00216   mHasBeenProcessed = true;
00217 }
00218 
00219 inline QCString
00220 Block::error() const
00221 {
00222   return mError;
00223 }
00224 
00225 inline void
00226 Block::setError( const QCString& 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 QString
00252 Block::signatureUserId() const
00253 {
00254   return mSignatureUserId;
00255 }
00256 
00257 inline void
00258 Block::setSignatureUserId( const QString& userId )
00259 {
00260   mSignatureUserId = userId;
00261 }
00262 
00263 inline QCString
00264 Block::signatureKeyId() const
00265 {
00266   return mSignatureKeyId;
00267 }
00268 
00269 inline void
00270 Block::setSignatureKeyId( const QCString& keyId )
00271 {
00272   mSignatureKeyId = keyId;
00273 }
00274 
00275 inline QCString
00276 Block::signatureDate() const
00277 {
00278   return mSignatureDate;
00279 }
00280 
00281 inline void
00282 Block::setSignatureDate( const QCString& date )
00283 {
00284   mSignatureDate = date;
00285 }
00286 
00287 inline QString
00288 Block::requiredKey() const
00289 {
00290   return mRequiredKey;
00291 }
00292 
00293 inline void
00294 Block::setRequiredKey( const QCString& keyId )
00295 {
00296   mRequiredKey = keyId;
00297 }
00298 
00299 inline QString
00300 Block::requiredUserId() const
00301 {
00302   return mRequiredUserId;
00303 }
00304 
00305 inline void
00306 Block::setRequiredUserId( const QString& userId )
00307 {
00308   mRequiredUserId = userId;
00309 }
00310 
00311 inline const QStrList
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 
KDE Home | KDE Accessibility Home | Description of Access Keys