aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-03-15 10:59:49 +0000
committerChristian Grothoff <christian@grothoff.org>2012-03-15 10:59:49 +0000
commit06ab78ee651fdda7cf37a7c012445bb087060a05 (patch)
tree3bc1c510eb0c1440406245832ab0aacc8ad011cd /src
parent6ae1a7d3bab29dd9d75c268aee9d0e0e002acf6c (diff)
downloadgnunet-06ab78ee651fdda7cf37a7c012445bb087060a05.tar.gz
gnunet-06ab78ee651fdda7cf37a7c012445bb087060a05.zip
add -P option for printing peer identities with gnunet-rsa
Diffstat (limited to 'src')
-rw-r--r--src/util/gnunet-rsa.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/util/gnunet-rsa.c b/src/util/gnunet-rsa.c
index 2dd1f376f..bfd854e65 100644
--- a/src/util/gnunet-rsa.c
+++ b/src/util/gnunet-rsa.c
@@ -28,9 +28,14 @@
28 28
29 29
30/** 30/**
31 * Flag for reverse lookup. 31 * Flag for printing public key.
32 */ 32 */
33static int print; 33static int print_public_key;
34
35/**
36 * Flag for printing hash of public key.
37 */
38static int print_peer_identity;
34 39
35 40
36/** 41/**
@@ -47,7 +52,7 @@ run (void *cls, char *const *args, const char *cfgfile,
47{ 52{
48 struct GNUNET_CRYPTO_RsaPrivateKey *pk; 53 struct GNUNET_CRYPTO_RsaPrivateKey *pk;
49 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; 54 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
50 char *s; 55 struct GNUNET_PeerIdentity pid;
51 56
52 if (NULL == args[0]) 57 if (NULL == args[0])
53 { 58 {
@@ -55,13 +60,24 @@ run (void *cls, char *const *args, const char *cfgfile,
55 return; 60 return;
56 } 61 }
57 pk = GNUNET_CRYPTO_rsa_key_create_from_file (args[0]); 62 pk = GNUNET_CRYPTO_rsa_key_create_from_file (args[0]);
58 if (print) 63 if (print_public_key)
59 { 64 {
65 char *s;
66
60 GNUNET_CRYPTO_rsa_key_get_public (pk, &pub); 67 GNUNET_CRYPTO_rsa_key_get_public (pk, &pub);
61 s = GNUNET_CRYPTO_rsa_public_key_to_string (&pub); 68 s = GNUNET_CRYPTO_rsa_public_key_to_string (&pub);
62 fprintf (stdout, "%s\n", s); 69 fprintf (stdout, "%s\n", s);
63 GNUNET_free (s); 70 GNUNET_free (s);
64 } 71 }
72 if (print_peer_identity)
73 {
74 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
75
76 GNUNET_CRYPTO_rsa_key_get_public (pk, &pub);
77 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
78 GNUNET_CRYPTO_hash_to_enc (&pid.hashPubKey, &enc);
79 fprintf (stdout, "%s\n", enc.encoding);
80 }
65 GNUNET_CRYPTO_rsa_key_free (pk); 81 GNUNET_CRYPTO_rsa_key_free (pk);
66} 82}
67 83
@@ -77,9 +93,12 @@ int
77main (int argc, char *const *argv) 93main (int argc, char *const *argv)
78{ 94{
79 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 95 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
80 { 'p', "print", NULL, 96 { 'p', "print-public-key", NULL,
81 gettext_noop ("print the public key in ASCII format"), 97 gettext_noop ("print the public key in ASCII format"),
82 0, &GNUNET_GETOPT_set_one, &print }, 98 0, &GNUNET_GETOPT_set_one, &print_public_key },
99 { 'P', "print-peer-identity", NULL,
100 gettext_noop ("print the hash of the public key in ASCII format"),
101 0, &GNUNET_GETOPT_set_one, &print_peer_identity },
83 GNUNET_GETOPT_OPTION_END 102 GNUNET_GETOPT_OPTION_END
84 }; 103 };
85 return (GNUNET_OK == 104 return (GNUNET_OK ==