Commit 9dea1cbc authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Add helpers for checking feasibility of certification revokations

GnuPG-bug-id: 6102
parent 57033773
......@@ -88,3 +88,30 @@ bool Kleo::userHasCertificationKey()
return (k.protocol() == GpgME::OpenPGP) && canCreateCertifications(k);
});
}
Kleo::CertificationRevocationFeasibility Kleo::userCanRevokeCertification(const GpgME::UserID::Signature &certification)
{
const auto certificationKey = KeyCache::instance()->findByKeyIDOrFingerprint(certification.signerKeyID());
const bool isSelfSignature = qstrcmp(certification.parent().parent().keyID(), certification.signerKeyID()) == 0;
if (!certificationKey.hasSecret()) {
return CertificationNotMadeWithOwnKey;
} else if (isSelfSignature) {
return CertificationIsSelfSignature;
} else if (certification.isRevokation()) {
return CertificationIsRevocation;
} else if (certification.isExpired()) {
return CertificationIsExpired;
} else if (certification.isInvalid()) {
return CertificationIsInvalid;
} else if (!canCreateCertifications(certificationKey)) {
return CertificationKeyNotAvailable;
}
return CertificationCanBeRevoked;
}
bool Kleo::userCanRevokeCertifications(const GpgME::UserID &userId)
{
return Kleo::any_of(userId.signatures(), [](const auto &certification) {
return userCanRevokeCertification(certification) == CertificationCanBeRevoked;
});
}
......@@ -66,4 +66,26 @@ bool isSecretKeyStoredInKeyRing(const GpgME::Key &key);
*/
bool userHasCertificationKey();
enum CertificationRevocationFeasibility {
CertificationCanBeRevoked = 0,
CertificationNotMadeWithOwnKey,
CertificationIsSelfSignature,
CertificationIsRevocation,
CertificationIsExpired,
CertificationIsInvalid,
CertificationKeyNotAvailable,
};
/**
* Checks if the user can revoke the given \p certification.
*/
CertificationRevocationFeasibility userCanRevokeCertification(const GpgME::UserID::Signature &certification);
/**
* Returns true if the user can revoke any of the certifications of the \p userId.
*
* \sa userCanRevokeCertification
*/
bool userCanRevokeCertifications(const GpgME::UserID &userId);
}
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