Verified Commit 1545acf0 authored by Ingo Klöcker's avatar Ingo Klöcker Committed by Ingo Klöcker
Browse files

Add helper to check if a key can be certified

An OpenPGP key, or more precisely one or more of its user IDs, can be
certified if the key itself is valid (i.e. not revoked, expired, or
otherwise invalid) and if at least one of the user IDs is valid.

GnuPG-bug-id: 6155
parent 7ceef3e1
......@@ -37,6 +37,13 @@ bool isLastValidUserID(const GpgME::UserID &userId)
});
return numberOfValidUserIds == 1;
}
bool hasValidUserID(const GpgME::Key &key)
{
return Kleo::any_of(key.userIDs(), [](const auto &u) {
return !Kleo::isRevokedOrExpired(u);
});
}
}
bool Kleo::isSelfSignature(const GpgME::UserID::Signature &signature)
......@@ -60,6 +67,13 @@ bool Kleo::canCreateCertifications(const GpgME::Key &key)
return key.canCertify() && canBeUsedForSecretKeyOperations(key);
}
bool Kleo::canBeCertified(const GpgME::Key &key)
{
return key.protocol() == GpgME::OpenPGP //
&& !key.isBad() //
&& hasValidUserID(key);
}
bool Kleo::canBeUsedForSecretKeyOperations(const GpgME::Key &key)
{
#if GPGME_VERSION_NUMBER >= 0x011102 // 1.17.2
......
......@@ -36,6 +36,13 @@ bool isRevokedOrExpired(const GpgME::UserID &userId);
*/
bool canCreateCertifications(const GpgME::Key &key);
/**
* Returns true if the key \p key can be certified, i.e. it is an OpenPGP key
* which is neither revoked nor expired and which has at least one user ID
* that is neither revoked nor expired.
*/
bool canBeCertified(const GpgME::Key &key);
/**
* Returns true if \p key can be used for operations requiring the secret key,
* i.e. if the secret key of the primary key pair is available in the keyring
......
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