libkdenetwork Library API Documentation

kpgpblock.cpp

00001 /* 00002 kpgpblock.cpp 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 #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 } // namespace Kpgp
KDE Logo
This file is part of the documentation for libkdenetwork Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:16 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003