diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2020-10-22 19:09:12 +0200 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2020-10-22 19:09:12 +0200 |
commit | ea1d3fd9f54879992fb997a1e94cfd6830085c4b (patch) | |
tree | 7a3fb2ad932a6ab0df3ae6bc5d5fea30575f5171 /src/gnsrecord | |
parent | acc69a8e5c921e5bbb03260383936487ec9ce0ca (diff) | |
download | gnunet-ea1d3fd9f54879992fb997a1e94cfd6830085c4b.tar.gz gnunet-ea1d3fd9f54879992fb997a1e94cfd6830085c4b.zip |
-more gnsrecord API
Diffstat (limited to 'src/gnsrecord')
-rw-r--r-- | src/gnsrecord/gnsrecord_misc.c | 47 | ||||
-rw-r--r-- | src/gnsrecord/gnunet-gnsrecord-tvg.c | 12 |
2 files changed, 57 insertions, 2 deletions
diff --git a/src/gnsrecord/gnsrecord_misc.c b/src/gnsrecord/gnsrecord_misc.c index 4b1695d69..ba8803850 100644 --- a/src/gnsrecord/gnsrecord_misc.c +++ b/src/gnsrecord/gnsrecord_misc.c | |||
@@ -272,6 +272,51 @@ GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, | |||
272 | } | 272 | } |
273 | 273 | ||
274 | 274 | ||
275 | enum GNUNET_GenericReturnValue | ||
276 | GNUNET_GNSRECORD_identity_from_data (const char *data, | ||
277 | size_t data_size, | ||
278 | uint32_t type, | ||
279 | struct GNUNET_IDENTITY_PublicKey *key) | ||
280 | { | ||
281 | if (GNUNET_NO == GNUNET_GNSRECORD_is_zonekey_type (type)) | ||
282 | return GNUNET_SYSERR; | ||
283 | if (data_size > sizeof (struct GNUNET_IDENTITY_PublicKey)) | ||
284 | return GNUNET_SYSERR; | ||
285 | key->type = type; | ||
286 | memcpy (key, data, data_size); | ||
287 | return GNUNET_OK; | ||
288 | } | ||
289 | |||
290 | enum GNUNET_GenericReturnValue | ||
291 | GNUNET_GNSRECORD_data_from_identity (const struct | ||
292 | GNUNET_IDENTITY_PublicKey *key, | ||
293 | char **data, | ||
294 | size_t *data_size, | ||
295 | uint32_t *type) | ||
296 | { | ||
297 | *type = key->type; | ||
298 | *data_size = GNUNET_IDENTITY_key_get_length (key); | ||
299 | if (0 == *data_size) | ||
300 | return GNUNET_SYSERR; | ||
301 | *data = GNUNET_malloc (*data_size); | ||
302 | memcpy (*data, key, *data_size); | ||
303 | return GNUNET_OK; | ||
304 | } | ||
305 | |||
306 | |||
307 | enum GNUNET_GenericReturnValue | ||
308 | GNUNET_GNSRECORD_is_zonekey_type (uint32_t type) | ||
309 | { | ||
310 | switch (type) | ||
311 | { | ||
312 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
313 | case GNUNET_GNSRECORD_TYPE_EDKEY: | ||
314 | return GNUNET_YES; | ||
315 | default: | ||
316 | return GNUNET_NO; | ||
317 | } | ||
318 | } | ||
319 | |||
275 | size_t | 320 | size_t |
276 | GNUNET_GNSRECORD_block_get_size (const struct GNUNET_GNSRECORD_Block *block) | 321 | GNUNET_GNSRECORD_block_get_size (const struct GNUNET_GNSRECORD_Block *block) |
277 | { | 322 | { |
@@ -325,6 +370,7 @@ GNUNET_GNSRECORD_query_from_block (const struct GNUNET_GNSRECORD_Block *block, | |||
325 | 370 | ||
326 | } | 371 | } |
327 | 372 | ||
373 | |||
328 | enum GNUNET_GenericReturnValue | 374 | enum GNUNET_GenericReturnValue |
329 | GNUNET_GNSRECORD_record_to_identity_key (const struct GNUNET_GNSRECORD_Data *rd, | 375 | GNUNET_GNSRECORD_record_to_identity_key (const struct GNUNET_GNSRECORD_Data *rd, |
330 | struct GNUNET_IDENTITY_PublicKey *key) | 376 | struct GNUNET_IDENTITY_PublicKey *key) |
@@ -346,4 +392,5 @@ GNUNET_GNSRECORD_record_to_identity_key (const struct GNUNET_GNSRECORD_Data *rd, | |||
346 | 392 | ||
347 | } | 393 | } |
348 | 394 | ||
395 | |||
349 | /* end of gnsrecord_misc.c */ | 396 | /* end of gnsrecord_misc.c */ |
diff --git a/src/gnsrecord/gnunet-gnsrecord-tvg.c b/src/gnsrecord/gnunet-gnsrecord-tvg.c index c29f377bc..47b13bdab 100644 --- a/src/gnsrecord/gnunet-gnsrecord-tvg.c +++ b/src/gnsrecord/gnunet-gnsrecord-tvg.c | |||
@@ -98,16 +98,24 @@ run (void *cls, | |||
98 | size_t data_size; | 98 | size_t data_size; |
99 | char *rdata; | 99 | char *rdata; |
100 | size_t rdata_size; | 100 | size_t rdata_size; |
101 | char ztld[128]; | ||
101 | 102 | ||
102 | id_priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); | 103 | id_priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
103 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key); | 104 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key); |
104 | GNUNET_IDENTITY_key_get_public (&id_priv, | 105 | GNUNET_IDENTITY_key_get_public (&id_priv, |
105 | &id_pub); | 106 | &id_pub); |
106 | fprintf (stdout, "Zone private key (d, little-endian scalar):\n"); | 107 | fprintf (stdout, "Zone private key (d, little-endian, with ztype prepended):\n"); |
107 | print_bytes (&id_priv, GNUNET_IDENTITY_key_get_length (&id_pub), 8); //FIXME length for privkey? | 108 | print_bytes (&id_priv, GNUNET_IDENTITY_key_get_length (&id_pub), 8); //FIXME length for privkey? |
108 | fprintf (stdout, "\n"); | 109 | fprintf (stdout, "\n"); |
109 | fprintf (stdout, "Zone public key (zk):\n"); | 110 | fprintf (stdout, "Zone identifier (zid):\n"); |
110 | print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); | 111 | print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); |
112 | GNUNET_STRINGS_data_to_string (&id_pub, | ||
113 | GNUNET_IDENTITY_key_get_length (&id_pub), | ||
114 | ztld, | ||
115 | sizeof (ztld)); | ||
116 | fprintf (stdout, "\n"); | ||
117 | fprintf (stdout, "Encoded zone identifier (zkl = zTLD):\n"); | ||
118 | fprintf (stdout, "%s\n", ztld); | ||
111 | fprintf (stdout, "\n"); | 119 | fprintf (stdout, "\n"); |
112 | 120 | ||
113 | pkey_data_p.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); | 121 | pkey_data_p.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |