- def generate_rr(self, owner: str, zone: 'Zone') -> 'Any':
- return zone.RR(owner, 'MX', '{0} {1}'.format(self._priority, zone.abs_hostname(self._name)))
+ def generate_rr(self):
+ return RR('@', 'MX', '{0} {1}'.format(self._priority, self._name))
+
+
+class TXT:
+ def __init__(self, text: str) -> None:
+ # test for bad characters
+ for c in ('\n', '\r', '\t'):
+ if c in text:
+ raise Exception("TXT record {0} contains invalid character")
+ self._text = text
+
+ def generate_rr(self):
+ text = escape_TXT(self._text)
+ # split into chunks of max. 255 characters; be careful not to split right after a backslash
+ chunks = re.findall(r'.{0,254}[^\\]', text)
+ assert sum(len(c) for c in chunks) == len (text)
+ chunksep = '"\n' + ' '*20 + '"'
+ chunked = '( "' + chunksep.join(chunks) + '" )'
+ # generate the chunks
+ return RR('@', 'TXT', chunked)
+
+
+class DKIM(TXT): # helper class to treat DKIM more antively
+ class Version:
+ DKIM1 = "DKIM1"
+
+ class Algorithm:
+ RSA = "rsa"
+
+ def __init__(self, selector, version, alg, key):
+ self._selector = check_label(selector)
+ version = check_label(version)
+ alg = check_label(alg)
+ key = check_base64(key)
+ super().__init__("v={0}; k={1}; p={2}".format(version, alg, key))
+
+ def generate_rr(self):
+ return super().generate_rr().relativize('{}._domainkey'.format(self._selector))