4 Copyright (C) 2001,2002 the KPGP authors
5 See file AUTHORS.kpgp for details
7 This file is part of KPGP, the KDE PGP/GnuPG support library.
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.
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
22 #include "libkpgp_export.h"
25 #include <QStringList>
36 UnknownBlock
= -1, // BEGIN PGP ???
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...)
64 * Used for signed, encrypted, or compressed files.
66 * BEGIN PGP PUBLIC KEY BLOCK
67 * Used for armoring public keys
69 * BEGIN PGP PRIVATE KEY BLOCK (PGP 2.x: BEGIN PGP SECRET KEY BLOCK)
70 * Used for armoring private keys
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.
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
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.
86 * BEGIN PGP SIGNED MESSAGE
87 * Used for cleartext signed messages.
89 class LIBKPGP_EXPORT Block
93 explicit Block(const QByteArray
&str
= QByteArray());
96 QByteArray
text() const;
97 void setText(const QByteArray
&str
);
99 void setProcessedText(const QByteArray
&str
);
102 void setStatus(const int status
);
104 BlockType
type() const;
106 /** is the message encrypted ? */
107 bool isEncrypted() const;
109 /** is the message signed by someone */
110 bool isSigned() const;
112 /** is the signature good ? */
113 bool goodSignature() const;
115 /** returns the primary user id of the signer or a null string if we
116 don't have the public key of the signer */
117 QString
signatureUserId() const;
118 void setSignatureUserId(const QString
&userId
);
120 /** keyID of signer */
121 QByteArray
signatureKeyId() const;
122 void setSignatureKeyId(const QByteArray
&keyId
);
124 /** date of the signature
125 WARNING: Will most likely be changed to QDateTime */
126 QByteArray
signatureDate() const;
127 void setSignatureDate(const QByteArray
&date
);
129 /** the persons who can decrypt the message */
130 const QStringList
encryptedFor() const;
132 /** shows the secret key which is needed
133 to decrypt the message */
134 QByteArray
requiredKey() const;
135 void setRequiredKey(const QByteArray
&keyId
);
137 QString
requiredUserId() const;
138 void setRequiredUserId(const QString
&userId
);
140 QByteArray
error() const;
141 void setError(const QByteArray
&str
);
143 /** Resets all information about this OpenPGP block */
146 /** decrypts this OpenPGP block if the passphrase is good.
147 returns false otherwise */
150 /** tries to verify this (clearsigned) OpenPGP block */
153 /** clearsigns this OpenPGP block with the key corresponding to the
154 given key id. The charset is needed to display the text correctly.
156 false if there was an unresolvable error or if signing was canceled
157 true if everything is o.k.
159 Kpgp::Result
clearsign(const QByteArray
&keyId
,
160 const QByteArray
&charset
= QByteArray());
162 /** encrypts this OpenPGP block for a list of persons. if sign is true then
163 the message is signed with the key corresponding to the given key id.
165 false if there was an unresolvable error or if encryption was canceled
166 true if everything is o.k.
168 Kpgp::Result
encrypt(const QStringList
&receivers
, const QByteArray
&keyId
,
169 const bool sign
, const QByteArray
&charset
= QByteArray());
174 BlockType
determineType() const;
177 QByteArray mProcessedText
;
179 QString mSignatureUserId
;
180 QByteArray mSignatureKeyId
;
181 QByteArray mSignatureDate
;
182 QByteArray mRequiredKey
;
183 QString mRequiredUserId
;
184 QStringList mEncryptedFor
;
186 bool mHasBeenProcessed
;
187 mutable BlockType mType
;
190 // -- inlined member functions ---------------------------------------------
195 if (mHasBeenProcessed
) {
196 return mProcessedText
;
203 Block::setText(const QByteArray
&str
)
210 Block::setProcessedText(const QByteArray
&str
)
212 mProcessedText
= str
;
213 mHasBeenProcessed
= true;
223 Block::setError(const QByteArray
&str
)
229 Block::status() const
235 Block::setStatus(const int status
)
243 if (mType
== NoPgpBlock
) {
244 mType
= determineType();
250 Block::signatureUserId() const
252 return mSignatureUserId
;
256 Block::setSignatureUserId(const QString
&userId
)
258 mSignatureUserId
= userId
;
262 Block::signatureKeyId() const
264 return mSignatureKeyId
;
268 Block::setSignatureKeyId(const QByteArray
&keyId
)
270 mSignatureKeyId
= keyId
;
274 Block::signatureDate() const
276 return mSignatureDate
;
280 Block::setSignatureDate(const QByteArray
&date
)
282 mSignatureDate
= date
;
286 Block::requiredKey() const
292 Block::setRequiredKey(const QByteArray
&keyId
)
294 mRequiredKey
= keyId
;
298 Block::requiredUserId() const
300 return mRequiredUserId
;
304 Block::setRequiredUserId(const QString
&userId
)
306 mRequiredUserId
= userId
;
309 inline const QStringList
310 Block::encryptedFor() const
312 return mEncryptedFor
;
316 Block::isEncrypted() const
318 if (mStatus
& ENCRYPTED
) {
325 Block::isSigned() const
327 if (mStatus
& SIGNED
) {
334 Block::goodSignature() const
336 if (mStatus
& GOODSIG
) {
344 Block::unknownSigner() const
346 if( mStatus & UNKNOWN_SIG )
352 // -------------------------------------------------------------------------