2 #include "gnunet_util_lib.h"
3 #include "gnunet_testing_lib.h"
5 static unsigned int nkeys;
6 static unsigned int nskip;
17 * @param args arguments passed to GNUNET_PROGRAM_run
18 * @param cfgfile the path to configuration file
19 * @param cfg the configuration file handle
22 run (void *cls, char *const *args, const char *cfgfile,
23 const struct GNUNET_CONFIGURATION_Handle *config)
26 struct GNUNET_DISK_FileHandle *f;
28 struct GNUNET_DISK_MapHandle *map;
29 struct GNUNET_CRYPTO_EddsaPrivateKey pkey;
30 struct GNUNET_PeerIdentity id;
35 if ((NULL == args) || (NULL == args[0]))
37 FPRINTF (stderr, "Need the hostkey file\n");
42 GNUNET_DISK_file_size (idfile, &fsize, GNUNET_YES, GNUNET_YES))
47 if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE))
50 _("Incorrect hostkey file format: %s\n"), idfile);
53 f = GNUNET_DISK_file_open (idfile, GNUNET_DISK_OPEN_READ,
54 GNUNET_DISK_PERM_NONE);
60 data = GNUNET_DISK_file_map (f, &map, GNUNET_DISK_MAP_TYPE_READ, fsize);
64 GNUNET_DISK_file_close (f);
67 nmax = fsize / GNUNET_TESTING_HOSTKEYFILESIZE;
68 for (cnt = nskip; cnt < (nskip + nkeys); cnt++)
70 if (nskip + cnt >= nmax)
72 PRINTF ("Max keys %u reached\n", nmax);
75 (void) memcpy (&pkey, data + (cnt * GNUNET_TESTING_HOSTKEYFILESIZE),
76 GNUNET_TESTING_HOSTKEYFILESIZE);
77 GNUNET_CRYPTO_eddsa_key_get_public (&pkey, &id.public_key);
78 PRINTF ("Key %u: %s\n", cnt, GNUNET_i2s_full (&id));
81 GNUNET_DISK_file_unmap (map);
82 GNUNET_DISK_file_close (f);
86 int main (int argc, char *argv[])
88 struct GNUNET_GETOPT_CommandLineOption option[] = {
89 {'n', "num-keys", "COUNT",
90 gettext_noop ("list COUNT number of keys"),
91 GNUNET_YES, &GNUNET_GETOPT_set_uint, &nkeys},
92 {'s', "skip", "COUNT",
93 gettext_noop ("skip COUNT number of keys in the beginning"),
94 GNUNET_YES, &GNUNET_GETOPT_set_uint, &nskip},
95 GNUNET_GETOPT_OPTION_END
99 result = GNUNET_SYSERR;
102 GNUNET_PROGRAM_run (argc, argv, "list-keys", "Lists the peer IDs corresponding to the given keys file\n",
104 if (GNUNET_OK != ret)
106 if (GNUNET_SYSERR == result)