예제 #1
0
    def load_from(self,
                  buffer: bytes,
                  offset: int = 0,
                  length: int = None) -> int:
        """
        Load the internal state of this object from the given buffer. The buffer may contain more data after the
        structured element is parsed. This data is ignored.

        :param buffer: The buffer to read data from
        :param offset: The offset in the buffer where to start reading
        :param length: The amount of data we are allowed to read from the buffer
        :return: The number of bytes used from the buffer
        """
        my_offset, option_len = self.parse_option_header(buffer,
                                                         offset,
                                                         length,
                                                         min_length=4)
        header_offset = my_offset

        # Parse the domain label
        max_offset = option_len + header_offset  # The option_len field counts bytes *after* the header fields
        name_len, self.fqdn = parse_domain_bytes(buffer,
                                                 offset=offset + my_offset,
                                                 length=option_len)
        my_offset += name_len

        if my_offset != max_offset:
            raise ValueError(
                'Option length does not match the length of the included fqdn')

        return my_offset
예제 #2
0
    def load_from(self, buffer: bytes, offset: int = 0, length: int = None) -> int:
        """
        Load the internal state of this object from the given buffer. The buffer may contain more data after the
        structured element is parsed. This data is ignored.

        :param buffer: The buffer to read data from
        :param offset: The offset in the buffer where to start reading
        :param length: The amount of data we are allowed to read from the buffer
        :return: The number of bytes used from the buffer
        """
        my_offset, suboption_len = self.parse_suboption_header(buffer, offset, length)
        header_offset = my_offset

        # Parse the domain labels
        max_offset = suboption_len + header_offset  # The option_len field counts bytes *after* the header fields
        domain_name_len, self.fqdn = parse_domain_bytes(buffer, offset=offset + my_offset, length=suboption_len)
        my_offset += domain_name_len

        if my_offset != max_offset:
            raise ValueError('Option length does not match the length of the included fqdn')

        return my_offset
예제 #3
0
 def test_parse_idn(self):
     offset, domain_name = parse_domain_bytes(self.idn_domain_bytes)
     self.assertEqual(offset, len(self.idn_domain_bytes))
     self.assertEqual(domain_name, self.idn_domain_name)
예제 #4
0
 def test_parse_relative(self):
     offset, domain_name = parse_domain_bytes(self.good_relative_domain_bytes, allow_relative=True)
     self.assertEqual(offset, len(self.good_relative_domain_bytes))
     self.assertEqual(domain_name, self.good_relative_domain_name)
예제 #5
0
 def test_parse_relative(self):
     offset, domain_name = parse_domain_bytes(self.good_relative_domain_bytes, allow_relative=True)
     self.assertEqual(offset, len(self.good_relative_domain_bytes))
     self.assertEqual(domain_name, self.good_domain_name)
예제 #6
0
 def test_parse_good(self):
     offset, domain_name = parse_domain_bytes(self.good_domain_bytes)
     self.assertEqual(offset, len(self.good_domain_bytes))
     self.assertEqual(domain_name, self.good_domain_name)