summaryrefslogtreecommitdiff
path: root/common/sexputil.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/sexputil.c')
-rw-r--r--common/sexputil.c65
1 files changed, 18 insertions, 47 deletions
diff --git a/common/sexputil.c b/common/sexputil.c
index 0c5c730..a8dc1a5 100644
--- a/common/sexputil.c
+++ b/common/sexputil.c
@@ -512,53 +512,6 @@ get_rsa_pk_from_canon_sexp (const unsigned char *keydata, size_t keydatalen,
}
-/* Return the algo of a public RSA expressed as an canonical encoded
- S-expression. The return value is a statically allocated
- string. On error that string is set to NULL. */
-gpg_error_t
-get_pk_algo_from_canon_sexp (const unsigned char *keydata, size_t keydatalen,
- const char **r_algo)
-{
- gpg_error_t err;
- const unsigned char *buf, *tok;
- size_t buflen, toklen;
- int depth;
-
- *r_algo = NULL;
-
- buf = keydata;
- buflen = keydatalen;
- depth = 0;
- if ((err = parse_sexp (&buf, &buflen, &depth, &tok, &toklen)))
- return err;
- if ((err = parse_sexp (&buf, &buflen, &depth, &tok, &toklen)))
- return err;
- if (!tok || toklen != 10 || memcmp ("public-key", tok, toklen))
- return gpg_error (GPG_ERR_BAD_PUBKEY);
- if ((err = parse_sexp (&buf, &buflen, &depth, &tok, &toklen)))
- return err;
- if ((err = parse_sexp (&buf, &buflen, &depth, &tok, &toklen)))
- return err;
- if (!tok)
- return gpg_error (GPG_ERR_BAD_PUBKEY);
-
- if (toklen == 3 && !memcmp ("rsa", tok, toklen))
- *r_algo = "rsa";
- else if (toklen == 3 && !memcmp ("dsa", tok, toklen))
- *r_algo = "dsa";
- else if (toklen == 3 && !memcmp ("elg", tok, toklen))
- *r_algo = "elg";
- else if (toklen == 5 && !memcmp ("ecdsa", tok, toklen))
- *r_algo = "ecdsa";
- else if (toklen == 5 && !memcmp ("eddsa", tok, toklen))
- *r_algo = "eddsa";
- else
- return gpg_error (GPG_ERR_PUBKEY_ALGO);
-
- return 0;
-}
-
-
/* Return the algo of a public KEY of SEXP. */
int
get_pk_algo_from_key (gcry_sexp_t key)
@@ -606,3 +559,21 @@ get_pk_algo_from_key (gcry_sexp_t key)
return algo;
}
+
+
+/* This is a variant of get_pk_algo_from_key but takes an canonical
+ * encoded S-expression as input. Returns a GCRYPT public key
+ * identiier or 0 on error. */
+int
+get_pk_algo_from_canon_sexp (const unsigned char *keydata, size_t keydatalen)
+{
+ gcry_sexp_t sexp;
+ int algo;
+
+ if (gcry_sexp_sscan (&sexp, NULL, keydata, keydatalen))
+ return 0;
+
+ algo = get_pk_algo_from_key (sexp);
+ gcry_sexp_release (sexp);
+ return algo;
+}