GNUNET_CRYPTO_ecdsa_public_key_to_string (const struct GNUNET_CRYPTO_EcdsaPublicKey *pub);
+/**
+ * Convert a private key to a string.
+ *
+ * @param priv key to convert
+ * @return string representing @a pub
+ */
+char *
+GNUNET_CRYPTO_eddsa_private_key_to_string (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv);
+
+
/**
* Convert a public key to a string.
*
}
+/**
+ * Convert a private key to a string.
+ *
+ * @param priv key to convert
+ * @return string representing @a pub
+ */
+char *
+GNUNET_CRYPTO_eddsa_private_key_to_string (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
+{
+ char *privkeybuf;
+ size_t keylen = (sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)) * 8;
+ char *end;
+
+ if (keylen % 5 > 0)
+ keylen += 5 - keylen % 5;
+ keylen /= 5;
+ privkeybuf = GNUNET_malloc (keylen + 1);
+ end = GNUNET_STRINGS_data_to_string ((unsigned char *) priv,
+ sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey),
+ privkeybuf,
+ keylen);
+ if (NULL == end)
+ {
+ GNUNET_free (privkeybuf);
+ return NULL;
+ }
+ *end = '\0';
+ return privkeybuf;
+}
+
+
/**
* Convert a string representing a public key to a public key.
*
if (enclen != keylen)
return GNUNET_SYSERR;
- if (GNUNET_OK != GNUNET_STRINGS_string_to_data (enc, enclen,
- pub,
- sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (enc, enclen,
+ pub,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
return GNUNET_SYSERR;
return GNUNET_OK;
}
if (enclen != keylen)
return GNUNET_SYSERR;
- if (GNUNET_OK != GNUNET_STRINGS_string_to_data (enc, enclen,
- pub,
- sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)))
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (enc, enclen,
+ pub,
+ sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)))
return GNUNET_SYSERR;
return GNUNET_OK;
}
*/
static int print_public_key;
+/**
+ * Flag for printing private key.
+ */
+static int print_private_key;
+
/**
* Flag for printing public key in hex.
*/
create_keys (args[0], args[1]);
return;
}
- if (print_public_key || print_public_key_hex)
+ if (print_public_key || print_public_key_hex || print_private_key)
{
char *str;
struct GNUNET_DISK_FileHandle *keyfile;
GNUNET_DISK_PERM_NONE);
if (NULL == keyfile)
return;
- while (sizeof (pk) == GNUNET_DISK_file_read (keyfile, &pk, sizeof (pk)))
+ while (sizeof (pk) ==
+ GNUNET_DISK_file_read (keyfile, &pk, sizeof (pk)))
{
GNUNET_CRYPTO_eddsa_key_get_public (&pk, &pub);
if (print_public_key_hex)
{
print_hex ("HEX:", &pub, sizeof (pub));
}
- else
+ else if (print_public_key)
{
str = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub);
FPRINTF (stdout, "%s\n", str);
GNUNET_free (str);
}
+ else if (print_private_key)
+ {
+ str = GNUNET_CRYPTO_eddsa_private_key_to_string (&pk);
+ FPRINTF (stdout, "%s\n", str);
+ GNUNET_free (str);
+ }
}
GNUNET_DISK_file_close (keyfile);
}
"print-public-key",
gettext_noop ("print the public key in ASCII format"),
&print_public_key),
+ GNUNET_GETOPT_option_flag ('P',
+ "print-private-key",
+ gettext_noop ("print the private key in ASCII format"),
+ &print_private_key),
GNUNET_GETOPT_option_flag ('x',
"print-hex",
gettext_noop ("print the public key in HEX format"),