libkdenetwork Library API Documentation

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