diff options
Diffstat (limited to 'src/gnsrecord/gnsrecord_misc.c')
-rw-r--r-- | src/gnsrecord/gnsrecord_misc.c | 151 |
1 files changed, 138 insertions, 13 deletions
diff --git a/src/gnsrecord/gnsrecord_misc.c b/src/gnsrecord/gnsrecord_misc.c index 5061f8493..82c38f19a 100644 --- a/src/gnsrecord/gnsrecord_misc.c +++ b/src/gnsrecord/gnsrecord_misc.c | |||
@@ -62,14 +62,14 @@ GNUNET_GNSRECORD_string_to_lowercase (const char *src) | |||
62 | * @return string form; will be overwritten by next call to #GNUNET_GNSRECORD_z2s | 62 | * @return string form; will be overwritten by next call to #GNUNET_GNSRECORD_z2s |
63 | */ | 63 | */ |
64 | const char * | 64 | const char * |
65 | GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_EcdsaPublicKey *z) | 65 | GNUNET_GNSRECORD_z2s (const struct GNUNET_IDENTITY_PublicKey *z) |
66 | { | 66 | { |
67 | static char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) * 8]; | 67 | static char buf[sizeof(struct GNUNET_IDENTITY_PublicKey) * 8]; |
68 | char *end; | 68 | char *end; |
69 | 69 | ||
70 | end = GNUNET_STRINGS_data_to_string ((const unsigned char *) z, | 70 | end = GNUNET_STRINGS_data_to_string ((const unsigned char *) z, |
71 | sizeof(struct | 71 | sizeof(struct |
72 | GNUNET_CRYPTO_EcdsaPublicKey), | 72 | GNUNET_IDENTITY_PublicKey), |
73 | buf, sizeof(buf)); | 73 | buf, sizeof(buf)); |
74 | if (NULL == end) | 74 | if (NULL == end) |
75 | { | 75 | { |
@@ -99,7 +99,7 @@ GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, | |||
99 | if (a->record_type != b->record_type) | 99 | if (a->record_type != b->record_type) |
100 | { | 100 | { |
101 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 101 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
102 | "Record type %lu != %lu\n", a->record_type, b->record_type); | 102 | "Record type %u != %u\n", a->record_type, b->record_type); |
103 | return GNUNET_NO; | 103 | return GNUNET_NO; |
104 | } | 104 | } |
105 | if ((a->expiration_time != b->expiration_time) && | 105 | if ((a->expiration_time != b->expiration_time) && |
@@ -107,15 +107,15 @@ GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, | |||
107 | { | 107 | { |
108 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 108 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
109 | "Expiration time %llu != %llu\n", | 109 | "Expiration time %llu != %llu\n", |
110 | a->expiration_time, | 110 | (unsigned long long) a->expiration_time, |
111 | b->expiration_time); | 111 | (unsigned long long) b->expiration_time); |
112 | return GNUNET_NO; | 112 | return GNUNET_NO; |
113 | } | 113 | } |
114 | if ((a->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS) | 114 | if ((a->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS) |
115 | != (b->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS)) | 115 | != (b->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS)) |
116 | { | 116 | { |
117 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 117 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
118 | "Flags %lu (%lu) != %lu (%lu)\n", a->flags, | 118 | "Flags %u (%u) != %u (%u)\n", a->flags, |
119 | a->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS, b->flags, | 119 | a->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS, b->flags, |
120 | b->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS); | 120 | b->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS); |
121 | return GNUNET_NO; | 121 | return GNUNET_NO; |
@@ -236,12 +236,12 @@ GNUNET_GNSRECORD_is_expired (const struct GNUNET_GNSRECORD_Data *rd) | |||
236 | * key in an encoding suitable for DNS labels. | 236 | * key in an encoding suitable for DNS labels. |
237 | */ | 237 | */ |
238 | const char * | 238 | const char * |
239 | GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) | 239 | GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_IDENTITY_PublicKey *pkey) |
240 | { | 240 | { |
241 | static char ret[128]; | 241 | static char ret[128]; |
242 | char *pkeys; | 242 | char *pkeys; |
243 | 243 | ||
244 | pkeys = GNUNET_CRYPTO_ecdsa_public_key_to_string (pkey); | 244 | pkeys = GNUNET_IDENTITY_public_key_to_string (pkey); |
245 | GNUNET_snprintf (ret, | 245 | GNUNET_snprintf (ret, |
246 | sizeof(ret), | 246 | sizeof(ret), |
247 | "%s", | 247 | "%s", |
@@ -262,15 +262,140 @@ GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) | |||
262 | */ | 262 | */ |
263 | int | 263 | int |
264 | GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, | 264 | GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, |
265 | struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) | 265 | struct GNUNET_IDENTITY_PublicKey *pkey) |
266 | { | 266 | { |
267 | if (GNUNET_OK != | 267 | if (GNUNET_OK != |
268 | GNUNET_CRYPTO_ecdsa_public_key_from_string (zkey, | 268 | GNUNET_IDENTITY_public_key_from_string (zkey, |
269 | strlen (zkey), | 269 | pkey)) |
270 | pkey)) | ||
271 | return GNUNET_SYSERR; | 270 | return GNUNET_SYSERR; |
272 | return GNUNET_OK; | 271 | return GNUNET_OK; |
273 | } | 272 | } |
274 | 273 | ||
275 | 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 | return (GNUNET_IDENTITY_read_key_from_buffer (key, data, data_size) == | ||
286 | data_size? | ||
287 | GNUNET_OK : | ||
288 | GNUNET_SYSERR); | ||
289 | } | ||
290 | |||
291 | |||
292 | enum GNUNET_GenericReturnValue | ||
293 | GNUNET_GNSRECORD_data_from_identity (const struct | ||
294 | GNUNET_IDENTITY_PublicKey *key, | ||
295 | char **data, | ||
296 | size_t *data_size, | ||
297 | uint32_t *type) | ||
298 | { | ||
299 | *type = ntohl (key->type); | ||
300 | *data_size = GNUNET_IDENTITY_key_get_length (key); | ||
301 | if (0 == *data_size) | ||
302 | return GNUNET_SYSERR; | ||
303 | *data = GNUNET_malloc (*data_size); | ||
304 | return (GNUNET_IDENTITY_write_key_to_buffer (key, *data, *data_size) == | ||
305 | *data_size? | ||
306 | GNUNET_OK : | ||
307 | GNUNET_SYSERR); | ||
308 | } | ||
309 | |||
310 | |||
311 | enum GNUNET_GenericReturnValue | ||
312 | GNUNET_GNSRECORD_is_zonekey_type (uint32_t type) | ||
313 | { | ||
314 | switch (type) | ||
315 | { | ||
316 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
317 | case GNUNET_GNSRECORD_TYPE_EDKEY: | ||
318 | return GNUNET_YES; | ||
319 | default: | ||
320 | return GNUNET_NO; | ||
321 | } | ||
322 | } | ||
323 | |||
324 | |||
325 | size_t | ||
326 | GNUNET_GNSRECORD_block_get_size (const struct GNUNET_GNSRECORD_Block *block) | ||
327 | { | ||
328 | switch (ntohl (block->type)) | ||
329 | { | ||
330 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
331 | return sizeof (uint32_t) /* zone type */ | ||
332 | + sizeof (block->ecdsa_block) /* EcdsaBlock */ | ||
333 | + ntohl (block->ecdsa_block.purpose.size) /* Length of signed data */ | ||
334 | - sizeof (block->ecdsa_block.purpose); /* Purpose already in EcdsaBlock */ | ||
335 | break; | ||
336 | default: | ||
337 | return 0; | ||
338 | } | ||
339 | return 0; | ||
340 | } | ||
341 | |||
342 | |||
343 | struct GNUNET_TIME_Absolute | ||
344 | GNUNET_GNSRECORD_block_get_expiration (const struct | ||
345 | GNUNET_GNSRECORD_Block *block) | ||
346 | { | ||
347 | |||
348 | switch (ntohl (block->type)) | ||
349 | { | ||
350 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
351 | return GNUNET_TIME_absolute_ntoh (block->ecdsa_block.expiration_time); | ||
352 | default: | ||
353 | return GNUNET_TIME_absolute_get_zero_ (); | ||
354 | } | ||
355 | return GNUNET_TIME_absolute_get_zero_ (); | ||
356 | |||
357 | } | ||
358 | |||
359 | |||
360 | enum GNUNET_GenericReturnValue | ||
361 | GNUNET_GNSRECORD_query_from_block (const struct GNUNET_GNSRECORD_Block *block, | ||
362 | struct GNUNET_HashCode *query) | ||
363 | { | ||
364 | switch (ntohl (block->type)) | ||
365 | { | ||
366 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
367 | GNUNET_CRYPTO_hash (&block->ecdsa_block.derived_key, | ||
368 | sizeof (block->ecdsa_block.derived_key), | ||
369 | query); | ||
370 | return GNUNET_OK; | ||
371 | default: | ||
372 | return GNUNET_SYSERR; | ||
373 | } | ||
374 | return GNUNET_SYSERR; | ||
375 | |||
376 | } | ||
377 | |||
378 | |||
379 | enum GNUNET_GenericReturnValue | ||
380 | GNUNET_GNSRECORD_record_to_identity_key (const struct GNUNET_GNSRECORD_Data *rd, | ||
381 | struct GNUNET_IDENTITY_PublicKey *key) | ||
382 | { | ||
383 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
384 | "Got record of type %u\n", | ||
385 | rd->record_type); | ||
386 | switch (rd->record_type) | ||
387 | { | ||
388 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
389 | key->type = htonl (rd->record_type); | ||
390 | memcpy (&key->ecdsa_key, rd->data, sizeof (key->ecdsa_key)); | ||
391 | return GNUNET_OK; | ||
392 | default: | ||
393 | return GNUNET_SYSERR; | ||
394 | } | ||
395 | return GNUNET_SYSERR; | ||
396 | |||
397 | |||
398 | } | ||
399 | |||
400 | |||
276 | /* end of gnsrecord_misc.c */ | 401 | /* end of gnsrecord_misc.c */ |