about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-08-30 02:12:05 +0100
committerJames Booth <boothj5@gmail.com>2015-08-30 02:12:05 +0100
commit688be91c23aaa2f6a16db56d884d8920a3b11af5 (patch)
tree6fb0c42d07e8e35acf3fd773136f21dc4bcad7ce
parentb4722632b6fa447386b7d786efc8dafd22a3671c (diff)
downloadprofani-tty-688be91c23aaa2f6a16db56d884d8920a3b11af5.tar.gz
PGP: Format fingerprints
-rw-r--r--src/command/commands.c4
-rw-r--r--src/pgp/gpg.c23
-rw-r--r--src/pgp/gpg.h2
-rw-r--r--tests/unittests/pgp/stub_gpg.c6
4 files changed, 34 insertions, 1 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index 06c6d9b8..ca67f709 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -4238,7 +4238,9 @@ cmd_pgp(ProfWin *window, const char * const command, gchar **args)
             ProfPGPKey *key = g_hash_table_lookup(keys, curr->data);
             cons_show("  %s", key->name);
             cons_show("    ID          : %s", key->id);
-            cons_show("    Fingerprint : %s", key->fp);
+            char *format_fp = p_gpg_format_fp_str(key->fp);
+            cons_show("    Fingerprint : %s", format_fp);
+            free(format_fp);
             if (key->secret) {
                 cons_show("    Type        : PUBLIC, PRIVATE");
             } else {
diff --git a/src/pgp/gpg.c b/src/pgp/gpg.c
index 8d075cd9..cda77e13 100644
--- a/src/pgp/gpg.c
+++ b/src/pgp/gpg.c
@@ -671,6 +671,29 @@ p_gpg_autocomplete_key_reset(void)
     autocomplete_reset(key_ac);
 }
 
+char *
+p_gpg_format_fp_str(char *fp)
+{
+    if (!fp) {
+        return NULL;
+    }
+
+    GString *format = g_string_new("");
+    int i;
+    int len = strlen(fp);
+    for (i = 0; i < len; i++) {
+        g_string_append_c(format, fp[i]);
+        if (((i+1) % 4 == 0) && (i+1 < len)) {
+            g_string_append_c(format, ' ');
+        }
+    }
+
+    char *result = format->str;
+    g_string_free(format, FALSE);
+
+    return result;
+}
+
 static char*
 _remove_header_footer(char *str, const char * const footer)
 {
diff --git a/src/pgp/gpg.h b/src/pgp/gpg.h
index 48742dd7..3c84efaa 100644
--- a/src/pgp/gpg.h
+++ b/src/pgp/gpg.h
@@ -69,5 +69,7 @@ char* p_gpg_decrypt(const char * const cipher);
 void p_gpg_free_decrypted(char *decrypted);
 char* p_gpg_autocomplete_key(const char * const search_str);
 void p_gpg_autocomplete_key_reset(void);
+char* p_gpg_format_fp_str(char *fp);
+
 
 #endif
diff --git a/tests/unittests/pgp/stub_gpg.c b/tests/unittests/pgp/stub_gpg.c
index 4ac51ab5..b31dc34c 100644
--- a/tests/unittests/pgp/stub_gpg.c
+++ b/tests/unittests/pgp/stub_gpg.c
@@ -61,3 +61,9 @@ char * p_gpg_autocomplete_key(const char * const search_str)
     return NULL;
 }
 
+char *
+p_gpg_format_fp_str(char *fp)
+{
+    return NULL;
+}
+