From 05a0e97f5c12c06082fbeab0fba6f86ddbfbe6b2 Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Thu, 25 Oct 2018 14:09:37 +0200 Subject: cpp: Add some convenience functions * lang/cpp/src/context.cpp (Context::create): New. * lang/cpp/src/context.h: Update accordingly. * lang/cpp/src/key.cpp, lang/cpp/src/key.h: (Key::isBad, Subkey::isBad, UserID::isBad) (UserID::Signature::isBad): Add shorthand for the isX checks. * NEWS: Mention it. -- I don't know how often I wrote: if (key.isNull() || key.isExpired() || key.isRevoked() ... And for the context it is good practice to use a unique ptr so the API should make it easy. --- lang/cpp/src/key.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lang/cpp/src/key.cpp') diff --git a/lang/cpp/src/key.cpp b/lang/cpp/src/key.cpp index 8fc266ff..0d272926 100644 --- a/lang/cpp/src/key.cpp +++ b/lang/cpp/src/key.cpp @@ -1033,6 +1033,26 @@ time_t Key::lastUpdate() const return static_cast(key ? key->last_update : 0); } +bool Key::isBad() const +{ + return isNull() || isRevoked() || isExpired() || isDisabled() || isInvalid(); +} + +bool Subkey::isBad() const +{ + return isNull() || isRevoked() || isExpired() || isDisabled() || isInvalid(); +} + +bool UserID::isBad() const +{ + return isNull() || isRevoked() || isInvalid(); +} + +bool UserID::Signature::isBad() const +{ + return isNull() || isExpired() || isInvalid(); +} + std::ostream &operator<<(std::ostream &os, const UserID &uid) { os << "GpgME::UserID("; -- cgit v1.2.3