cpp: Add origin and last_update to UserID
authorAndre Heinecke <aheinecke@intevation.de>
Thu, 19 Apr 2018 09:56:15 +0000 (11:56 +0200)
committerAndre Heinecke <aheinecke@intevation.de>
Thu, 19 Apr 2018 09:56:15 +0000 (11:56 +0200)
* NEWS: Mention it.
* lang/cpp/src/key.cpp, lang/cpp/src/key.h (UserID::lastUpdate),
(UserID::origin): New.
(gpgme_origin_to_pp_origin): New helper.

NEWS
lang/cpp/src/key.cpp
lang/cpp/src/key.h

diff --git a/NEWS b/NEWS
index 9d6bd0a..6deb325 100644 (file)
--- 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)
 -------------------------------------------------
index 838033c..034286f 100644 (file)
@@ -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()) {
@@ -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
index 07ddc25..76a0d4f 100644 (file)
@@ -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;