diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch) | |
tree | 67208f7c145782a7e90b123b982ca78d88cc2c87 /libkpgp/kpgpblock.cpp | |
download | tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'libkpgp/kpgpblock.cpp')
-rw-r--r-- | libkpgp/kpgpblock.cpp | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/libkpgp/kpgpblock.cpp b/libkpgp/kpgpblock.cpp new file mode 100644 index 000000000..8bf551199 --- /dev/null +++ b/libkpgp/kpgpblock.cpp @@ -0,0 +1,136 @@ +/* + kpgpblock.cpp + + Copyright (C) 2001,2002 the KPGP authors + See file AUTHORS.kpgp for details + + This file is part of KPGP, the KDE PGP/GnuPG support library. + + KPGP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "kpgpblock.h" +#include "kpgp.h" + +#include <string.h> + +namespace Kpgp { + +Block::Block( const QCString& str ) + : mText(str), mProcessedText(), mError(), + mSignatureUserId(), mSignatureKeyId(), mSignatureDate(), + mRequiredKey(), mEncryptedFor(), + mStatus(0), mHasBeenProcessed(false), mType(NoPgpBlock) +{ + mEncryptedFor.setAutoDelete( true ); +} + +Block::~Block() +{ +} + +void +Block::reset() +{ + mProcessedText = QCString(); + mError = QCString(); + mSignatureUserId = QString::null; + mSignatureKeyId = QCString(); + mSignatureDate = QCString(); + mRequiredKey = QCString(); + mEncryptedFor.clear(); + mStatus = 0; + mHasBeenProcessed = false; +} + +void +Block::clear() +{ + reset(); + mText = QCString(); + mType = NoPgpBlock; +} + +BlockType +Block::determineType() const +{ + if( !strncmp( mText.data(), "-----BEGIN PGP ", 15 ) ) + { + if( !strncmp( mText.data() + 15, "SIGNED", 6 ) ) + return ClearsignedBlock; + else if( !strncmp( mText.data() + 15, "SIGNATURE", 9 ) ) + return SignatureBlock; + else if( !strncmp( mText.data() + 15, "PUBLIC", 6 ) ) + return PublicKeyBlock; + else if( !strncmp( mText.data() + 15, "PRIVATE", 7 ) || + !strncmp( mText.data() + 15, "SECRET", 6 ) ) + return PrivateKeyBlock; + else if( !strncmp( mText.data() + 15, "MESSAGE", 7 ) ) + { + if( !strncmp( mText.data() + 22, ", PART", 6 ) ) + return MultiPgpMessageBlock; + else + return PgpMessageBlock; + } + else if( !strncmp( mText.data() + 15, "ARMORED FILE", 12 ) ) + return PgpMessageBlock; + else + return UnknownBlock; + } + else + return NoPgpBlock; +} + +bool +Block::decrypt() +{ + Kpgp::Module *pgp = Kpgp::Module::getKpgp(); + + if( pgp == 0 ) + return false; + + return pgp->decrypt( *this ); +} + +bool +Block::verify() +{ + Kpgp::Module *pgp = Kpgp::Module::getKpgp(); + + if( pgp == 0 ) + return false; + + return pgp->verify( *this ); +} + +Kpgp::Result +Block::clearsign( const QCString& keyId, const QCString& charset ) +{ + Kpgp::Module *pgp = Kpgp::Module::getKpgp(); + + if( pgp == 0 ) + return Kpgp::Failure; + + return pgp->clearsign( *this, keyId, charset ); +} + +Kpgp::Result +Block::encrypt( const QStringList& receivers, const QCString& keyId, + const bool sign, const QCString& charset ) +{ + Kpgp::Module *pgp = Kpgp::Module::getKpgp(); + + if( pgp == 0 ) + return Kpgp::Failure; + + return pgp->encrypt( *this, receivers, keyId, sign, charset ); +} + +} // namespace Kpgp |