Commit be42142a authored by Steven Noonan's avatar Steven Noonan Committed by Andrius Štikonas
Browse files

replace 'size' display with 'strength' display

parent 2c59f95f
......@@ -81,8 +81,8 @@ QString
KGpgKeyNode::getSize() const
{
return i18nc("size of signing key / size of encryption key",
"%1 / %2", QString::number(getSignKeySize()),
QString::number(getEncryptionKeySize()));
"%1 / %2", m_key->strength(),
m_key->encryptionStrength());
}
QString
......
......@@ -89,7 +89,7 @@ KGpgSubkeyNode::getName() const
QString
KGpgSubkeyNode::getSize() const
{
return QString::number(m_skey.size());
return m_skey.strength();
}
KGpgKeyNode *
......
......@@ -21,16 +21,38 @@
namespace KgpgCore
{
static QString _describe_key_strength(KgpgKeyAlgo algorithm, const uint size, const QString &curve)
{
const char *prefix = NULL;
if (curve.length() > 0)
return curve;
switch(algorithm)
{
case ALGO_RSA: prefix = "rsa"; break;
case ALGO_ELGAMAL: prefix = "elg"; break;
case ALGO_DSA: prefix = "dsa"; break;
}
if (prefix) {
return QString("%1%2").arg(prefix, QString::number(size));
}
return QString("%1").arg(size);
}
//BEGIN KeySub
KgpgKeySubPrivate::KgpgKeySubPrivate(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo,
const KgpgSubKeyType type, const QDateTime &date)
const KgpgSubKeyType type, const QDateTime &date, const QString &curve)
: gpgsubvalid(false),
gpgsubid(id),
gpgsubsize(size),
gpgsubcreation(date),
gpgsubtrust(trust),
gpgsubalgo(algo),
gpgsubtype(type)
gpgsubtype(type),
gpgcurve(curve)
{
}
......@@ -48,8 +70,8 @@ bool KgpgKeySubPrivate::operator==(const KgpgKeySubPrivate &other) const
}
KgpgKeySub::KgpgKeySub(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, const KgpgSubKeyType type,
const QDateTime &date)
: d(new KgpgKeySubPrivate(id, size, trust, algo, type, date))
const QDateTime &date, const QString &curve)
: d(new KgpgKeySubPrivate(id, size, trust, algo, type, date, curve))
{
}
......@@ -78,6 +100,11 @@ uint KgpgKeySub::size() const
return d->gpgsubsize;
}
QString KgpgKeySub::strength() const
{
return _describe_key_strength(algorithm(), size(), d->gpgcurve);
}
bool KgpgKeySub::unlimited() const
{
return d->gpgsubexpiration.isNull();
......@@ -113,6 +140,11 @@ KgpgSubKeyType KgpgKeySub::type() const
return d->gpgsubtype;
}
QString KgpgKeySub::curve() const
{
return d->gpgcurve;
}
bool KgpgKeySub::operator==(const KgpgKeySub &other) const
{
if (d == other.d) return true;
......@@ -132,7 +164,7 @@ KgpgKeySub& KgpgKeySub::operator=(const KgpgKeySub &other)
//BEGIN Key
KgpgKeyPrivate::KgpgKeyPrivate(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, const KgpgSubKeyType subtype,
const KgpgSubKeyType keytype, const QDateTime &creationDate)
const KgpgSubKeyType keytype, const QDateTime &creationDate, const QString &curve)
: gpgkeysecret(false),
gpgkeyvalid(false),
gpgkeyid(id),
......@@ -142,6 +174,7 @@ KgpgKeyPrivate::KgpgKeyPrivate(const QString &id, const uint size, const KgpgKey
gpgkeyalgo(algo),
gpgsubtype(subtype),
gpgkeytype(keytype),
gpgcurve(curve),
gpgsublist(new KgpgKeySubList())
{
}
......@@ -168,8 +201,8 @@ bool KgpgKeyPrivate::operator==(const KgpgKeyPrivate &other) const
}
KgpgKey::KgpgKey(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, const KgpgSubKeyType subtype,
const KgpgSubKeyType keytype, const QDateTime &creationDate)
: d(new KgpgKeyPrivate(id, size, trust, algo, subtype, keytype, creationDate))
const KgpgSubKeyType keytype, const QDateTime &creationDate, const QString &curve)
: d(new KgpgKeyPrivate(id, size, trust, algo, subtype, keytype, creationDate, curve))
{
}
......@@ -263,6 +296,11 @@ uint KgpgKey::size() const
return d->gpgkeysize;
}
QString KgpgKey::strength() const
{
return _describe_key_strength(algorithm(), size(), d->gpgcurve);
}
uint KgpgKey::encryptionSize() const
{
const KgpgKeySub *enc = Q_NULLPTR;
......@@ -282,6 +320,25 @@ uint KgpgKey::encryptionSize() const
return 0;
}
QString KgpgKey::encryptionStrength() const
{
const KgpgKeySub *enc = Q_NULLPTR;
// Get the first encryption subkey
foreach (const KgpgKeySub &k, *d->gpgsublist) {
if (k.type() & SKT_ENCRYPTION) {
// if the first encryption subkey is expired
// check if there is one that is not
if (k.trust() > TRUST_EXPIRED)
return _describe_key_strength(k.algorithm(), k.size(), k.curve());
if (enc == Q_NULLPTR)
enc = &k;
}
}
if (enc != Q_NULLPTR)
return _describe_key_strength(enc->algorithm(), enc->size(), enc->curve());
return QString("");
}
gpgme_validity_t KgpgKey::ownerTrust() const
{
return d->gpgkeyownertrust;
......@@ -324,7 +381,7 @@ KgpgKeyAlgo KgpgKey::encryptionAlgorithm() const
KgpgSubKeyType KgpgKey::subtype() const
{
return d->gpgsubtype;
return d->gpgsubtype;
}
KgpgSubKeyType KgpgKey::keytype() const
......@@ -332,6 +389,11 @@ KgpgSubKeyType KgpgKey::keytype() const
return d->gpgkeytype;
}
QString KgpgKey::curve() const
{
return d->gpgcurve;
}
KgpgKeySubListPtr KgpgKey::subList() const
{
return d->gpgsublist;
......
......@@ -119,7 +119,7 @@ class KgpgKeySubPrivate : public QSharedData
KgpgKeySubPrivate();
public:
KgpgKeySubPrivate(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, const KgpgSubKeyType type,
const QDateTime &date);
const QDateTime &date, const QString &curve);
bool gpgsubvalid;
const QString gpgsubid;
......@@ -129,6 +129,7 @@ public:
const KgpgKeyTrust gpgsubtrust;
const KgpgKeyAlgo gpgsubalgo;
const KgpgSubKeyType gpgsubtype;
const QString gpgcurve;
bool operator==(const KgpgKeySubPrivate &other) const;
inline bool operator!=(const KgpgKeySubPrivate &other) const
......@@ -140,7 +141,7 @@ class KgpgKeySub
KgpgKeySub();
public:
KgpgKeySub(const QString &id, const uint size, const KgpgKeyTrust trust, const KgpgKeyAlgo algo, const KgpgSubKeyType type,
const QDateTime &date);
const QDateTime &date, const QString &curve);
KgpgKeySub(const KgpgKeySub &other);
void setExpiration(const QDateTime &date);
......@@ -148,6 +149,7 @@ public:
QString id() const;
uint size() const;
QString strength() const;
bool unlimited() const;
QDateTime expirationDate() const;
QDateTime creationDate() const;
......@@ -155,6 +157,7 @@ public:
KgpgKeyAlgo algorithm() const;
bool valid() const;
KgpgSubKeyType type() const;
QString curve() const;
bool operator==(const KgpgKeySub &other) const;
inline bool operator!=(const KgpgKeySub &other) const
......@@ -213,8 +216,9 @@ public:
* @param keytype key capabilities of this and all subkeys combined
* @param creationDate date of key creation
*/
KgpgKeyPrivate(const QString& id, const uint size, const KgpgCore::KgpgKeyTrust trust, const KgpgCore::KgpgKeyAlgo algo,
const KgpgCore::KgpgSubKeyType subtype, const KgpgCore::KgpgSubKeyType keytype, const QDateTime& creationDate);
KgpgKeyPrivate(const QString &id, const uint size, const KgpgCore::KgpgKeyTrust trust, const KgpgCore::KgpgKeyAlgo algo,
const KgpgCore::KgpgSubKeyType subtype, const KgpgCore::KgpgSubKeyType keytype, const QDateTime &creationDate,
const QString &curve);
bool gpgkeysecret;
bool gpgkeyvalid;
......@@ -231,6 +235,7 @@ public:
const KgpgKeyAlgo gpgkeyalgo;
const KgpgSubKeyType gpgsubtype;
const KgpgSubKeyType gpgkeytype;
QString gpgcurve;
KgpgKeySubListPtr gpgsublist;
......@@ -253,7 +258,8 @@ public:
* @param creationDate date of key creation
*/
KgpgKey(const QString &id, const uint size, const KgpgCore::KgpgKeyTrust trust, const KgpgCore::KgpgKeyAlgo algo,
const KgpgCore::KgpgSubKeyType subtype, const KgpgCore::KgpgSubKeyType keytype, const QDateTime& creationDate);
const KgpgCore::KgpgSubKeyType subtype, const KgpgCore::KgpgSubKeyType keytype, const QDateTime& creationDate,
const QString &curve);
KgpgKey(const KgpgKey &other);
void setSecret(const bool secret);
......@@ -274,7 +280,9 @@ public:
QString comment() const;
const QString &fingerprint() const;
uint size() const;
QString strength() const;
uint encryptionSize() const;
QString encryptionStrength() const;
gpgme_validity_t ownerTrust() const;
KgpgKeyTrust trust() const;
QDateTime creationDate() const;
......@@ -284,6 +292,7 @@ public:
KgpgKeyAlgo encryptionAlgorithm() const;
KgpgSubKeyType subtype() const;
KgpgSubKeyType keytype() const;
QString curve() const;
KgpgKeySubListPtr subList() const;
......
......@@ -168,7 +168,7 @@ readPublicKeysProcess(GPGProc &p, KGpgKeyNode *readNode)
publiclistkeys << KgpgKey(lsp.at(4), lsp.at(2).toUInt(), Convert::toTrust(lsp.at(1)),
Convert::toAlgo(lsp.at(3).toInt()), subtype, keytype,
QDateTime::fromTime_t(lsp.at(5).toUInt()));
QDateTime::fromTime_t(lsp.at(5).toUInt()), lsp.at(16));
publickey = &publiclistkeys.last();
......@@ -201,7 +201,8 @@ readPublicKeysProcess(GPGProc &p, KGpgKeyNode *readNode)
subtype = Convert::toSubType(lsp.at(11), false);
KgpgKeySub sub(lsp.at(4), lsp.at(2).toUInt(), Convert::toTrust(lsp.at(1)),
Convert::toAlgo(lsp.at(3).toInt()), subtype, QDateTime::fromTime_t(lsp.at(5).toUInt()));
Convert::toAlgo(lsp.at(3).toInt()), subtype, QDateTime::fromTime_t(lsp.at(5).toUInt()),
lsp.at(16));
// FIXME: Please see kgpgkey.h, KgpgSubKey class
if (items <= 11)
......@@ -341,7 +342,7 @@ readSecretKeysProcess(GPGProc &p)
result << KgpgKey(lsp.at(4), lsp.at(2).toUInt(), Convert::toTrust(lsp.at(1)),
Convert::toAlgo(lsp.at(3).toInt()), subtype, keytype,
QDateTime::fromTime_t(lsp.at(5).toUInt()));
QDateTime::fromTime_t(lsp.at(5).toUInt()), lsp.at(16));
secretkey = &result.last();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment