mirror of
git://git.gnupg.org/gnupg.git
synced 2025-04-17 15:44:34 +02:00
common: Extend the new get_keyalgo_string function
* common/openpgp-oid.c (openpgp_oid_or_name_to_curve): New. (get_keyalgo_string): Use it. -- We do not always have an OID, so except the name or the alias of the curve as well. This creates a second entry mapping to the same name but that does not matter. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
d1c518cdc9
commit
332a72f734
@ -389,9 +389,9 @@ openpgp_curve_to_oid (const char *name, unsigned int *r_nbits)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Map an OpenPGP OID to the Libgcrypt curve NAME. Returns NULL for
|
/* Map an OpenPGP OID to the Libgcrypt curve name. Returns NULL for
|
||||||
unknown curve names. Unless CANON is set we prefer an alias name
|
* unknown curve names. Unless CANON is set we prefer an alias name
|
||||||
here which is more suitable for printing. */
|
* here which is more suitable for printing. */
|
||||||
const char *
|
const char *
|
||||||
openpgp_oid_to_curve (const char *oidstr, int canon)
|
openpgp_oid_to_curve (const char *oidstr, int canon)
|
||||||
{
|
{
|
||||||
@ -408,6 +408,27 @@ openpgp_oid_to_curve (const char *oidstr, int canon)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Map an OpenPGP OID, name or alias to the Libgcrypt curve name.
|
||||||
|
* Returns NULL for unknown curve names. Unless CANON is set we
|
||||||
|
* prefer an alias name here which is more suitable for printing. */
|
||||||
|
const char *
|
||||||
|
openpgp_oid_or_name_to_curve (const char *oidname, int canon)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!oidname)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
for (i=0; oidtable[i].name; i++)
|
||||||
|
if (!strcmp (oidtable[i].oidstr, oidname)
|
||||||
|
|| !strcmp (oidtable[i].name, oidname)
|
||||||
|
|| (oidtable[i].alias &&!strcmp (oidtable[i].alias, oidname)))
|
||||||
|
return !canon && oidtable[i].alias? oidtable[i].alias : oidtable[i].name;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Return true if the curve with NAME is supported. */
|
/* Return true if the curve with NAME is supported. */
|
||||||
static int
|
static int
|
||||||
curve_supported_p (const char *name)
|
curve_supported_p (const char *name)
|
||||||
@ -528,7 +549,7 @@ const char *
|
|||||||
get_keyalgo_string (enum gcry_pk_algos algo,
|
get_keyalgo_string (enum gcry_pk_algos algo,
|
||||||
unsigned int nbits, const char *curve)
|
unsigned int nbits, const char *curve)
|
||||||
{
|
{
|
||||||
const char *prefix = NULL;
|
const char *prefix;
|
||||||
int i;
|
int i;
|
||||||
char *name, *curvebuf;
|
char *name, *curvebuf;
|
||||||
|
|
||||||
@ -537,9 +558,11 @@ get_keyalgo_string (enum gcry_pk_algos algo,
|
|||||||
case GCRY_PK_RSA: prefix = "rsa"; break;
|
case GCRY_PK_RSA: prefix = "rsa"; break;
|
||||||
case GCRY_PK_ELG: prefix = "elg"; break;
|
case GCRY_PK_ELG: prefix = "elg"; break;
|
||||||
case GCRY_PK_DSA: prefix = "dsa"; break;
|
case GCRY_PK_DSA: prefix = "dsa"; break;
|
||||||
|
case GCRY_PK_ECC:
|
||||||
case GCRY_PK_ECDH:
|
case GCRY_PK_ECDH:
|
||||||
case GCRY_PK_ECDSA:
|
case GCRY_PK_ECDSA:
|
||||||
case GCRY_PK_EDDSA: prefix = ""; break;
|
case GCRY_PK_EDDSA: prefix = ""; break;
|
||||||
|
default: prefix = NULL; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prefix && *prefix && nbits)
|
if (prefix && *prefix && nbits)
|
||||||
@ -569,7 +592,7 @@ get_keyalgo_string (enum gcry_pk_algos algo,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Not yet in the table - add it. */
|
/* Not yet in the table - add it. */
|
||||||
curvename = openpgp_oid_to_curve (curve, 0);
|
curvename = openpgp_oid_or_name_to_curve (curve, 0);
|
||||||
if (curvename)
|
if (curvename)
|
||||||
name = xasprintf ("%s", curvename);
|
name = xasprintf ("%s", curvename);
|
||||||
else if (curve)
|
else if (curve)
|
||||||
|
@ -232,6 +232,7 @@ int openpgp_oidbuf_is_cv25519 (const void *buf, size_t len);
|
|||||||
int openpgp_oid_is_cv25519 (gcry_mpi_t a);
|
int openpgp_oid_is_cv25519 (gcry_mpi_t a);
|
||||||
const char *openpgp_curve_to_oid (const char *name, unsigned int *r_nbits);
|
const char *openpgp_curve_to_oid (const char *name, unsigned int *r_nbits);
|
||||||
const char *openpgp_oid_to_curve (const char *oid, int canon);
|
const char *openpgp_oid_to_curve (const char *oid, int canon);
|
||||||
|
const char *openpgp_oid_or_name_to_curve (const char *oidname, int canon);
|
||||||
const char *openpgp_enum_curves (int *idxp);
|
const char *openpgp_enum_curves (int *idxp);
|
||||||
const char *openpgp_is_curve_supported (const char *name,
|
const char *openpgp_is_curve_supported (const char *name,
|
||||||
int *r_algo, unsigned int *r_nbits);
|
int *r_algo, unsigned int *r_nbits);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user