00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
#include "kpgpblock.h"
00020
#include "kpgp.h"
00021
00022
#include <string.h>
00023
00024
namespace Kpgp {
00025
00026 Block::Block(
const QCString& str )
00027 : mText(str), mProcessedText(), mError(),
00028 mSignatureUserId(), mSignatureKeyId(), mSignatureDate(),
00029 mRequiredKey(), mEncryptedFor(),
00030 mStatus(0), mHasBeenProcessed(false), mType(NoPgpBlock)
00031 {
00032 mEncryptedFor.setAutoDelete(
true );
00033 }
00034
00035 Block::~Block()
00036 {
00037 }
00038
00039
void
00040 Block::reset()
00041 {
00042 mProcessedText =
QCString();
00043 mError = QCString();
00044 mSignatureUserId = QString::null;
00045 mSignatureKeyId = QCString();
00046 mSignatureDate = QCString();
00047 mRequiredKey = QCString();
00048 mEncryptedFor.clear();
00049 mStatus = 0;
00050 mHasBeenProcessed =
false;
00051 }
00052
00053
void
00054 Block::clear()
00055 {
00056
reset();
00057 mText =
QCString();
00058 mType = NoPgpBlock;
00059 }
00060
00061 BlockType
00062 Block::determineType()
const
00063
{
00064
if( !strncmp( mText.data(),
"-----BEGIN PGP ", 15 ) )
00065 {
00066
if( !strncmp( mText.data() + 15,
"SIGNED", 6 ) )
00067
return ClearsignedBlock;
00068
else if( !strncmp( mText.data() + 15,
"SIGNATURE", 9 ) )
00069
return SignatureBlock;
00070
else if( !strncmp( mText.data() + 15,
"PUBLIC", 6 ) )
00071
return PublicKeyBlock;
00072
else if( !strncmp( mText.data() + 15,
"PRIVATE", 7 ) ||
00073 !strncmp( mText.data() + 15,
"SECRET", 6 ) )
00074
return PrivateKeyBlock;
00075
else if( !strncmp( mText.data() + 15,
"MESSAGE", 7 ) )
00076 {
00077
if( !strncmp( mText.data() + 22,
", PART", 6 ) )
00078
return MultiPgpMessageBlock;
00079
else
00080
return PgpMessageBlock;
00081 }
00082
else if( !strncmp( mText.data() + 15,
"ARMORED FILE", 12 ) )
00083
return PgpMessageBlock;
00084
else
00085
return UnknownBlock;
00086 }
00087
else
00088
return NoPgpBlock;
00089 }
00090
00091
bool
00092 Block::decrypt()
00093 {
00094 Kpgp::Module *pgp = Kpgp::Module::getKpgp();
00095
00096
if( pgp == 0 )
00097
return false;
00098
00099
return pgp->decrypt( *
this );
00100 }
00101
00102
bool
00103 Block::verify()
00104 {
00105 Kpgp::Module *pgp = Kpgp::Module::getKpgp();
00106
00107
if( pgp == 0 )
00108
return false;
00109
00110
return pgp->verify( *
this );
00111 }
00112
00113 Kpgp::Result
00114 Block::clearsign(
const QCString& keyId,
const QCString& charset )
00115 {
00116 Kpgp::Module *pgp = Kpgp::Module::getKpgp();
00117
00118
if( pgp == 0 )
00119
return Kpgp::Failure;
00120
00121
return pgp->clearsign( *
this, keyId, charset );
00122 }
00123
00124 Kpgp::Result
00125 Block::encrypt(
const QStringList& receivers,
const QCString& keyId,
00126
const bool sign,
const QCString& charset )
00127 {
00128 Kpgp::Module *pgp = Kpgp::Module::getKpgp();
00129
00130
if( pgp == 0 )
00131
return Kpgp::Failure;
00132
00133
return pgp->encrypt( *
this, receivers, keyId, sign, charset );
00134 }
00135
00136 }