diff --git a/NEWS b/NEWS index 9d6bd0ab..6deb3256 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ Noteworthy changes in version 1.11.1 (unreleased) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cpp: Key::origin NEW. cpp: Key::lastUpdate NEW. + cpp: UserID::origin NEW. + cpp: UserID::lastUpdate NEW. Noteworthy changes in version 1.11.0 (2018-04-18) ------------------------------------------------- diff --git a/lang/cpp/src/key.cpp b/lang/cpp/src/key.cpp index 838033c5..034286f0 100644 --- a/lang/cpp/src/key.cpp +++ b/lang/cpp/src/key.cpp @@ -967,6 +967,42 @@ Error UserID::revoke() return ret; } +static Key::Origin gpgme_origin_to_pp_origin (const unsigned int origin) +{ + switch (origin) { + case GPGME_KEYORG_KS: + return Key::OriginKS; + case GPGME_KEYORG_DANE: + return Key::OriginDane; + case GPGME_KEYORG_WKD: + return Key::OriginWKD; + case GPGME_KEYORG_URL: + return Key::OriginURL; + case GPGME_KEYORG_FILE: + return Key::OriginFile; + case GPGME_KEYORG_SELF: + return Key::OriginSelf; + case GPGME_KEYORG_OTHER: + return Key::OriginOther; + case GPGME_KEYORG_UNKNOWN: + default: + return Key::OriginUnknown; + } +} + +Key::Origin UserID::origin() const +{ + if (isNull()) { + return Key::OriginUnknown; + } + return gpgme_origin_to_pp_origin(uid->origin); +} + +time_t UserID::lastUpdate() const +{ + return static_cast(uid ? uid->last_update : 0); +} + Error Key::addUid(const char *uid) { if (isNull()) { @@ -986,25 +1022,7 @@ Key::Origin Key::origin() const if (isNull()) { return OriginUnknown; } - switch (key->origin) { - case GPGME_KEYORG_KS: - return OriginKS; - case GPGME_KEYORG_DANE: - return OriginDane; - case GPGME_KEYORG_WKD: - return OriginWKD; - case GPGME_KEYORG_URL: - return OriginURL; - case GPGME_KEYORG_FILE: - return OriginFile; - case GPGME_KEYORG_SELF: - return OriginSelf; - case GPGME_KEYORG_OTHER: - return OriginOther; - case GPGME_KEYORG_UNKNOWN: - default: - return OriginUnknown; - } + return gpgme_origin_to_pp_origin(key->origin); } time_t Key::lastUpdate() const diff --git a/lang/cpp/src/key.h b/lang/cpp/src/key.h index 07ddc256..76a0d4f4 100644 --- a/lang/cpp/src/key.h +++ b/lang/cpp/src/key.h @@ -392,6 +392,16 @@ public: * * @returns an error on error.*/ Error revoke(); + + /*! Get the origin of the key. + * + * @returns the Origin. */ + Key::Origin origin() const; + + /*! Get the last update time. + * + * @returns the last update time. */ + time_t lastUpdate() const; private: shared_gpgme_key_t key; gpgme_user_id_t uid;