diff options
| -rw-r--r-- | dns/rdtypes/ANY/CAA.py | 9 | ||||
| -rw-r--r-- | dns/rdtypes/ANY/CSYNC.py | 24 | ||||
| -rw-r--r-- | dns/rdtypes/ANY/HINFO.py | 18 | ||||
| -rw-r--r-- | dns/rdtypes/ANY/HIP.py | 24 | ||||
| -rw-r--r-- | dns/rdtypes/ANY/X25.py | 9 | ||||
| -rw-r--r-- | dns/rdtypes/IN/NAPTR.py | 3 | ||||
| -rw-r--r-- | dns/rdtypes/txtbase.py | 3 |
7 files changed, 23 insertions, 67 deletions
diff --git a/dns/rdtypes/ANY/CAA.py b/dns/rdtypes/ANY/CAA.py index d498107..f840530 100644 --- a/dns/rdtypes/ANY/CAA.py +++ b/dns/rdtypes/ANY/CAA.py @@ -62,9 +62,8 @@ class CAA(dns.rdata.Rdata): file.write(self.value) @classmethod - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None): - (flags, l) = struct.unpack('!BB', wire[current: current + 2]) - current += 2 - tag = wire[current: current + l] - value = wire[current + l:current + rdlen - 2] + def from_parser(cls, rdclass, rdtype, parser, origin=None): + flags = parser.get_uint8() + tag = parser.get_counted_bytes() + value = parser.get_remaining() return cls(rdclass, rdtype, flags, tag, value) diff --git a/dns/rdtypes/ANY/CSYNC.py b/dns/rdtypes/ANY/CSYNC.py index 66f2f31..8d546d5 100644 --- a/dns/rdtypes/ANY/CSYNC.py +++ b/dns/rdtypes/ANY/CSYNC.py @@ -93,26 +93,14 @@ class CSYNC(dns.rdata.Rdata): file.write(bitmap) @classmethod - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None): - if rdlen < 6: - raise dns.exception.FormError("CSYNC too short") - (serial, flags) = struct.unpack("!IH", wire[current: current + 6]) - current += 6 - rdlen -= 6 + def from_parser(cls, rdclass, rdtype, parser, origin=None): + (serial, flags) = parser.get_struct("!IH") windows = [] - while rdlen > 0: - if rdlen < 3: - raise dns.exception.FormError("CSYNC too short") - window = wire[current] - octets = wire[current + 1] + while parser.remaining() > 0: + window = parser.get_uint8() + octets = parser.get_uint8() if octets == 0 or octets > 32: raise dns.exception.FormError("bad CSYNC octets") - current += 2 - rdlen -= 2 - if rdlen < octets: - raise dns.exception.FormError("bad CSYNC bitmap length") - bitmap = bytearray(wire[current: current + octets].unwrap()) - current += octets - rdlen -= octets + bitmap = parser.get_bytes(octets) windows.append((window, bitmap)) return cls(rdclass, rdtype, serial, flags, windows) diff --git a/dns/rdtypes/ANY/HINFO.py b/dns/rdtypes/ANY/HINFO.py index dc982f1..4a219e1 100644 --- a/dns/rdtypes/ANY/HINFO.py +++ b/dns/rdtypes/ANY/HINFO.py @@ -64,19 +64,7 @@ class HINFO(dns.rdata.Rdata): file.write(self.os) @classmethod - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None): - l = wire[current] - current += 1 - rdlen -= 1 - if l > rdlen: - raise dns.exception.FormError - cpu = wire[current:current + l].unwrap() - current += l - rdlen -= l - l = wire[current] - current += 1 - rdlen -= 1 - if l != rdlen: - raise dns.exception.FormError - os = wire[current: current + l].unwrap() + def from_parser(cls, rdclass, rdtype, parser, origin=None): + cpu = parser.get_counted_bytes() + os = parser.get_counted_bytes() return cls(rdclass, rdtype, cpu, os) diff --git a/dns/rdtypes/ANY/HIP.py b/dns/rdtypes/ANY/HIP.py index 51e42ac..73f515c 100644 --- a/dns/rdtypes/ANY/HIP.py +++ b/dns/rdtypes/ANY/HIP.py @@ -77,24 +77,12 @@ class HIP(dns.rdata.Rdata): server.to_wire(file, None, origin, False) @classmethod - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None): - (lh, algorithm, lk) = struct.unpack('!BBH', - wire[current: current + 4]) - current += 4 - rdlen -= 4 - hit = wire[current: current + lh].unwrap() - current += lh - rdlen -= lh - key = wire[current: current + lk].unwrap() - current += lk - rdlen -= lk + def from_parser(cls, rdclass, rdtype, parser, origin=None): + (lh, algorithm, lk) = parser.get_struct('!BBH') + hit = parser.get_bytes(lh) + key = parser.get_bytes(lk) servers = [] - while rdlen > 0: - (server, cused) = dns.name.from_wire(wire[: current + rdlen], - current) - current += cused - rdlen -= cused - if origin is not None: - server = server.relativize(origin) + while parser.remaining() > 0: + server = parser.get_name(origin) servers.append(server) return cls(rdclass, rdtype, hit, algorithm, key, servers) diff --git a/dns/rdtypes/ANY/X25.py b/dns/rdtypes/ANY/X25.py index ac61849..c43e6b8 100644 --- a/dns/rdtypes/ANY/X25.py +++ b/dns/rdtypes/ANY/X25.py @@ -54,11 +54,6 @@ class X25(dns.rdata.Rdata): file.write(self.address) @classmethod - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None): - l = wire[current] - current += 1 - rdlen -= 1 - if l != rdlen: - raise dns.exception.FormError - address = wire[current: current + l].unwrap() + def from_parser(cls, rdclass, rdtype, parser, origin=None): + address = parser.get_counted_bytes() return cls(rdclass, rdtype, address) diff --git a/dns/rdtypes/IN/NAPTR.py b/dns/rdtypes/IN/NAPTR.py index 747df4c..13911b3 100644 --- a/dns/rdtypes/IN/NAPTR.py +++ b/dns/rdtypes/IN/NAPTR.py @@ -89,8 +89,7 @@ class NAPTR(dns.rdata.Rdata): (order, preference) = parser.get_struct('!HH') strings = [] for i in range(3): - l = parser.get_uint8() - s = parser.get_bytes(l) + s = parser.get_counted_bytes() strings.append(s) replacement = parser.get_name(origin) return cls(rdclass, rdtype, order, preference, strings[0], strings[1], diff --git a/dns/rdtypes/txtbase.py b/dns/rdtypes/txtbase.py index 2f818d5..2a07b0b 100644 --- a/dns/rdtypes/txtbase.py +++ b/dns/rdtypes/txtbase.py @@ -87,7 +87,6 @@ class TXTBase(dns.rdata.Rdata): def from_parser(cls, rdclass, rdtype, parser, origin=None): strings = [] while parser.remaining() > 0: - l = parser.get_uint8() - s = parser.get_bytes(l) + s = parser.get_counted_bytes() strings.append(s) return cls(rdclass, rdtype, strings) |
