• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

libkpgp

  • sources
  • kde-4.14
  • kdepim
  • libkpgp
kpgpblock.h
Go to the documentation of this file.
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 "libkpgp_export.h"
23 #include "kpgp.h"
24 
25 #include <QtCore/QStringList>
26 #include <QtCore/QString>
27 
28 namespace Kpgp {
29 
30 #ifdef ERROR
31 # undef ERROR
32 #endif
33 
34 enum BlockType {
35  UnknownBlock = -1, // BEGIN PGP ???
36  NoPgpBlock = 0,
37  PgpMessageBlock = 1, // BEGIN PGP MESSAGE
38  MultiPgpMessageBlock = 2, // BEGIN PGP MESSAGE, PART X[/Y]
39  SignatureBlock = 3, // BEGIN PGP SIGNATURE
40  ClearsignedBlock = 4, // BEGIN PGP SIGNED MESSAGE
41  PublicKeyBlock = 5, // BEGIN PGP PUBLIC KEY BLOCK
42  PrivateKeyBlock = 6 // BEGIN PGP PRIVATE KEY BLOCK (PGP 2.x: ...SECRET...)
43 };
44 
45 enum MessageStatus{
46  OK = 0x0000,
47  RUN_ERR = 0x0001,
48  ERROR = 0x0001,
49  ENCRYPTED = 0x0002,
50  SIGNED = 0x0004,
51  GOODSIG = 0x0008,
52  ERR_SIGNING = 0x0010,
53  UNKNOWN_SIG = 0x0020,
54  BADPHRASE = 0x0040,
55  BADKEYS = 0x0080,
56  NO_SEC_KEY = 0x0100,
57  MISSINGKEY = 0x0200,
58  CANCEL = 0x8000
59 };
60 
61 
62  /*
63  * BEGIN PGP MESSAGE
64  * Used for signed, encrypted, or compressed files.
65  *
66  * BEGIN PGP PUBLIC KEY BLOCK
67  * Used for armoring public keys
68  *
69  * BEGIN PGP PRIVATE KEY BLOCK (PGP 2.x: BEGIN PGP SECRET KEY BLOCK)
70  * Used for armoring private keys
71  *
72  * BEGIN PGP MESSAGE, PART X/Y
73  * Used for multi-part messages, where the armor is split amongst Y
74  * parts, and this is the Xth part out of Y.
75  *
76  * BEGIN PGP MESSAGE, PART X
77  * Used for multi-part messages, where this is the Xth part of an
78  * unspecified number of parts. Requires the MESSAGE-ID Armor
79  * Header to be used.
80  *
81  * BEGIN PGP SIGNATURE
82  * Used for detached signatures, OpenPGP/MIME signatures, and
83  * signatures following clearsigned messages. Note that PGP 2.x
84  * uses BEGIN PGP MESSAGE for detached signatures.
85  *
86  * BEGIN PGP SIGNED MESSAGE
87  * Used for cleartext signed messages.
88  */
89 class KPGP_EXPORT Block
90 {
91  public:
92 
93  explicit Block( const QByteArray& str = QByteArray() );
94  ~Block();
95 
96  QByteArray text() const;
97  void setText( const QByteArray& str );
98 
99  void setProcessedText( const QByteArray& str );
100 
101  int status() const;
102  void setStatus( const int status );
103 
104  BlockType type() const;
105 
107  bool isEncrypted() const;
108 
110  bool isSigned() const;
111 
113  bool goodSignature() const;
114 
117  QString signatureUserId() const;
118  void setSignatureUserId( const QString& userId );
119 
121  QByteArray signatureKeyId() const;
122  void setSignatureKeyId( const QByteArray& keyId );
123 
126  QByteArray signatureDate() const;
127  void setSignatureDate( const QByteArray& date );
128 
130  const QStringList encryptedFor() const;
131 
134  QByteArray requiredKey() const;
135  void setRequiredKey( const QByteArray& keyId );
136 
137  QString requiredUserId() const;
138  void setRequiredUserId( const QString& userId );
139 
140  QByteArray error() const;
141  void setError( const QByteArray& str );
142 
144  void reset();
145 
148  bool decrypt();
149 
151  bool verify();
152 
159  Kpgp::Result clearsign( const QByteArray& keyId,
160  const QByteArray& charset = QByteArray() );
161 
168  Kpgp::Result encrypt( const QStringList& receivers, const QByteArray& keyId,
169  const bool sign, const QByteArray& charset = QByteArray() );
170 
171  private:
172  void clear();
173 
174  BlockType determineType() const;
175 
176  QByteArray mText;
177  QByteArray mProcessedText;
178  QByteArray mError;
179  QString mSignatureUserId;
180  QByteArray mSignatureKeyId;
181  QByteArray mSignatureDate;
182  QByteArray mRequiredKey;
183  QString mRequiredUserId;
184  QStringList mEncryptedFor;
185  int mStatus;
186  bool mHasBeenProcessed;
187  mutable BlockType mType;
188 };
189 
190 // -- inlined member functions ---------------------------------------------
191 
192 inline QByteArray
193 Block::text() const
194 {
195  if( mHasBeenProcessed )
196  return mProcessedText;
197  else
198  return mText;
199 }
200 
201 inline void
202 Block::setText( const QByteArray& str )
203 {
204  clear();
205  mText = str;
206 }
207 
208 inline void
209 Block::setProcessedText( const QByteArray& str )
210 {
211  mProcessedText = str;
212  mHasBeenProcessed = true;
213 }
214 
215 inline QByteArray
216 Block::error() const
217 {
218  return mError;
219 }
220 
221 inline void
222 Block::setError( const QByteArray& str )
223 {
224  mError = str;
225 }
226 
227 inline int
228 Block::status() const
229 {
230  return mStatus;
231 }
232 
233 inline void
234 Block::setStatus( const int status )
235 {
236  mStatus = status;
237 }
238 
239 inline BlockType
240 Block::type() const
241 {
242  if( mType == NoPgpBlock )
243  mType = determineType();
244  return mType;
245 }
246 
247 inline QString
248 Block::signatureUserId() const
249 {
250  return mSignatureUserId;
251 }
252 
253 inline void
254 Block::setSignatureUserId( const QString& userId )
255 {
256  mSignatureUserId = userId;
257 }
258 
259 inline QByteArray
260 Block::signatureKeyId() const
261 {
262  return mSignatureKeyId;
263 }
264 
265 inline void
266 Block::setSignatureKeyId( const QByteArray& keyId )
267 {
268  mSignatureKeyId = keyId;
269 }
270 
271 inline QByteArray
272 Block::signatureDate() const
273 {
274  return mSignatureDate;
275 }
276 
277 inline void
278 Block::setSignatureDate( const QByteArray& date )
279 {
280  mSignatureDate = date;
281 }
282 
283 inline QByteArray
284 Block::requiredKey() const
285 {
286  return mRequiredKey;
287 }
288 
289 inline void
290 Block::setRequiredKey( const QByteArray& keyId )
291 {
292  mRequiredKey = keyId;
293 }
294 
295 inline QString
296 Block::requiredUserId() const
297 {
298  return mRequiredUserId;
299 }
300 
301 inline void
302 Block::setRequiredUserId( const QString& userId )
303 {
304  mRequiredUserId = userId;
305 }
306 
307 inline const QStringList
308 Block::encryptedFor() const
309 {
310  return mEncryptedFor;
311 }
312 
313 inline bool
314 Block::isEncrypted() const
315 {
316  if( mStatus & ENCRYPTED )
317  return true;
318  return false;
319 }
320 
321 inline bool
322 Block::isSigned() const
323 {
324  if( mStatus & SIGNED )
325  return true;
326  return false;
327 }
328 
329 inline bool
330 Block::goodSignature() const
331 {
332  if( mStatus & GOODSIG )
333  return true;
334  return false;
335 }
336 
337 /*
338 inline bool
339 Block::unknownSigner() const
340 {
341  if( mStatus & UNKNOWN_SIG )
342  return true;
343  return false;
344 }
345 */
346 
347 // -------------------------------------------------------------------------
348 
349 } // namespace Kpgp
350 
351 #endif
352 
Kpgp::Block::setError
void setError(const QByteArray &str)
Definition: kpgpblock.h:222
Kpgp::Block::signatureUserId
QString signatureUserId() const
returns the primary user id of the signer or a null string if we don't have the public key of the sig...
Definition: kpgpblock.h:248
Kpgp::Block::setSignatureDate
void setSignatureDate(const QByteArray &date)
Definition: kpgpblock.h:278
Kpgp::Block::setText
void setText(const QByteArray &str)
Definition: kpgpblock.h:202
QByteArray
Kpgp::SignatureBlock
Definition: kpgpblock.h:39
Kpgp::MessageStatus
MessageStatus
Definition: kpgpblock.h:45
Kpgp::NO_SEC_KEY
Definition: kpgpblock.h:56
Kpgp::Block::status
int status() const
Definition: kpgpblock.h:228
Kpgp::Block::setRequiredKey
void setRequiredKey(const QByteArray &keyId)
Definition: kpgpblock.h:290
Kpgp::Block
Definition: kpgpblock.h:89
Kpgp::Block::goodSignature
bool goodSignature() const
is the signature good ?
Definition: kpgpblock.h:330
Kpgp::Block::isSigned
bool isSigned() const
is the message signed by someone
Definition: kpgpblock.h:322
Kpgp::Block::error
QByteArray error() const
Definition: kpgpblock.h:216
Kpgp::PrivateKeyBlock
Definition: kpgpblock.h:42
Kpgp::BADPHRASE
Definition: kpgpblock.h:54
Kpgp::Block::setRequiredUserId
void setRequiredUserId(const QString &userId)
Definition: kpgpblock.h:302
Kpgp::Block::setSignatureUserId
void setSignatureUserId(const QString &userId)
Definition: kpgpblock.h:254
Kpgp::CANCEL
Definition: kpgpblock.h:58
Kpgp::MultiPgpMessageBlock
Definition: kpgpblock.h:38
Kpgp::GOODSIG
Definition: kpgpblock.h:51
Kpgp::BlockType
BlockType
Definition: kpgpblock.h:34
Kpgp::BADKEYS
Definition: kpgpblock.h:55
Kpgp::NoPgpBlock
Definition: kpgpblock.h:36
Kpgp::PublicKeyBlock
Definition: kpgpblock.h:41
QString
Kpgp::ENCRYPTED
Definition: kpgpblock.h:49
Kpgp::OK
Definition: kpgpblock.h:46
Kpgp::Block::signatureDate
QByteArray signatureDate() const
date of the signature WARNING: Will most likely be changed to QDateTime
Definition: kpgpblock.h:272
QStringList
Kpgp::Block::signatureKeyId
QByteArray signatureKeyId() const
keyID of signer
Definition: kpgpblock.h:260
libkpgp_export.h
Kpgp::Block::requiredKey
QByteArray requiredKey() const
shows the secret key which is needed to decrypt the message
Definition: kpgpblock.h:284
Kpgp::Block::setSignatureKeyId
void setSignatureKeyId(const QByteArray &keyId)
Definition: kpgpblock.h:266
Kpgp::Result
Result
Definition: kpgp.h:65
Kpgp::MISSINGKEY
Definition: kpgpblock.h:57
Kpgp::PgpMessageBlock
Definition: kpgpblock.h:37
Kpgp::Block::text
QByteArray text() const
Definition: kpgpblock.h:193
Kpgp::Block::setProcessedText
void setProcessedText(const QByteArray &str)
Definition: kpgpblock.h:209
Kpgp::ERROR
Definition: kpgpblock.h:48
Kpgp::UNKNOWN_SIG
Definition: kpgpblock.h:53
Kpgp::ClearsignedBlock
Definition: kpgpblock.h:40
Kpgp::SIGNED
Definition: kpgpblock.h:50
kpgp.h
Kpgp::Block::isEncrypted
bool isEncrypted() const
is the message encrypted ?
Definition: kpgpblock.h:314
Kpgp::Block::encryptedFor
const QStringList encryptedFor() const
the persons who can decrypt the message
Definition: kpgpblock.h:308
KPGP_EXPORT
#define KPGP_EXPORT
Definition: libkpgp_export.h:35
Kpgp::ERR_SIGNING
Definition: kpgpblock.h:52
Kpgp::Block::requiredUserId
QString requiredUserId() const
Definition: kpgpblock.h:296
Kpgp::Block::setStatus
void setStatus(const int status)
Definition: kpgpblock.h:234
Kpgp::UnknownBlock
Definition: kpgpblock.h:35
Kpgp::Block::type
BlockType type() const
Definition: kpgpblock.h:240
Kpgp::RUN_ERR
Definition: kpgpblock.h:47
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkpgp

Skip menu "libkpgp"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal