Show PGP error strings

This commit is contained in:
James Booth
2015-12-15 00:38:16 +00:00
parent 482eea4fcf
commit 88fd2a25ee
5 changed files with 33 additions and 14 deletions

View File

@@ -424,12 +424,13 @@ p_gpg_libver(void)
}
gboolean
p_gpg_valid_key(const char *const keyid)
p_gpg_valid_key(const char *const keyid, char **err_str)
{
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));
*err_str = strdup(gpgme_strerror(error));
return FALSE;
}
@@ -438,18 +439,21 @@ p_gpg_valid_key(const char *const keyid)
if (error || key == NULL) {
log_error("GPG: Failed to get key. %s %s", gpgme_strsource(error), gpgme_strerror(error));
*err_str = strdup(gpgme_strerror(error));
gpgme_release(ctx);
return FALSE;
}
if (key) {
if (key == NULL) {
*err_str = strdup("Unknown error");
gpgme_release(ctx);
gpgme_key_unref(key);
return TRUE;
return FALSE;
}
gpgme_release(ctx);
return FALSE;
gpgme_key_unref(key);
return TRUE;
}
gboolean

View File

@@ -59,7 +59,7 @@ GHashTable* p_gpg_list_keys(void);
void p_gpg_free_keys(GHashTable *keys);
gboolean p_gpg_addkey(const char *const jid, const char *const keyid);
GHashTable* p_gpg_pubkeys(void);
gboolean p_gpg_valid_key(const char *const keyid);
gboolean p_gpg_valid_key(const char *const keyid, char **err_str);
gboolean p_gpg_available(const char *const barejid);
const char* p_gpg_libver(void);
char* p_gpg_sign(const char *const str, const char *const fp);