diff options
| author | Brian Wellington <bwelling@xbill.org> | 2020-07-02 12:34:24 -0700 |
|---|---|---|
| committer | Brian Wellington <bwelling@xbill.org> | 2020-07-02 12:34:24 -0700 |
| commit | 94534d127336fa5aef46728263c0a73b01744073 (patch) | |
| tree | 7a7f3734c71b856b0f447ac2df1a7a8be284e2bc | |
| parent | 4ae8722a516c63a2d85b7060b6f2c8b8e77eef31 (diff) | |
| download | dnspython-parser.tar.gz | |
port more typesparser
| -rw-r--r-- | dns/rdtypes/ANY/NSEC.py | 25 | ||||
| -rw-r--r-- | dns/rdtypes/ANY/NSEC3.py | 36 | ||||
| -rw-r--r-- | dns/rdtypes/ANY/RRSIG.py | 18 | ||||
| -rw-r--r-- | dns/rdtypes/ANY/SOA.py | 21 | ||||
| -rw-r--r-- | dns/rdtypes/ANY/TSIG.py | 33 |
5 files changed, 29 insertions, 104 deletions
diff --git a/dns/rdtypes/ANY/NSEC.py b/dns/rdtypes/ANY/NSEC.py index 0f79d94..3494c71 100644 --- a/dns/rdtypes/ANY/NSEC.py +++ b/dns/rdtypes/ANY/NSEC.py @@ -93,26 +93,13 @@ class NSEC(dns.rdata.Rdata): file.write(bitmap) @classmethod - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None): - (next, cused) = dns.name.from_wire(wire[: current + rdlen], current) - current += cused - rdlen -= cused + def from_parser(cls, rdclass, rdtype, parser, origin=None): + next = parser.get_name(origin) windows = [] - while rdlen > 0: - if rdlen < 3: - raise dns.exception.FormError("NSEC too short") - window = wire[current] - octets = wire[current + 1] - if octets == 0 or octets > 32: + while parser.remaining() > 0: + window = parser.get_uint8() + bitmap = parser.get_counted_bytes() + if len(bitmap) == 0 or len(bitmap) > 32: raise dns.exception.FormError("bad NSEC octets") - current += 2 - rdlen -= 2 - if rdlen < octets: - raise dns.exception.FormError("bad NSEC bitmap length") - bitmap = bytearray(wire[current: current + octets].unwrap()) - current += octets - rdlen -= octets windows.append((window, bitmap)) - if origin is not None: - next = next.relativize(origin) return cls(rdclass, rdtype, next, windows) diff --git a/dns/rdtypes/ANY/NSEC3.py b/dns/rdtypes/ANY/NSEC3.py index 208f9e8..ecfa722 100644 --- a/dns/rdtypes/ANY/NSEC3.py +++ b/dns/rdtypes/ANY/NSEC3.py @@ -138,36 +138,16 @@ class NSEC3(dns.rdata.Rdata): file.write(bitmap) @classmethod - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None): - (algorithm, flags, iterations, slen) = \ - struct.unpack('!BBHB', wire[current: current + 5]) - - current += 5 - rdlen -= 5 - salt = wire[current: current + slen].unwrap() - current += slen - rdlen -= slen - nlen = wire[current] - current += 1 - rdlen -= 1 - next = wire[current: current + nlen].unwrap() - current += nlen - rdlen -= nlen + def from_parser(cls, rdclass, rdtype, parser, origin=None): + (algorithm, flags, iterations) = parser.get_struct('!BBH') + salt = parser.get_counted_bytes() + next = parser.get_counted_bytes() windows = [] - while rdlen > 0: - if rdlen < 3: - raise dns.exception.FormError("NSEC3 too short") - window = wire[current] - octets = wire[current + 1] - if octets == 0 or octets > 32: + while parser.remaining() > 0: + window = parser.get_uint8() + bitmap = parser.get_counted_bytes() + if len(bitmap) == 0 or len(bitmap) > 32: raise dns.exception.FormError("bad NSEC3 octets") - current += 2 - rdlen -= 2 - if rdlen < octets: - raise dns.exception.FormError("bad NSEC3 bitmap length") - bitmap = bytearray(wire[current: current + octets].unwrap()) - current += octets - rdlen -= octets windows.append((window, bitmap)) return cls(rdclass, rdtype, algorithm, flags, iterations, salt, next, windows) diff --git a/dns/rdtypes/ANY/RRSIG.py b/dns/rdtypes/ANY/RRSIG.py index ddc6141..b698646 100644 --- a/dns/rdtypes/ANY/RRSIG.py +++ b/dns/rdtypes/ANY/RRSIG.py @@ -115,16 +115,8 @@ class RRSIG(dns.rdata.Rdata): file.write(self.signature) @classmethod - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None): - header = struct.unpack('!HBBIIIH', wire[current: current + 18]) - current += 18 - rdlen -= 18 - (signer, cused) = dns.name.from_wire(wire[: current + rdlen], current) - current += cused - rdlen -= cused - if origin is not None: - signer = signer.relativize(origin) - signature = wire[current: current + rdlen].unwrap() - return cls(rdclass, rdtype, header[0], header[1], header[2], - header[3], header[4], header[5], header[6], signer, - signature) + def from_parser(cls, rdclass, rdtype, parser, origin=None): + header = parser.get_struct('!HBBIIIH') + signer = parser.get_name(origin) + signature = parser.get_remaining() + return cls(rdclass, rdtype, *header, signer, signature) diff --git a/dns/rdtypes/ANY/SOA.py b/dns/rdtypes/ANY/SOA.py index cd59ec0..3bc47ca 100644 --- a/dns/rdtypes/ANY/SOA.py +++ b/dns/rdtypes/ANY/SOA.py @@ -71,20 +71,7 @@ class SOA(dns.rdata.Rdata): file.write(five_ints) @classmethod - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None): - (mname, cused) = dns.name.from_wire(wire[: current + rdlen], current) - current += cused - rdlen -= cused - (rname, cused) = dns.name.from_wire(wire[: current + rdlen], current) - current += cused - rdlen -= cused - if rdlen != 20: - raise dns.exception.FormError - five_ints = struct.unpack('!IIIII', - wire[current: current + rdlen]) - if origin is not None: - mname = mname.relativize(origin) - rname = rname.relativize(origin) - return cls(rdclass, rdtype, mname, rname, - five_ints[0], five_ints[1], five_ints[2], five_ints[3], - five_ints[4]) + def from_parser(cls, rdclass, rdtype, parser, origin=None): + mname = parser.get_name(origin) + rname = parser.get_name(origin) + return cls(rdclass, rdtype, mname, rname, *parser.get_struct('!IIIII')) diff --git a/dns/rdtypes/ANY/TSIG.py b/dns/rdtypes/ANY/TSIG.py index 002c2db..269c86c 100644 --- a/dns/rdtypes/ANY/TSIG.py +++ b/dns/rdtypes/ANY/TSIG.py @@ -80,33 +80,12 @@ class TSIG(dns.rdata.Rdata): file.write(self.other) @classmethod - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None): - (algorithm, cused) = dns.name.from_wire(wire[: current + rdlen], - current) - current += cused - rdlen -= cused - if rdlen < 10: - raise dns.exception.FormError - (time_hi, time_lo, fudge, mac_len) = \ - struct.unpack('!HIHH', wire[current: current + 10]) - current += 10 - rdlen -= 10 + def from_parser(cls, rdclass, rdtype, parser, origin=None): + algorithm = parser.get_name(origin) + (time_hi, time_lo, fudge) = parser.get_struct('!HIH') time_signed = (time_hi << 32) + time_lo - if rdlen < mac_len: - raise dns.exception.FormError - mac = wire[current: current + mac_len].unwrap() - current += mac_len - rdlen -= mac_len - if rdlen < 6: - raise dns.exception.FormError - (original_id, error, other_len) = \ - struct.unpack('!HHH', wire[current: current + 6]) - current += 6 - rdlen -= 6 - if rdlen < other_len: - raise dns.exception.FormError - other = wire[current: current + other_len].unwrap() - current += other_len - rdlen -= other_len + mac = parser.get_counted_bytes(2) + (original_id, error) = parser.get_struct('!HH') + other = parser.get_counted_bytes(2) return cls(rdclass, rdtype, algorithm, time_signed, fudge, mac, original_id, error, other) |
