def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None): if rdlen < 3: raise exception.FormError header = struct.unpack('!BBB', wire[current:current + 3]) gateway_type = header[1] current += 3 rdlen -= 3 if gateway_type == 0: gateway = None elif gateway_type == 1: gateway = inet.inet_ntop(inet.AF_INET, wire[current:current + 4]) current += 4 rdlen -= 4 elif gateway_type == 2: gateway = inet.inet_ntop(inet.AF_INET6, wire[current:current + 16]) current += 16 rdlen -= 16 elif gateway_type == 3: (gateway, cused) = name.from_wire(wire[:current + rdlen], current) current += cused rdlen -= cused else: raise exception.FormError('invalid IPSECKEY gateway type') key = wire[current:current + rdlen].unwrap() return cls(rdclass, rdtype, header[0], gateway_type, header[2], gateway, key)
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None): if rdlen < 3: raise exception.FormError header = struct.unpack("!BBB", wire[current : current + 3]) gateway_type = header[1] current += 3 rdlen -= 3 if gateway_type == 0: gateway = None elif gateway_type == 1: gateway = inet.inet_ntop(inet.AF_INET, wire[current : current + 4]) current += 4 rdlen -= 4 elif gateway_type == 2: gateway = inet.inet_ntop(inet.AF_INET6, wire[current : current + 16]) current += 16 rdlen -= 16 elif gateway_type == 3: (gateway, cused) = name.from_wire(wire[: current + rdlen], current) current += cused rdlen -= cused else: raise exception.FormError("invalid IPSECKEY gateway type") key = wire[current : current + rdlen].unwrap() return cls(rdclass, rdtype, header[0], gateway_type, header[2], gateway, key)
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None): items = [] while 1: if rdlen == 0: break if rdlen < 4: raise exception.FormError header = struct.unpack('!HBB', wire[current:current + 4]) afdlen = header[2] if afdlen > 127: negation = True afdlen -= 128 else: negation = False current += 4 rdlen -= 4 if rdlen < afdlen: raise exception.FormError address = wire[current:current + afdlen].unwrap() l = len(address) if header[0] == 1: if l < 4: address += '\x00' * (4 - l) address = inet.inet_ntop(inet.AF_INET, address) elif header[0] == 2: if l < 16: address += '\x00' * (16 - l) address = inet.inet_ntop(inet.AF_INET6, address) else: # # This isn't really right according to the RFC, but it # seems better than throwing an exception # address = address.encode('hex_codec') current += afdlen rdlen -= afdlen item = APLItem(header[0], negation, address, header[1]) items.append(item) return cls(rdclass, rdtype, items)
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): items = [] while 1: if rdlen == 0: break if rdlen < 4: raise exception.FormError header = struct.unpack('!HBB', wire[current : current + 4]) afdlen = header[2] if afdlen > 127: negation = True afdlen -= 128 else: negation = False current += 4 rdlen -= 4 if rdlen < afdlen: raise exception.FormError address = wire[current : current + afdlen].unwrap() l = len(address) if header[0] == 1: if l < 4: address += '\x00' * (4 - l) address = inet.inet_ntop(inet.AF_INET, address) elif header[0] == 2: if l < 16: address += '\x00' * (16 - l) address = inet.inet_ntop(inet.AF_INET6, address) else: # # This isn't really right according to the RFC, but it # seems better than throwing an exception # address = address.encode('hex_codec') current += afdlen rdlen -= afdlen item = APLItem(header[0], negation, address, header[1]) items.append(item) return cls(rdclass, rdtype, items)
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None): address = inet.inet_ntop(inet.AF_INET6, wire[current:current + rdlen]) return cls(rdclass, rdtype, address)
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): address = inet.inet_ntop(inet.AF_INET6, wire[current : current + rdlen]) return cls(rdclass, rdtype, address)