about summary refs log tree commit diff stats
path: root/src/pgp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pgp')
-rw-r--r--src/pgp/gpg.c29
-rw-r--r--src/pgp/gpg.h1
2 files changed, 30 insertions, 0 deletions
diff --git a/src/pgp/gpg.c b/src/pgp/gpg.c
index 3e2cfe67..be35bb3a 100644
--- a/src/pgp/gpg.c
+++ b/src/pgp/gpg.c
@@ -281,6 +281,35 @@ p_gpg_free_key(ProfPGPKey *key)
 }
 
 gboolean
+p_gpg_valid_key(const char * const keyid)
+{
+    gpgme_ctx_t ctx;
+    gpgme_error_t error = gpgme_new(&ctx);
+    if (error) {
+        log_error("GPG: Failed to create gpgme context. %s %s", gpgme_strsource(error), gpgme_strerror(error));
+        return FALSE;
+    }
+
+    gpgme_key_t key = NULL;
+    error = gpgme_get_key(ctx, keyid, &key, 1);
+
+    if (error || key == NULL) {
+        log_error("GPG: Failed to get key. %s %s", gpgme_strsource(error), gpgme_strerror(error));
+        gpgme_release(ctx);
+        return FALSE;
+    }
+
+    if (key) {
+        gpgme_release(ctx);
+        gpgme_key_unref(key);
+        return TRUE;
+    }
+
+    gpgme_release(ctx);
+    return FALSE;
+}
+
+gboolean
 p_gpg_available(const char * const barejid)
 {
     char *fp = g_hash_table_lookup(fingerprints, barejid);
diff --git a/src/pgp/gpg.h b/src/pgp/gpg.h
index 77f14d1e..7b3a4433 100644
--- a/src/pgp/gpg.h
+++ b/src/pgp/gpg.h
@@ -48,6 +48,7 @@ void p_gpg_on_disconnect(void);
 GSList* p_gpg_list_keys(void);
 gboolean p_gpg_addkey(const char * const jid, const char * const keyid);
 GHashTable* p_gpg_fingerprints(void);
+gboolean p_gpg_valid_key(const char * const keyid);
 gboolean p_gpg_available(const char * const barejid);
 const char* p_gpg_libver(void);
 void p_gpg_free_key(ProfPGPKey *key);