#!/usr/bin/env python

""" Convert a list of strings into the encoding of a DNS TXT record,
using the syntax for unknown types (RFC 3597). Convenient for types
which are based on TXT (like WALLET or RESINFO) as long as they are
not yet implemented in the zone file parser. """

import sys

if len(sys.argv) <= 1:
    raise Exception("Usage: %s list-of-strings" % sys.argv[0])

value = ""
length = 0
for s in sys.argv[1:]:
    string = s.encode("ASCII")
    l = len(string)
    if l > 255:
         raise Exception("Maximum length 255 bytes exceeded for \"%s\"" % string)
    value += "%02x" % l
    length += 1
    for c in string:
        value += "%02x" % c
        length += 1
    value += " "
print("\# %i %s" % (length, value))
