diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-11-01 10:33:57 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-11-01 10:33:57 +0100 |
commit | d1a84861ce988b9cdc87e19ff140400833e616fd (patch) | |
tree | 6bdeab590dc8b6f0695f9808831c96475b299c67 /src/util/gnunet-ecc.c | |
parent | a901264efb50a61f096a4966a0cb5789690706f0 (diff) | |
download | gnunet-d1a84861ce988b9cdc87e19ff140400833e616fd.tar.gz gnunet-d1a84861ce988b9cdc87e19ff140400833e616fd.zip |
add -P option to gnunet-ecc
Diffstat (limited to 'src/util/gnunet-ecc.c')
-rw-r--r-- | src/util/gnunet-ecc.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/util/gnunet-ecc.c b/src/util/gnunet-ecc.c index 42ecc2101..66a4bd3e9 100644 --- a/src/util/gnunet-ecc.c +++ b/src/util/gnunet-ecc.c | |||
@@ -49,6 +49,11 @@ static unsigned int list_keys_count; | |||
49 | static int print_public_key; | 49 | static int print_public_key; |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * Flag for printing private key. | ||
53 | */ | ||
54 | static int print_private_key; | ||
55 | |||
56 | /** | ||
52 | * Flag for printing public key in hex. | 57 | * Flag for printing public key in hex. |
53 | */ | 58 | */ |
54 | static int print_public_key_hex; | 59 | static int print_public_key_hex; |
@@ -377,7 +382,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
377 | create_keys (args[0], args[1]); | 382 | create_keys (args[0], args[1]); |
378 | return; | 383 | return; |
379 | } | 384 | } |
380 | if (print_public_key || print_public_key_hex) | 385 | if (print_public_key || print_public_key_hex || print_private_key) |
381 | { | 386 | { |
382 | char *str; | 387 | char *str; |
383 | struct GNUNET_DISK_FileHandle *keyfile; | 388 | struct GNUNET_DISK_FileHandle *keyfile; |
@@ -388,19 +393,26 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
388 | GNUNET_DISK_PERM_NONE); | 393 | GNUNET_DISK_PERM_NONE); |
389 | if (NULL == keyfile) | 394 | if (NULL == keyfile) |
390 | return; | 395 | return; |
391 | while (sizeof (pk) == GNUNET_DISK_file_read (keyfile, &pk, sizeof (pk))) | 396 | while (sizeof (pk) == |
397 | GNUNET_DISK_file_read (keyfile, &pk, sizeof (pk))) | ||
392 | { | 398 | { |
393 | GNUNET_CRYPTO_eddsa_key_get_public (&pk, &pub); | 399 | GNUNET_CRYPTO_eddsa_key_get_public (&pk, &pub); |
394 | if (print_public_key_hex) | 400 | if (print_public_key_hex) |
395 | { | 401 | { |
396 | print_hex ("HEX:", &pub, sizeof (pub)); | 402 | print_hex ("HEX:", &pub, sizeof (pub)); |
397 | } | 403 | } |
398 | else | 404 | else if (print_public_key) |
399 | { | 405 | { |
400 | str = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub); | 406 | str = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub); |
401 | FPRINTF (stdout, "%s\n", str); | 407 | FPRINTF (stdout, "%s\n", str); |
402 | GNUNET_free (str); | 408 | GNUNET_free (str); |
403 | } | 409 | } |
410 | else if (print_private_key) | ||
411 | { | ||
412 | str = GNUNET_CRYPTO_eddsa_private_key_to_string (&pk); | ||
413 | FPRINTF (stdout, "%s\n", str); | ||
414 | GNUNET_free (str); | ||
415 | } | ||
404 | } | 416 | } |
405 | GNUNET_DISK_file_close (keyfile); | 417 | GNUNET_DISK_file_close (keyfile); |
406 | } | 418 | } |
@@ -438,6 +450,10 @@ main (int argc, | |||
438 | "print-public-key", | 450 | "print-public-key", |
439 | gettext_noop ("print the public key in ASCII format"), | 451 | gettext_noop ("print the public key in ASCII format"), |
440 | &print_public_key), | 452 | &print_public_key), |
453 | GNUNET_GETOPT_option_flag ('P', | ||
454 | "print-private-key", | ||
455 | gettext_noop ("print the private key in ASCII format"), | ||
456 | &print_private_key), | ||
441 | GNUNET_GETOPT_option_flag ('x', | 457 | GNUNET_GETOPT_option_flag ('x', |
442 | "print-hex", | 458 | "print-hex", |
443 | gettext_noop ("print the public key in HEX format"), | 459 | gettext_noop ("print the public key in HEX format"), |