1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
/*
* context.h
*
* Copyright 2008 gpg4usb-team <[email protected]>
*
* This program 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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.
*/
#ifndef __SGPGMEPP_CONTEXT_H__
#define __SGPGMEPP_CONTEXT_H__
#include <locale.h>
#include <errno.h>
#include <gpgme.h>
#include <QLinkedList>
#include <QtGui>
QT_BEGIN_NAMESPACE
class QMessageBox;
class sstream;
class QApplication;
class QByteArray;
class QString;
QT_END_NAMESPACE
class GpgKey
{
public:
GpgKey() {
privkey = false;
}
QString id;
QString name;
QString email;
bool privkey;
QString fpr;
};
typedef QLinkedList< GpgKey > GpgKeyList;
class GpgSignature
{
public:
QString fpr;
QString name;
QString email;
gpgme_error_t signStatusCode;
QString signStatusString;
bool presentInKeyList;
};
typedef QLinkedList< GpgSignature > GpgSignatureList;
namespace GpgME
{
class Context : public QObject
{
Q_OBJECT
public:
Context(); // Constructor
~Context(); // Destructor
void importKey(QByteArray inBuffer);
bool exportKeys(QStringList *uidList, QByteArray *outBuffer);
void generateKey(QString *params);
GpgKeyList listKeys();
void deleteKeys(QStringList *uidList);
bool encrypt(QStringList *uidList, const QByteArray &inBuffer,
QByteArray *outBuffer);
bool decrypt(const QByteArray &inBuffer, QByteArray *outBuffer);
void clearPasswordCache();
void exportSecretKey(QString uid, QByteArray *outBuffer);
gpgme_key_t getKeyDetails(QString uid);
gpgme_signature_t verify(QByteArray in);
// void decryptVerify(QByteArray in);
void sign(const QByteArray &inBuffer, QByteArray *outBuffer);
bool sign(QStringList *uidList, const QByteArray &inBuffer, QByteArray *outBuffer );
/**
* @details If text contains PGP-message, put a linebreak before the message,
* so that gpgme can decrypt correctly
*
* @param in Pointer to the QBytearray to check.
*/
void preventNoDataErr(QByteArray *in);
/**
* @brief
*
* @param text
* @return \li 2, if the text is completly signed,
* \li 1, if the text is partially signed,
* \li 0, if the text is not signed at all.
*/
int textIsSigned(const QByteArray &text);
signals:
void keyDBChanged();
private:
gpgme_ctx_t mCtx;
gpgme_data_t in, out;
gpgme_error_t err;
gpgme_error_t readToBuffer(gpgme_data_t in, QByteArray *outBuffer);
QByteArray mPasswordCache;
QSettings settings;
bool debug;
int checkErr(gpgme_error_t err) const;
int checkErr(gpgme_error_t err, QString comment) const;
static gpgme_error_t passphraseCb(void *hook, const char *uid_hint,
const char *passphrase_info,
int last_was_bad, int fd);
gpgme_error_t passphrase(const char *uid_hint,
const char *passphrase_info,
int last_was_bad, int fd);
void executeGpgCommand(QStringList arguments,
QByteArray *stdOut,
QByteArray *stdErr);
};
} // namespace GpgME
#endif // __SGPGMEPP_CONTEXT_H__
|