diff options
author | Maximilian Krambach <[email protected]> | 2018-04-20 13:23:57 +0000 |
---|---|---|
committer | Maximilian Krambach <[email protected]> | 2018-04-20 13:23:57 +0000 |
commit | 94f21d9f6bc1cf94e068e26eae53e593189dcec6 (patch) | |
tree | b176a836c504cbd71a5ca17ca025b23285d1505a /lang/cpp | |
parent | js: Initial commit for JavaScript Native Messaging API (diff) | |
parent | core: Do not modify args for ignored failures (diff) | |
download | gpgme-94f21d9f6bc1cf94e068e26eae53e593189dcec6.tar.gz gpgme-94f21d9f6bc1cf94e068e26eae53e593189dcec6.zip |
Merge branch 'master' into javascript-binding
Diffstat (limited to 'lang/cpp')
-rw-r--r-- | lang/cpp/src/key.cpp | 49 | ||||
-rw-r--r-- | lang/cpp/src/key.h | 31 |
2 files changed, 80 insertions, 0 deletions
diff --git a/lang/cpp/src/key.cpp b/lang/cpp/src/key.cpp index 0e86a19e..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<time_t>(uid ? uid->last_update : 0); +} + Error Key::addUid(const char *uid) { if (isNull()) { @@ -981,6 +1017,19 @@ Error Key::addUid(const char *uid) return ret; } +Key::Origin Key::origin() const +{ + if (isNull()) { + return OriginUnknown; + } + return gpgme_origin_to_pp_origin(key->origin); +} + +time_t Key::lastUpdate() const +{ + return static_cast<time_t>(key ? key->last_update : 0); +} + std::ostream &operator<<(std::ostream &os, const UserID &uid) { os << "GpgME::UserID("; diff --git a/lang/cpp/src/key.h b/lang/cpp/src/key.h index c3c711c1..76a0d4f4 100644 --- a/lang/cpp/src/key.h +++ b/lang/cpp/src/key.h @@ -178,6 +178,27 @@ public: */ static Key locate(const char *mbox); + /* @enum Origin + * @brief The Origin of the key. */ + enum Origin : unsigned int { + OriginUnknown = 0, + OriginKS = 1, + OriginDane = 3, + OriginWKD = 4, + OriginURL = 5, + OriginFile = 6, + OriginSelf = 7, + OriginOther = 31, + }; + /*! Get the origin of the key. + * + * @returns the Origin. */ + Origin origin() const; + + /*! Get the last update time. + * + * @returns the last update time. */ + time_t lastUpdate() const; private: gpgme_key_t impl() const { @@ -371,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; |