From: Jelte Jansen Date: Mon, 28 Jul 2008 12:44:37 +0000 (+0000) Subject: patch from Jakob Schlyter adding BubbleBabble output in DS RR printing X-Git-Tag: release-1.4.0~93 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2bcff81e99feaca8bf4635d5331bb6c326c4a315;p=thirdparty%2Fldns.git patch from Jakob Schlyter adding BubbleBabble output in DS RR printing --- diff --git a/host2str.c b/host2str.c index aff5887e..dc35a050 100644 --- a/host2str.c +++ b/host2str.c @@ -938,7 +938,16 @@ ldns_rr2buffer_str(ldns_buffer *output, const ldns_rr *rr) case LDNS_RR_TYPE_RRSIG: ldns_buffer_printf(output, " ;{id = %d}", ldns_rdf2native_int16(ldns_rr_rdf(rr, 6))); - break; + break; + case LDNS_RR_TYPE_DS: + { + uint8_t *data = ldns_rdf_data(ldns_rr_rdf(rr, 3)); + size_t len = ldns_rdf_size(ldns_rr_rdf(rr, 3)); + char *babble = ldns_bubblebabble(data, len); + ldns_buffer_printf(output, " ; %s", babble); + LDNS_FREE(babble); + } + break; default: break; diff --git a/ldns/util.h.in b/ldns/util.h.in index c60b49a6..8088d2f9 100644 --- a/ldns/util.h.in +++ b/ldns/util.h.in @@ -277,4 +277,14 @@ time_t mktime_from_utc(const struct tm *tm); */ int ldns_init_random(FILE *fd, unsigned int size); + +/** + * Encode data as BubbleBabble + * + * \param[in] a pointer to data to be encoded + * \param[in] size the number of bytes of data + * \return a string of BubbleBabble + */ +char *ldns_bubblebabble(uint8_t *data, size_t len); + #endif /* !_UTIL_H */ diff --git a/util.c b/util.c index 7b471295..75444569 100644 --- a/util.c +++ b/util.c @@ -318,3 +318,49 @@ ldns_init_random(FILE *fd, unsigned int size) return 0; } +char * +ldns_bubblebabble(uint8_t *data, size_t len) +{ + char vowels[] = { 'a', 'e', 'i', 'o', 'u', 'y' }; + char consonants[] = { 'b', 'c', 'd', 'f', 'g', 'h', 'k', 'l', 'm', + 'n', 'p', 'r', 's', 't', 'v', 'z', 'x' }; + size_t i, j = 0, rounds, seed = 1; + char *retval; + + rounds = (len / 2) + 1; + retval = LDNS_XMALLOC(char, rounds * 6); + retval[j++] = 'x'; + for (i = 0; i < rounds; i++) { + size_t idx0, idx1, idx2, idx3, idx4; + if ((i + 1 < rounds) || (len % 2 != 0)) { + idx0 = (((((size_t)(data[2 * i])) >> 6) & 3) + + seed) % 6; + idx1 = (((size_t)(data[2 * i])) >> 2) & 15; + idx2 = ((((size_t)(data[2 * i])) & 3) + + (seed / 6)) % 6; + retval[j++] = vowels[idx0]; + retval[j++] = consonants[idx1]; + retval[j++] = vowels[idx2]; + if ((i + 1) < rounds) { + idx3 = (((size_t)(data[(2 * i) + 1])) >> 4) & 15; + idx4 = (((size_t)(data[(2 * i) + 1]))) & 15; + retval[j++] = consonants[idx3]; + retval[j++] = '-'; + retval[j++] = consonants[idx4]; + seed = ((seed * 5) + + ((((size_t)(data[2 * i])) * 7) + + ((size_t)(data[(2 * i) + 1])))) % 36; + } + } else { + idx0 = seed % 6; + idx1 = 16; + idx2 = seed / 6; + retval[j++] = vowels[idx0]; + retval[j++] = consonants[idx1]; + retval[j++] = vowels[idx2]; + } + } + retval[j++] = 'x'; + retval[j++] = '\0'; + return retval; +}