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
26 /* member functions of Kpgp::KeyIDList --------------------------------- */
28 /** Converts from a KeyIDList to a QStringList.
30 QStringList
KeyIDList::toStringList() const
33 for( KeyIDList::ConstIterator it
= begin(); it
!= end(); ++it
) {
39 /** Converts from a QStringList to a KeyIDList.
41 KeyIDList
KeyIDList::fromStringList( const QStringList
& l
)
44 for( QStringList::ConstIterator it
= l
.begin(); it
!= l
.end(); ++it
) {
45 res
<< (*it
).toLocal8Bit();
50 /* member functions of Kpgp::UserID ------------------------------------ */
52 UserID::UserID(const QString
& str
, const Validity validity
,
53 const bool revoked
, const bool invalid
)
62 /* member functions of Kpgp::Subkey ------------------------------------ */
64 Subkey::Subkey(const KeyID
& keyID
, const bool secret
)
84 /* member functions of Kpgp::Key --------------------------------------- */
86 Key::Key(const KeyID
& keyid
, const QString
& uid
, const bool secret
) :
87 mSubkeys(), mUserIDs()
91 addSubkey(keyid
, secret
);
103 mEncryptPref
= UnknownEncryptPref
;
108 //kDebug( 5326 ) <<"Kpgp::Key: Deleting key" << primaryUserID();
109 qDeleteAll( mUserIDs
);
111 qDeleteAll( mSubkeys
);
127 mEncryptPref
= UnknownEncryptPref
;
129 qDeleteAll( mSubkeys
);
131 qDeleteAll( mUserIDs
);
136 Key::keyTrust() const
138 Validity trust
= KPGP_VALIDITY_UNKNOWN
;
140 foreach ( UserID
* userId
, mUserIDs
)
142 if( userId
->validity() > trust
)
143 trust
= userId
->validity();
150 Key::keyTrust( const QString
& uid
) const
152 Validity trust
= KPGP_VALIDITY_UNKNOWN
;
157 foreach ( UserID
* userId
, mUserIDs
)
159 if( userId
->text() == uid
)
160 trust
= userId
->validity();
167 Key::cloneKeyTrust( const Key
* key
)
172 foreach ( UserID
* userId
, mUserIDs
)
174 userId
->setValidity( key
->keyTrust( userId
->text() ) );
181 return ( !mRevoked
&& !mExpired
&& !mDisabled
&& !mInvalid
);
186 Key::isValidEncryptionKey() const
188 return ( !mRevoked
&& !mExpired
&& !mDisabled
&& !mInvalid
&& mCanEncrypt
);
193 Key::isValidSigningKey() const
195 return ( !mRevoked
&& !mExpired
&& !mDisabled
&& !mInvalid
&& mCanSign
);
199 void Key::addUserID(const QString
&uid
, const Validity validity
,
200 const bool revoked
, const bool invalid
)
202 if (!uid
.isEmpty()) {
203 UserID
*userID
= new UserID(uid
, validity
, revoked
, invalid
);
204 mUserIDs
.append(userID
);
208 bool Key::matchesUserID(const QString
& str
, bool cs
)
210 if (str
.isEmpty() || mUserIDs
.isEmpty())
213 foreach ( UserID
*userId
, mUserIDs
) {
214 if ((userId
->text().indexOf(str
, 0, cs
?Qt::CaseSensitive
:Qt::CaseInsensitive
)) != -1)
221 void Key::addSubkey(const KeyID
& keyID
, const bool secret
)
223 if (!keyID
.isEmpty()) {
224 Subkey
*key
= new Subkey(keyID
, secret
);
225 mSubkeys
.append(key
);
229 Subkey
*Key::getSubkey(const KeyID
& keyID
)
231 if (keyID
.isEmpty() || mSubkeys
.isEmpty())
234 // is the given key ID a long (16 chars) or a short (8 chars) key ID?
235 bool longKeyID
= (keyID
.length() == 16);
237 foreach ( Subkey
* subKey
, mSubkeys
) {
239 if (subKey
->longKeyID() == keyID
)
243 if (subKey
->keyID() == keyID
)
251 void Key::setFingerprint(const KeyID
& keyID
, const QByteArray
&fpr
)
254 if ((key
= getSubkey(keyID
)) != 0) {
255 key
->setFingerprint(fpr
);
258 kDebug(5326) <<"Error: Can't set fingerprint. A subkey with key ID 0x"
259 << keyID
<< "doesn't exist.";