Verified Commit 172f645d authored by Ingo Klöcker's avatar Ingo Klöcker Committed by Ingo Klöcker
Browse files

Add helper to check if two UserID objects represent the same user ID

GnuPG-bug-id: 6265
parent 014e3c7a
......@@ -141,3 +141,22 @@ bool Kleo::userIDBelongsToKey(const GpgME::UserID &userID, const GpgME::Key &key
{
return !qstricmp(userID.parent().primaryFingerprint(), key.primaryFingerprint());
}
static time_t creationDate(const GpgME::UserID &uid)
{
// returns the date of the first self-signature
for (unsigned int i = 0, numSignatures = uid.numSignatures(); i < numSignatures; ++i) {
const auto sig = uid.signature(i);
if (Kleo::isSelfSignature(sig)) {
return sig.creationTime();
}
}
return 0;
}
bool Kleo::userIDsAreEqual(const GpgME::UserID &lhs, const GpgME::UserID &rhs)
{
return (qstrcmp(lhs.parent().primaryFingerprint(), rhs.parent().primaryFingerprint()) == 0
&& qstrcmp(lhs.id(), rhs.id()) == 0
&& creationDate(lhs) == creationDate(rhs));
}
......@@ -110,4 +110,13 @@ inline auto userIDBelongsToKey(const GpgME::Key &key)
};
}
/**
* Returns true, if the two user IDs \p lhs and \p rhs are equal.
*
* Equality means that both user IDs belong to the same key, contain identical
* text, and have the same creation date (i.e. the creation date of the first
* self-signature is the same).
*/
bool userIDsAreEqual(const GpgME::UserID &lhs, const GpgME::UserID &rhs);
}
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