2 #include "gnunet_util_lib.h"
3 #include "gnunet_testing_lib.h"
5 static unsigned int nkeys;
6 static unsigned int nskip;
13 * @param args arguments passed to GNUNET_PROGRAM_run
14 * @param cfgfile the path to configuration file
15 * @param cfg the configuration file handle
18 run (void *cls, char *const *args, const char *cfgfile,
19 const struct GNUNET_CONFIGURATION_Handle *config)
22 struct GNUNET_DISK_FileHandle *f;
24 struct GNUNET_DISK_MapHandle *map;
25 struct GNUNET_CRYPTO_EddsaPrivateKey pkey;
26 struct GNUNET_PeerIdentity id;
31 if ((NULL == args) || (NULL == args[0]))
33 FPRINTF (stderr, "Need the hostkey file\n");
38 GNUNET_DISK_file_size (idfile, &fsize, GNUNET_YES, GNUNET_YES))
43 if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE))
46 _("Incorrect hostkey file format: %s\n"), idfile);
49 f = GNUNET_DISK_file_open (idfile, GNUNET_DISK_OPEN_READ,
50 GNUNET_DISK_PERM_NONE);
56 data = GNUNET_DISK_file_map (f, &map, GNUNET_DISK_MAP_TYPE_READ, fsize);
60 GNUNET_DISK_file_close (f);
63 nmax = fsize / GNUNET_TESTING_HOSTKEYFILESIZE;
64 for (cnt = nskip; cnt < (nskip + nkeys); cnt++)
66 if (nskip + cnt >= nmax)
68 PRINTF ("Max keys %u reached\n", nmax);
72 data + (cnt * GNUNET_TESTING_HOSTKEYFILESIZE),
73 GNUNET_TESTING_HOSTKEYFILESIZE);
74 GNUNET_CRYPTO_eddsa_key_get_public (&pkey, &id.public_key);
75 PRINTF ("Key %u: %s\n", cnt, GNUNET_i2s_full (&id));
78 GNUNET_DISK_file_unmap (map);
79 GNUNET_DISK_file_close (f);
83 int main (int argc, char *argv[])
85 struct GNUNET_GETOPT_CommandLineOption option[] = {
86 GNUNET_GETOPT_OPTION_SET_UINT ('n',
89 gettext_noop ("list COUNT number of keys"),
91 GNUNET_GETOPT_OPTION_END
95 result = GNUNET_SYSERR;
98 GNUNET_PROGRAM_run (argc, argv, "list-keys", "Lists the peer IDs corresponding to the given keys file\n",
100 if (GNUNET_OK != ret)
102 if (GNUNET_SYSERR == result)