00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
class QStringList;
00027
00028
#include "kpgp.h"
00029
00030
namespace Kpgp {
00031
00032
typedef enum {
00033 UnknownBlock = -1,
00034 NoPgpBlock = 0,
00035 PgpMessageBlock = 1,
00036 MultiPgpMessageBlock = 2,
00037 SignatureBlock = 3,
00038 ClearsignedBlock = 4,
00039 PublicKeyBlock = 5,
00040 PrivateKeyBlock = 6
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
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
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
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
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350 }
00351
00352
#endif
00353