aboutsummaryrefslogtreecommitdiffstats
path: root/src/gpgme.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2015-08-30 17:04:44 +0000
committerWerner Koch <[email protected]>2015-08-30 17:04:44 +0000
commitc4b6b35bfa98e478f1d13f4ce3e664771f2604c2 (patch)
tree103c0bba4e50e1b49446e0203b38d46bf75cd94d /src/gpgme.c
parentPost release updates (diff)
downloadgpgme-c4b6b35bfa98e478f1d13f4ce3e664771f2604c2.tar.gz
gpgme-c4b6b35bfa98e478f1d13f4ce3e664771f2604c2.zip
Add gpgme_pubkey_algo_string
* src/gpgme.h.in (GPGME_PK_EDDSA): New. (gpgme_pubkey_algo_string): New. * src/conversion.c (_gpgme_map_pk_algo): Add new algo. * src/gpgme.c (gpgme_pubkey_algo_string): New. (gpgme_pubkey_algo_name): Reformat. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'src/gpgme.c')
-rw-r--r--src/gpgme.c81
1 files changed, 55 insertions, 26 deletions
diff --git a/src/gpgme.c b/src/gpgme.c
index 0cf999a7..343e7752 100644
--- a/src/gpgme.c
+++ b/src/gpgme.c
@@ -1,7 +1,7 @@
/* gpgme.c - GnuPG Made Easy.
Copyright (C) 2000 Werner Koch (dd9jn)
Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2012,
- 2014 g10 Code GmbH
+ 2014, 2015 g10 Code GmbH
This file is part of GPGME.
@@ -994,41 +994,70 @@ gpgme_sig_notation_get (gpgme_ctx_t ctx)
return ctx->sig_notations;
}
+
-const char *
-gpgme_pubkey_algo_name (gpgme_pubkey_algo_t algo)
+/* Return a public key algorithm string made of the algorithm and size
+ or the curve name. May return NULL on error. Caller must free the
+ result using gpgme_free. */
+char *
+gpgme_pubkey_algo_string (gpgme_subkey_t subkey)
{
- switch (algo)
+ const char *prefix = NULL;
+ char *result;
+
+ if (!subkey)
{
- case GPGME_PK_RSA:
- return "RSA";
+ gpg_err_set_errno (EINVAL);
+ return NULL;
+ }
+ switch (subkey->pubkey_algo)
+ {
+ case GPGME_PK_RSA:
case GPGME_PK_RSA_E:
- return "RSA-E";
-
- case GPGME_PK_RSA_S:
- return "RSA-S";
-
- case GPGME_PK_ELG_E:
- return "ELG-E";
-
- case GPGME_PK_DSA:
- return "DSA";
-
+ case GPGME_PK_RSA_S: prefix = "rsa"; break;
+ case GPGME_PK_ELG_E: prefix = "elg"; break;
+ case GPGME_PK_DSA: prefix = "dsa"; break;
+ case GPGME_PK_ELG: prefix = "xxx"; break;
case GPGME_PK_ECC:
- return "ECC";
+ case GPGME_PK_ECDH:
+ case GPGME_PK_ECDSA:
+ case GPGME_PK_EDDSA: prefix = ""; break;
+ }
- case GPGME_PK_ELG:
- return "ELG";
+ if (prefix && *prefix)
+ {
+ char buffer[40];
+ snprintf (buffer, sizeof buffer, "%s%u", prefix, subkey->length);
+ result = strdup (buffer);
+ }
+ else if (prefix && subkey->curve && *subkey->curve)
+ result = strdup (subkey->curve);
+ else if (prefix)
+ result = strdup ("E_error");
+ else
+ result = strdup ("unknown");
- case GPGME_PK_ECDSA:
- return "ECDSA";
+ return result;
+}
- case GPGME_PK_ECDH:
- return "ECDH";
- default:
- return NULL;
+const char *
+gpgme_pubkey_algo_name (gpgme_pubkey_algo_t algo)
+{
+ switch (algo)
+ {
+ case GPGME_PK_RSA: return "RSA";
+ case GPGME_PK_RSA_E: return "RSA-E";
+ case GPGME_PK_RSA_S: return "RSA-S";
+ case GPGME_PK_ELG_E: return "ELG-E";
+ case GPGME_PK_DSA: return "DSA";
+ case GPGME_PK_ECC: return "ECC";
+ case GPGME_PK_ELG: return "ELG";
+ case GPGME_PK_ECDSA: return "ECDSA";
+ case GPGME_PK_ECDH: return "ECDH";
+ case GPGME_PK_EDDSA: return "EdDSA";
+ default: return NULL;
}
}