From: Andre Noll Date: Mon, 27 Aug 2018 15:30:33 +0000 (+0200) Subject: gcrypt: Drop unnecessary arguments of decode_key(). X-Git-Tag: v0.6.3~33^2~9 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=eb833d819057adb3916aa2f2704ca2df7fd6a48f gcrypt: Drop unnecessary arguments of decode_key(). Its single caller passes string literals, which are known at compile time. So we may get rid of the two arguments. --- diff --git a/gcrypt.c b/gcrypt.c index 694c0adb..50ddff46 100644 --- a/gcrypt.c +++ b/gcrypt.c @@ -106,8 +106,12 @@ static const char *gcrypt_strerror(gcry_error_t gret) return gcry_strerror(gcry_err_code(gret)); } -static int decode_key(const char *key_file, const char *header_str, - const char *footer_str, unsigned char **result) +/** Private keys start with this header. */ +#define PRIVATE_KEY_HEADER "-----BEGIN RSA PRIVATE KEY-----" +/** Private keys end with this footer. */ +#define PRIVATE_KEY_FOOTER "-----END RSA PRIVATE KEY-----" + +static int decode_key(const char *key_file, unsigned char **result) { int ret, ret2, i, j; void *map; @@ -119,13 +123,13 @@ static int decode_key(const char *key_file, const char *header_str, if (ret < 0) goto out; ret = -E_KEY_MARKER; - if (strncmp(map, header_str, strlen(header_str))) + if (strncmp(map, PRIVATE_KEY_HEADER, strlen(PRIVATE_KEY_HEADER))) goto unmap; - footer = strstr(map, footer_str); + footer = strstr(map, PRIVATE_KEY_FOOTER); ret = -E_KEY_MARKER; if (!footer) goto unmap; - begin = map + strlen(header_str); + begin = map + strlen(PRIVATE_KEY_HEADER); /* skip whitespace at the beginning */ for (; begin < footer; begin++) { if (para_isspace(*begin)) @@ -290,11 +294,6 @@ static int find_privkey_bignum_offset(const unsigned char *data, int len) return p - data; } -/** Private keys start with this header. */ -#define PRIVATE_KEY_HEADER "-----BEGIN RSA PRIVATE KEY-----" -/** Private keys end with this footer. */ -#define PRIVATE_KEY_FOOTER "-----END RSA PRIVATE KEY-----" - static int get_private_key(const char *key_file, struct asymmetric_key **result) { gcry_mpi_t n = NULL, e = NULL, d = NULL, p = NULL, q = NULL, @@ -307,8 +306,7 @@ static int get_private_key(const char *key_file, struct asymmetric_key **result) struct asymmetric_key *key; *result = NULL; - ret = decode_key(key_file, PRIVATE_KEY_HEADER, PRIVATE_KEY_FOOTER, - &blob); + ret = decode_key(key_file, &blob); if (ret < 0) return ret; blob_size = ret;