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;
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))
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,
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;