diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-08-25 18:41:44 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-08-25 18:41:44 +0000 |
commit | 56ac8e5c6628c5f89c538149da966eb52a95b8f2 (patch) | |
tree | a39302edf6e810b827a2a4b39154228d9be41915 /src/gnsrecord | |
parent | aa435eeb5437249d349753f4c55daab297126de6 (diff) | |
download | gnunet-56ac8e5c6628c5f89c538149da966eb52a95b8f2.tar.gz gnunet-56ac8e5c6628c5f89c538149da966eb52a95b8f2.zip |
support RFC4043 and RFC 4398 mnemonics in conversion
Diffstat (limited to 'src/gnsrecord')
-rw-r--r-- | src/gnsrecord/plugin_gnsrecord_dns.c | 88 |
1 files changed, 78 insertions, 10 deletions
diff --git a/src/gnsrecord/plugin_gnsrecord_dns.c b/src/gnsrecord/plugin_gnsrecord_dns.c index 65ce9b0df..63fdce5f3 100644 --- a/src/gnsrecord/plugin_gnsrecord_dns.c +++ b/src/gnsrecord/plugin_gnsrecord_dns.c | |||
@@ -259,6 +259,74 @@ dns_value_to_string (void *cls, | |||
259 | 259 | ||
260 | 260 | ||
261 | /** | 261 | /** |
262 | * Convert RFC 4394 Mnemonics to the corresponding integer values. | ||
263 | * | ||
264 | * @param mnemonic string to look up | ||
265 | * @return the value, 0 if not found | ||
266 | */ | ||
267 | static unsigned int | ||
268 | rfc4394_mnemonic_to_value (const char *mnemonic) | ||
269 | { | ||
270 | static struct { | ||
271 | const char *mnemonic; | ||
272 | unsigned int val; | ||
273 | } table[] = { | ||
274 | { "PKIX", 1 }, | ||
275 | { "SPKI", 2 }, | ||
276 | { "PGP", 3 }, | ||
277 | { "IPKIX", 4 }, | ||
278 | { "ISPKI", 5 }, | ||
279 | { "IPGP", 6 }, | ||
280 | { "ACPKIX", 7}, | ||
281 | { "IACPKIX", 8}, | ||
282 | { "URI", 253}, | ||
283 | { "OID", 254}, | ||
284 | { NULL, 0 } | ||
285 | }; | ||
286 | unsigned int i; | ||
287 | |||
288 | for (i=0;NULL != table[i].mnemonic;i++) | ||
289 | if (0 == strcasecmp (mnemonic, | ||
290 | table[i].mnemonic)) | ||
291 | return table[i].val; | ||
292 | return 0; | ||
293 | } | ||
294 | |||
295 | |||
296 | /** | ||
297 | * Convert RFC 4034 algorithm types to the corresponding integer values. | ||
298 | * | ||
299 | * @param mnemonic string to look up | ||
300 | * @return the value, 0 if not found | ||
301 | */ | ||
302 | static unsigned int | ||
303 | rfc4034_mnemonic_to_value (const char *mnemonic) | ||
304 | { | ||
305 | static struct { | ||
306 | const char *mnemonic; | ||
307 | unsigned int val; | ||
308 | } table[] = { | ||
309 | { "RSAMD5", 1 }, | ||
310 | { "DH", 2 }, | ||
311 | { "DSA", 3 }, | ||
312 | { "ECC", 4 }, | ||
313 | { "RSASHA1", 5 }, | ||
314 | { "INDIRECT", 252 }, | ||
315 | { "PRIVATEDNS", 253 }, | ||
316 | { "PRIVATEOID", 254 }, | ||
317 | { NULL, 0 } | ||
318 | }; | ||
319 | unsigned int i; | ||
320 | |||
321 | for (i=0;NULL != table[i].mnemonic;i++) | ||
322 | if (0 == strcasecmp (mnemonic, | ||
323 | table[i].mnemonic)) | ||
324 | return table[i].val; | ||
325 | return 0; | ||
326 | } | ||
327 | |||
328 | |||
329 | /** | ||
262 | * Convert human-readable version of a 'value' of a record to the binary | 330 | * Convert human-readable version of a 'value' of a record to the binary |
263 | * representation. | 331 | * representation. |
264 | * | 332 | * |
@@ -356,12 +424,12 @@ dns_string_to_value (void *cls, | |||
356 | 424 | ||
357 | sdup = GNUNET_strdup (s); | 425 | sdup = GNUNET_strdup (s); |
358 | typep = strtok (sdup, " "); | 426 | typep = strtok (sdup, " "); |
359 | /* TODO: add typep mnemonic conversion according to RFC 4398 */ | ||
360 | if ( (NULL == typep) || | 427 | if ( (NULL == typep) || |
361 | (1 != SSCANF (typep, | 428 | ( (0 == (type = rfc4394_mnemonic_to_value (typep))) && |
362 | "%u", | 429 | ( (1 != SSCANF (typep, |
363 | &type)) || | 430 | "%u", |
364 | (type > UINT16_MAX) ) | 431 | &type)) || |
432 | (type > UINT16_MAX) ) ) ) | ||
365 | { | 433 | { |
366 | GNUNET_free (sdup); | 434 | GNUNET_free (sdup); |
367 | return GNUNET_SYSERR; | 435 | return GNUNET_SYSERR; |
@@ -377,12 +445,12 @@ dns_string_to_value (void *cls, | |||
377 | return GNUNET_SYSERR; | 445 | return GNUNET_SYSERR; |
378 | } | 446 | } |
379 | algp = strtok (NULL, " "); | 447 | algp = strtok (NULL, " "); |
380 | /* TODO: add algp mnemonic conversion according to RFC 4398/RFC 4034 */ | ||
381 | if ( (NULL == algp) || | 448 | if ( (NULL == algp) || |
382 | (1 != sscanf (algp, | 449 | ( (0 == (type = rfc4034_mnemonic_to_value (typep))) && |
383 | "%u", | 450 | ( (1 != sscanf (algp, |
384 | &alg)) || | 451 | "%u", |
385 | (alg > UINT8_MAX) ) | 452 | &alg)) || |
453 | (alg > UINT8_MAX) ) ) ) | ||
386 | { | 454 | { |
387 | GNUNET_free (sdup); | 455 | GNUNET_free (sdup); |
388 | return GNUNET_SYSERR; | 456 | return GNUNET_SYSERR; |