2
* openpgp.cpp - OpenPGP base
3
* Copyright (C) 2003 Justin Karneges
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
#include<qstringlist.h>
26
using namespace OpenPGP;
29
//----------------------------------------------------------------------------
31
//----------------------------------------------------------------------------
40
const QString & Key::keyID() const
45
const QString & Key::userID() const
50
void Key::setKeyID(const QString &s)
55
void Key::setUserID(const QString &s)
61
//----------------------------------------------------------------------------
63
//----------------------------------------------------------------------------
64
class Request::Private
72
QString enc, sig, keyID;
79
Request::Request(Engine *eng)
93
int Request::type() const
98
void Request::encrypt(const QByteArray &in, const QStringList &keys)
101
d->eng->encrypt(this, in, keys);
104
void Request::decrypt(const QString &in)
107
d->eng->decrypt(this, in);
110
void Request::sign(const QByteArray &in, const QString &keyID)
113
d->eng->sign(this, in, keyID);
116
void Request::verify(const QByteArray &in, const QString &sig)
119
d->eng->verify(this, in, sig);
122
void Request::submitPassphrase(const QString &str)
124
d->eng->submitPassphrase(this, str);
127
void Request::op_encryptFinished(bool b, const QString &str)
134
void Request::op_decryptFinished(bool b, const QByteArray &out)
141
void Request::op_signFinished(bool b, const QString &str)
148
void Request::op_verifyFinished(int x, const QString &str, const QDateTime &ts)
151
if(x != VerifyError) {
163
void Request::op_needPassphrase()
168
QString Request::encrypted() const
173
QByteArray Request::decrypted() const
178
QString Request::signature() const
183
QString Request::keyID() const
188
QDateTime Request::timestamp() const
193
int Request::verifyResult() const
195
return d->verifyResult;
198
void Request::op_setBadPassphrase(bool b)
203
bool Request::badPassphrase() const
209
//----------------------------------------------------------------------------
211
//----------------------------------------------------------------------------
212
Engine::Engine(QObject *parent)
221
void Engine::encryptFinished(Request *r, bool b, const QString &str)
223
r->op_encryptFinished(b, str);
226
void Engine::decryptFinished(Request *r, bool b, const QByteArray &out)
228
r->op_decryptFinished(b, out);
231
void Engine::signFinished(Request *r, bool b, const QString &str)
233
r->op_signFinished(b, str);
236
void Engine::verifyFinished(Request *r, int x, const QString &str, const QDateTime &ts)
238
r->op_verifyFinished(x, str, ts);
241
void Engine::needPassphrase(Request *r)
243
r->op_needPassphrase();
246
void Engine::setBadPassphrase(Request *r, bool b)
248
r->op_setBadPassphrase(b);
252
//----------------------------------------------------------------------------
254
//----------------------------------------------------------------------------
256
static QPtrList<Engine> createEngineList()
258
QPtrList<Engine> list;
259
list.append(new GnuPG);
263
QValueList<EngineItem> OpenPGP::getAllEngines()
265
QValueList<EngineItem> list;
266
QPtrList<Engine> el = createEngineList();
267
QPtrListIterator<Engine> it(el);
268
for(Engine *e; (e = it.current()); ++it)
269
list += qMakePair(e->id(), e->name());
270
el.setAutoDelete(true);
275
QValueList<EngineItem> OpenPGP::getAvailableEngines()
277
QValueList<EngineItem> list;
278
QPtrList<Engine> el = createEngineList();
279
QPtrListIterator<Engine> it(el);
280
for(Engine *e; (e = it.current()); ++it) {
281
if(e->checkAvailability())
282
list += qMakePair(e->id(), e->name());
284
el.setAutoDelete(true);
289
Engine * OpenPGP::createEngine(const QString &id)
297
QString OpenPGP::stripHeaderFooter(const QString &str)
302
QStringList lines = QStringList::split('\n', str, true);
303
QStringList::ConstIterator it = lines.begin();
304
// skip the first line
306
if(it == lines.end())
310
for(; it != lines.end(); ++it) {
314
if(it == lines.end())
317
if(it == lines.end())
321
for(; it != lines.end(); ++it) {
322
if((*it).at(0) == '-')
333
QString OpenPGP::addHeaderFooter(const QString &str, int type)
342
s += QString("-----BEGIN PGP %1-----\n").arg(stype);
343
s += "Version: PGP\n";
346
s += QString("-----END PGP %1-----\n").arg(stype);