aboutsummaryrefslogtreecommitdiff
path: root/src/gnsrecord/gnsrecord_misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnsrecord/gnsrecord_misc.c')
-rw-r--r--src/gnsrecord/gnsrecord_misc.c95
1 files changed, 84 insertions, 11 deletions
diff --git a/src/gnsrecord/gnsrecord_misc.c b/src/gnsrecord/gnsrecord_misc.c
index 5061f8493..4b1695d69 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 */
64const char * 64const char *
65GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_EcdsaPublicKey *z) 65GNUNET_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) &&
@@ -115,7 +115,7 @@ GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a,
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 */
238const char * 238const char *
239GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) 239GNUNET_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,88 @@ GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
262 */ 262 */
263int 263int
264GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, 264GNUNET_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
275size_t
276GNUNET_GNSRECORD_block_get_size (const struct GNUNET_GNSRECORD_Block *block)
277{
278 switch (ntohl (block->type))
279 {
280 case GNUNET_GNSRECORD_TYPE_PKEY:
281 return sizeof (uint32_t) /* zone type */
282 + sizeof (block->ecdsa_block) /* EcdsaBlock */
283 + ntohl (block->ecdsa_block.purpose.size) /* Length of signed data */
284 - sizeof (block->ecdsa_block.purpose); /* Purpose already in EcdsaBlock */
285 break;
286 default:
287 return 0;
288 }
289 return 0;
290}
291
292
293struct GNUNET_TIME_Absolute
294GNUNET_GNSRECORD_block_get_expiration (const struct
295 GNUNET_GNSRECORD_Block *block)
296{
297
298 switch (ntohl (block->type))
299 {
300 case GNUNET_GNSRECORD_TYPE_PKEY:
301 return GNUNET_TIME_absolute_ntoh (block->ecdsa_block.expiration_time);
302 default:
303 return GNUNET_TIME_absolute_get_zero_ ();
304 }
305 return GNUNET_TIME_absolute_get_zero_ ();
306
307}
308
309
310enum GNUNET_GenericReturnValue
311GNUNET_GNSRECORD_query_from_block (const struct GNUNET_GNSRECORD_Block *block,
312 struct GNUNET_HashCode *query)
313{
314 switch (ntohl (block->type))
315 {
316 case GNUNET_GNSRECORD_TYPE_PKEY:
317 GNUNET_CRYPTO_hash (&block->ecdsa_block.derived_key,
318 sizeof (block->ecdsa_block.derived_key),
319 query);
320 return GNUNET_OK;
321 default:
322 return GNUNET_SYSERR;
323 }
324 return GNUNET_SYSERR;
325
326}
327
328enum GNUNET_GenericReturnValue
329GNUNET_GNSRECORD_record_to_identity_key (const struct GNUNET_GNSRECORD_Data *rd,
330 struct GNUNET_IDENTITY_PublicKey *key)
331{
332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
333 "Got record of type %u\n",
334 rd->record_type);
335 switch (rd->record_type)
336 {
337 case GNUNET_GNSRECORD_TYPE_PKEY:
338 key->type = htonl (rd->record_type);
339 memcpy (&key->ecdsa_key, rd->data, sizeof (key->ecdsa_key));
340 return GNUNET_OK;
341 default:
342 return GNUNET_SYSERR;
343 }
344 return GNUNET_SYSERR;
345
346
347}
348
276/* end of gnsrecord_misc.c */ 349/* end of gnsrecord_misc.c */