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>
29 class TQStringList;
30 
31 #include "kpgp.h"
32 
33 namespace Kpgp {
34 
35 typedef 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 
46 typedef 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 
63 class Base;
64 class 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  */
93 class 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 
196 inline TQCString
197 Block::text() const
198 {
199  if( mHasBeenProcessed )
200  return mProcessedText;
201  else
202  return mText;
203 }
204 
205 inline void
206 Block::setText( const TQCString& str )
207 {
208  clear();
209  mText = str;
210 }
211 
212 inline void
213 Block::setProcessedText( const TQCString& str )
214 {
215  mProcessedText = str;
216  mHasBeenProcessed = true;
217 }
218 
219 inline TQCString
220 Block::error() const
221 {
222  return mError;
223 }
224 
225 inline void
226 Block::setError( const TQCString& str )
227 {
228  mError = str;
229 }
230 
231 inline int
232 Block::status() const
233 {
234  return mStatus;
235 }
236 
237 inline void
238 Block::setStatus( const int status )
239 {
240  mStatus = status;
241 }
242 
243 inline BlockType
244 Block::type()
245 {
246  if( mType == NoPgpBlock )
247  mType = determineType();
248  return mType;
249 }
250 
251 inline TQString
252 Block::signatureUserId() const
253 {
254  return mSignatureUserId;
255 }
256 
257 inline void
258 Block::setSignatureUserId( const TQString& userId )
259 {
260  mSignatureUserId = userId;
261 }
262 
263 inline TQCString
264 Block::signatureKeyId() const
265 {
266  return mSignatureKeyId;
267 }
268 
269 inline void
270 Block::setSignatureKeyId( const TQCString& keyId )
271 {
272  mSignatureKeyId = keyId;
273 }
274 
275 inline TQCString
276 Block::signatureDate() const
277 {
278  return mSignatureDate;
279 }
280 
281 inline void
282 Block::setSignatureDate( const TQCString& date )
283 {
284  mSignatureDate = date;
285 }
286 
287 inline TQString
288 Block::requiredKey() const
289 {
290  return mRequiredKey;
291 }
292 
293 inline void
294 Block::setRequiredKey( const TQCString& keyId )
295 {
296  mRequiredKey = keyId;
297 }
298 
299 inline TQString
300 Block::requiredUserId() const
301 {
302  return mRequiredUserId;
303 }
304 
305 inline void
306 Block::setRequiredUserId( const TQString& userId )
307 {
308  mRequiredUserId = userId;
309 }
310 
311 inline const TQStrList
312 Block::encryptedFor() const
313 {
314  return mEncryptedFor;
315 }
316 
317 inline bool
318 Block::isEncrypted() const
319 {
320  if( mStatus & ENCRYPTED )
321  return true;
322  return false;
323 }
324 
325 inline bool
326 Block::isSigned() const
327 {
328  if( mStatus & SIGNED )
329  return true;
330  return false;
331 }
332 
333 inline bool
334 Block::goodSignature() const
335 {
336  if( mStatus & GOODSIG )
337  return true;
338  return false;
339 }
340 
341 /*
342 inline bool
343 Block::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