aboutsummaryrefslogtreecommitdiff
path: root/src/gnsrecord/gnunet-gnsrecord-tvg.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnsrecord/gnunet-gnsrecord-tvg.c')
-rw-r--r--src/gnsrecord/gnunet-gnsrecord-tvg.c46
1 files changed, 34 insertions, 12 deletions
diff --git a/src/gnsrecord/gnunet-gnsrecord-tvg.c b/src/gnsrecord/gnunet-gnsrecord-tvg.c
index ea2c6e3bb..f1420d2d0 100644
--- a/src/gnsrecord/gnunet-gnsrecord-tvg.c
+++ b/src/gnsrecord/gnunet-gnsrecord-tvg.c
@@ -37,9 +37,10 @@
37#define TEST_RRCOUNT 2 37#define TEST_RRCOUNT 2
38 38
39static void 39static void
40print_bytes (void *buf, 40print_bytes_ (void *buf,
41 size_t buf_len, 41 size_t buf_len,
42 int fold) 42 int fold,
43 int in_be)
43{ 44{
44 int i; 45 int i;
45 46
@@ -47,11 +48,22 @@ print_bytes (void *buf,
47 { 48 {
48 if ((0 != i) && (0 != fold) && (i % fold == 0)) 49 if ((0 != i) && (0 != fold) && (i % fold == 0))
49 printf ("\n"); 50 printf ("\n");
50 printf ("%02x", ((unsigned char*) buf)[i]); 51 if (in_be)
52 printf ("%02x", ((unsigned char*) buf)[buf_len - 1 - i]);
53 else
54 printf ("%02x", ((unsigned char*) buf)[i]);
51 } 55 }
52 printf ("\n"); 56 printf ("\n");
53} 57}
54 58
59static void
60print_bytes (void *buf,
61 size_t buf_len,
62 int fold)
63{
64 print_bytes_ (buf, buf_len, fold, 0);
65}
66
55 67
56static void 68static void
57print_record (const struct GNUNET_GNSRECORD_Data *rd) 69print_record (const struct GNUNET_GNSRECORD_Data *rd)
@@ -95,6 +107,7 @@ run_pkey (void)
95 size_t data_size; 107 size_t data_size;
96 char *rdata; 108 char *rdata;
97 size_t rdata_size; 109 size_t rdata_size;
110 uint32_t rd_count_nbo;
98 char ztld[128]; 111 char ztld[128];
99 112
100 id_priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); 113 id_priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY);
@@ -102,10 +115,10 @@ run_pkey (void)
102 GNUNET_IDENTITY_key_get_public (&id_priv, 115 GNUNET_IDENTITY_key_get_public (&id_priv,
103 &id_pub); 116 &id_pub);
104 fprintf (stdout, 117 fprintf (stdout,
105 "Zone private key (d, little-endian, with ztype prepended):\n"); 118 "Zone private key (d, big-endian):\n");
106 print_bytes (&id_priv, GNUNET_IDENTITY_key_get_length (&id_pub), 8); // FIXME length for privkey? 119 print_bytes_ (&id_priv.ecdsa_key, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 8, 1);
107 fprintf (stdout, "\n"); 120 fprintf (stdout, "\n");
108 fprintf (stdout, "Zone identifier (zid):\n"); 121 fprintf (stdout, "Zone identifier (ztype|zkey):\n");
109 print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); 122 print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8);
110 GNUNET_STRINGS_data_to_string (&id_pub, 123 GNUNET_STRINGS_data_to_string (&id_pub,
111 GNUNET_IDENTITY_key_get_length (&id_pub), 124 GNUNET_IDENTITY_key_get_length (&id_pub),
@@ -143,10 +156,14 @@ run_pkey (void)
143 rdata_size = GNUNET_GNSRECORD_records_get_size (2, 156 rdata_size = GNUNET_GNSRECORD_records_get_size (2,
144 rd); 157 rd);
145 rdata = GNUNET_malloc (rdata_size); 158 rdata = GNUNET_malloc (rdata_size);
159 rd_count_nbo = htonl(2);
160 GNUNET_memcpy (rdata,
161 &rd_count_nbo,
162 sizeof (uint32_t));
146 GNUNET_GNSRECORD_records_serialize (2, 163 GNUNET_GNSRECORD_records_serialize (2,
147 rd, 164 rd,
148 rdata_size, 165 rdata_size,
149 rdata); 166 rdata + sizeof (uint32_t));
150 fprintf (stdout, "RDATA:\n"); 167 fprintf (stdout, "RDATA:\n");
151 print_bytes (rdata, rdata_size, 8); 168 print_bytes (rdata, rdata_size, 8);
152 fprintf (stdout, "\n"); 169 fprintf (stdout, "\n");
@@ -197,6 +214,7 @@ run_edkey (void)
197 size_t data_size; 214 size_t data_size;
198 char *rdata; 215 char *rdata;
199 size_t rdata_size; 216 size_t rdata_size;
217 uint32_t rd_count_nbo;
200 char ztld[128]; 218 char ztld[128];
201 219
202 id_priv.type = htonl (GNUNET_IDENTITY_TYPE_EDDSA); 220 id_priv.type = htonl (GNUNET_IDENTITY_TYPE_EDDSA);
@@ -204,10 +222,10 @@ run_edkey (void)
204 GNUNET_IDENTITY_key_get_public (&id_priv, 222 GNUNET_IDENTITY_key_get_public (&id_priv,
205 &id_pub); 223 &id_pub);
206 fprintf (stdout, 224 fprintf (stdout,
207 "Zone private key (d, little-endian, with ztype prepended):\n"); 225 "Zone private key (d, big-endian):\n");
208 print_bytes (&id_priv, GNUNET_IDENTITY_key_get_length (&id_pub), 8); // FIXME length for privkey? 226 print_bytes_ (&id_priv.eddsa_key, sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey), 8, 1);
209 fprintf (stdout, "\n"); 227 fprintf (stdout, "\n");
210 fprintf (stdout, "Zone identifier (zid):\n"); 228 fprintf (stdout, "Zone identifier (ztype|zkey):\n");
211 print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); 229 print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8);
212 GNUNET_STRINGS_data_to_string (&id_pub, 230 GNUNET_STRINGS_data_to_string (&id_pub,
213 GNUNET_IDENTITY_key_get_length (&id_pub), 231 GNUNET_IDENTITY_key_get_length (&id_pub),
@@ -244,11 +262,15 @@ run_edkey (void)
244 262
245 rdata_size = GNUNET_GNSRECORD_records_get_size (2, 263 rdata_size = GNUNET_GNSRECORD_records_get_size (2,
246 rd); 264 rd);
247 rdata = GNUNET_malloc (rdata_size); 265 rdata = GNUNET_malloc (sizeof (uint32_t) + rdata_size);
266 rd_count_nbo = htonl(2);
267 GNUNET_memcpy (rdata,
268 &rd_count_nbo,
269 sizeof (uint32_t));
248 GNUNET_GNSRECORD_records_serialize (2, 270 GNUNET_GNSRECORD_records_serialize (2,
249 rd, 271 rd,
250 rdata_size, 272 rdata_size,
251 rdata); 273 rdata + sizeof (uint32_t));
252 fprintf (stdout, "RDATA:\n"); 274 fprintf (stdout, "RDATA:\n");
253 print_bytes (rdata, rdata_size, 8); 275 print_bytes (rdata, rdata_size, 8);
254 fprintf (stdout, "\n"); 276 fprintf (stdout, "\n");