summaryrefslogtreecommitdiff
path: root/src/testing/list-keys.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/list-keys.c')
-rw-r--r--src/testing/list-keys.c112
1 files changed, 56 insertions, 56 deletions
diff --git a/src/testing/list-keys.c b/src/testing/list-keys.c
index 39a48d071..37b880b49 100644
--- a/src/testing/list-keys.c
+++ b/src/testing/list-keys.c
@@ -15,10 +15,10 @@ static int result;
15 * @param cfg the configuration file handle 15 * @param cfg the configuration file handle
16 */ 16 */
17static void 17static void
18run (void *cls, 18run(void *cls,
19 char *const *args, 19 char *const *args,
20 const char *cfgfile, 20 const char *cfgfile,
21 const struct GNUNET_CONFIGURATION_Handle *config) 21 const struct GNUNET_CONFIGURATION_Handle *config)
22{ 22{
23 char *idfile; 23 char *idfile;
24 struct GNUNET_DISK_FileHandle *f; 24 struct GNUNET_DISK_FileHandle *f;
@@ -31,79 +31,79 @@ run (void *cls,
31 unsigned int nmax; 31 unsigned int nmax;
32 32
33 if ((NULL == args) || (NULL == args[0])) 33 if ((NULL == args) || (NULL == args[0]))
34 { 34 {
35 fprintf (stderr, "Need the hostkey file\n"); 35 fprintf(stderr, "Need the hostkey file\n");
36 return; 36 return;
37 } 37 }
38 idfile = args[0]; 38 idfile = args[0];
39 if (GNUNET_OK != 39 if (GNUNET_OK !=
40 GNUNET_DISK_file_size (idfile, &fsize, GNUNET_YES, GNUNET_YES)) 40 GNUNET_DISK_file_size(idfile, &fsize, GNUNET_YES, GNUNET_YES))
41 { 41 {
42 GNUNET_break (0); 42 GNUNET_break(0);
43 return; 43 return;
44 } 44 }
45 if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE)) 45 if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE))
46 { 46 {
47 fprintf (stderr, _ ("Incorrect hostkey file format: %s\n"), idfile); 47 fprintf(stderr, _("Incorrect hostkey file format: %s\n"), idfile);
48 return; 48 return;
49 } 49 }
50 f = GNUNET_DISK_file_open (idfile, 50 f = GNUNET_DISK_file_open(idfile,
51 GNUNET_DISK_OPEN_READ, 51 GNUNET_DISK_OPEN_READ,
52 GNUNET_DISK_PERM_NONE); 52 GNUNET_DISK_PERM_NONE);
53 if (NULL == f) 53 if (NULL == f)
54 { 54 {
55 GNUNET_break (0); 55 GNUNET_break(0);
56 return; 56 return;
57 } 57 }
58 data = GNUNET_DISK_file_map (f, &map, GNUNET_DISK_MAP_TYPE_READ, fsize); 58 data = GNUNET_DISK_file_map(f, &map, GNUNET_DISK_MAP_TYPE_READ, fsize);
59 if (NULL == data) 59 if (NULL == data)
60 { 60 {
61 GNUNET_break (0); 61 GNUNET_break(0);
62 GNUNET_DISK_file_close (f); 62 GNUNET_DISK_file_close(f);
63 return; 63 return;
64 } 64 }
65 nmax = fsize / GNUNET_TESTING_HOSTKEYFILESIZE; 65 nmax = fsize / GNUNET_TESTING_HOSTKEYFILESIZE;
66 for (cnt = nskip; cnt < (nskip + nkeys); cnt++) 66 for (cnt = nskip; cnt < (nskip + nkeys); cnt++)
67 {
68 if (nskip + cnt >= nmax)
69 { 67 {
70 printf ("Max keys %u reached\n", nmax); 68 if (nskip + cnt >= nmax)
71 break; 69 {
70 printf("Max keys %u reached\n", nmax);
71 break;
72 }
73 GNUNET_memcpy(&pkey,
74 data + (cnt * GNUNET_TESTING_HOSTKEYFILESIZE),
75 GNUNET_TESTING_HOSTKEYFILESIZE);
76 GNUNET_CRYPTO_eddsa_key_get_public(&pkey, &id.public_key);
77 printf("Key %u: %s\n", cnt, GNUNET_i2s_full(&id));
72 } 78 }
73 GNUNET_memcpy (&pkey,
74 data + (cnt * GNUNET_TESTING_HOSTKEYFILESIZE),
75 GNUNET_TESTING_HOSTKEYFILESIZE);
76 GNUNET_CRYPTO_eddsa_key_get_public (&pkey, &id.public_key);
77 printf ("Key %u: %s\n", cnt, GNUNET_i2s_full (&id));
78 }
79 result = GNUNET_OK; 79 result = GNUNET_OK;
80 GNUNET_DISK_file_unmap (map); 80 GNUNET_DISK_file_unmap(map);
81 GNUNET_DISK_file_close (f); 81 GNUNET_DISK_file_close(f);
82} 82}
83 83
84 84
85int 85int
86main (int argc, char *argv[]) 86main(int argc, char *argv[])
87{ 87{
88 struct GNUNET_GETOPT_CommandLineOption option[] = 88 struct GNUNET_GETOPT_CommandLineOption option[] =
89 {GNUNET_GETOPT_option_uint ('n', 89 { GNUNET_GETOPT_option_uint('n',
90 "num-keys", 90 "num-keys",
91 "COUNT", 91 "COUNT",
92 gettext_noop ("list COUNT number of keys"), 92 gettext_noop("list COUNT number of keys"),
93 &nkeys), 93 &nkeys),
94 GNUNET_GETOPT_OPTION_END}; 94 GNUNET_GETOPT_OPTION_END };
95 int ret; 95 int ret;
96 96
97 result = GNUNET_SYSERR; 97 result = GNUNET_SYSERR;
98 nkeys = 10; 98 nkeys = 10;
99 ret = 99 ret =
100 GNUNET_PROGRAM_run (argc, 100 GNUNET_PROGRAM_run(argc,
101 argv, 101 argv,
102 "list-keys", 102 "list-keys",
103 "Lists the peer IDs corresponding to the given keys file\n", 103 "Lists the peer IDs corresponding to the given keys file\n",
104 option, 104 option,
105 &run, 105 &run,
106 NULL); 106 NULL);
107 if (GNUNET_OK != ret) 107 if (GNUNET_OK != ret)
108 return 1; 108 return 1;
109 if (GNUNET_SYSERR == result) 109 if (GNUNET_SYSERR == result)