libkpgp

kpgpblock.h
1/*
2 kpgpblock.h
3
4 Copyright (C) 2001,2002 the KPGP authors
5 See file AUTHORS.kpgp for details
6
7 This file is part of KPGP, the KDE PGP/GnuPG support library.
8
9 KPGP is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19#ifndef KPGPBLOCK_H
20#define KPGPBLOCK_H
21
22#include <tqcstring.h>
23#include <tqstring.h>
24#include <tqstrlist.h>
25
26#include <tdemacros.h>
27
28//#include <tqstringlist.h>
29class TQStringList;
30
31#include "kpgp.h"
32
33namespace Kpgp {
34
35typedef enum {
36 UnknownBlock = -1, // BEGIN PGP ???
37 NoPgpBlock = 0,
38 PgpMessageBlock = 1, // BEGIN PGP MESSAGE
39 MultiPgpMessageBlock = 2, // BEGIN PGP MESSAGE, PART X[/Y]
40 SignatureBlock = 3, // BEGIN PGP SIGNATURE
41 ClearsignedBlock = 4, // BEGIN PGP SIGNED MESSAGE
42 PublicKeyBlock = 5, // BEGIN PGP PUBLIC KEY BLOCK
43 PrivateKeyBlock = 6 // BEGIN PGP PRIVATE KEY BLOCK (PGP 2.x: ...SECRET...)
44} BlockType;
45
46typedef enum {
47 OK = 0x0000,
48 CLEARTEXT = 0x0000,
49 RUN_ERR = 0x0001,
50 ERROR = 0x0001,
51 ENCRYPTED = 0x0002,
52 SIGNED = 0x0004,
53 GOODSIG = 0x0008,
54 ERR_SIGNING = 0x0010,
55 UNKNOWN_SIG = 0x0020,
56 BADPHRASE = 0x0040,
57 BADKEYS = 0x0080,
58 NO_SEC_KEY = 0x0100,
59 MISSINGKEY = 0x0200,
60 CANCEL = 0x8000
61} MessageStatus;
62
63class Base;
64class Module;
65
66 /*
67 * BEGIN PGP MESSAGE
68 * Used for signed, encrypted, or compressed files.
69 *
70 * BEGIN PGP PUBLIC KEY BLOCK
71 * Used for armoring public keys
72 *
73 * BEGIN PGP PRIVATE KEY BLOCK (PGP 2.x: BEGIN PGP SECRET KEY BLOCK)
74 * Used for armoring private keys
75 *
76 * BEGIN PGP MESSAGE, PART X/Y
77 * Used for multi-part messages, where the armor is split amongst Y
78 * parts, and this is the Xth part out of Y.
79 *
80 * BEGIN PGP MESSAGE, PART X
81 * Used for multi-part messages, where this is the Xth part of an
82 * unspecified number of parts. Requires the MESSAGE-ID Armor
83 * Header to be used.
84 *
85 * BEGIN PGP SIGNATURE
86 * Used for detached signatures, OpenPGP/MIME signatures, and
87 * signatures following clearsigned messages. Note that PGP 2.x
88 * uses BEGIN PGP MESSAGE for detached signatures.
89 *
90 * BEGIN PGP SIGNED MESSAGE
91 * Used for cleartext signed messages.
92 */
93class TDE_EXPORT Block
94{
95 public:
96
97 Block( const TQCString& str = TQCString() );
98 ~Block();
99
100 TQCString text() const;
101 void setText( const TQCString& str );
102
103 void setProcessedText( const TQCString& str );
104
105 int status() const;
106 void setStatus( const int status );
107
108 BlockType type();
109
111 bool isEncrypted() const;
112
114 bool isSigned() const;
115
117 bool goodSignature() const;
118
121 TQString signatureUserId() const;
122 void setSignatureUserId( const TQString& userId );
123
125 TQCString signatureKeyId() const;
126 void setSignatureKeyId( const TQCString& keyId );
127
130 TQCString signatureDate() const;
131 void setSignatureDate( const TQCString& date );
132
134 const TQStrList encryptedFor() const;
135
138 TQString requiredKey() const;
139 void setRequiredKey( const TQCString& keyId );
140
141 TQString requiredUserId() const;
142 void setRequiredUserId( const TQString& userId );
143
144 TQCString error() const;
145 void setError( const TQCString& str );
146
148 void reset();
149
152 bool decrypt();
153
155 bool verify();
156
163 Kpgp::Result clearsign( const TQCString& keyId,
164 const TQCString& charset = TQCString() );
165
172 Kpgp::Result encrypt( const TQStringList& receivers, const TQCString& keyId,
173 const bool sign, const TQCString& charset = TQCString() );
174
175 private:
176 void clear();
177
178 BlockType determineType() const;
179
180 TQCString mText;
181 TQCString mProcessedText;
182 TQCString mError;
183 TQString mSignatureUserId;
184 TQCString mSignatureKeyId;
185 TQCString mSignatureDate;
186 TQCString mRequiredKey;
187 TQString mRequiredUserId;
188 TQStrList mEncryptedFor;
189 int mStatus;
190 bool mHasBeenProcessed;
191 BlockType mType;
192};
193
194// -- inlined member functions ---------------------------------------------
195
196inline TQCString
197Block::text() const
198{
199 if( mHasBeenProcessed )
200 return mProcessedText;
201 else
202 return mText;
203}
204
205inline void
206Block::setText( const TQCString& str )
207{
208 clear();
209 mText = str;
210}
211
212inline void
213Block::setProcessedText( const TQCString& str )
214{
215 mProcessedText = str;
216 mHasBeenProcessed = true;
217}
218
219inline TQCString
220Block::error() const
221{
222 return mError;
223}
224
225inline void
226Block::setError( const TQCString& str )
227{
228 mError = str;
229}
230
231inline int
232Block::status() const
233{
234 return mStatus;
235}
236
237inline void
238Block::setStatus( const int status )
239{
240 mStatus = status;
241}
242
243inline BlockType
244Block::type()
245{
246 if( mType == NoPgpBlock )
247 mType = determineType();
248 return mType;
249}
250
251inline TQString
252Block::signatureUserId() const
253{
254 return mSignatureUserId;
255}
256
257inline void
258Block::setSignatureUserId( const TQString& userId )
259{
260 mSignatureUserId = userId;
261}
262
263inline TQCString
264Block::signatureKeyId() const
265{
266 return mSignatureKeyId;
267}
268
269inline void
270Block::setSignatureKeyId( const TQCString& keyId )
271{
272 mSignatureKeyId = keyId;
273}
274
275inline TQCString
276Block::signatureDate() const
277{
278 return mSignatureDate;
279}
280
281inline void
282Block::setSignatureDate( const TQCString& date )
283{
284 mSignatureDate = date;
285}
286
287inline TQString
288Block::requiredKey() const
289{
290 return mRequiredKey;
291}
292
293inline void
294Block::setRequiredKey( const TQCString& keyId )
295{
296 mRequiredKey = keyId;
297}
298
299inline TQString
300Block::requiredUserId() const
301{
302 return mRequiredUserId;
303}
304
305inline void
306Block::setRequiredUserId( const TQString& userId )
307{
308 mRequiredUserId = userId;
309}
310
311inline const TQStrList
312Block::encryptedFor() const
313{
314 return mEncryptedFor;
315}
316
317inline bool
318Block::isEncrypted() const
319{
320 if( mStatus & ENCRYPTED )
321 return true;
322 return false;
323}
324
325inline bool
326Block::isSigned() const
327{
328 if( mStatus & SIGNED )
329 return true;
330 return false;
331}
332
333inline bool
334Block::goodSignature() const
335{
336 if( mStatus & GOODSIG )
337 return true;
338 return false;
339}
340
341/*
342inline bool
343Block::unknownSigner() const
344{
345 if( mStatus & UNKNOWN_SIG )
346 return true;
347 return false;
348}
349*/
350
351// -------------------------------------------------------------------------
352
353} // namespace Kpgp
354
355#endif
356