Example #1
0
    def load_from(self, buffer: bytes, offset: int = 0, length: int = None) -> int:
        my_offset, option_len = self.parse_option_header(buffer, offset, length)
        header_offset = my_offset

        # Parse the domain labels
        max_offset = option_len + header_offset  # The option_len field counts bytes *after* the header fields
        domain_names_len, self.search_list = parse_domain_list_bytes(buffer,
                                                                     offset=offset + my_offset, length=option_len)
        my_offset += domain_names_len

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

        self.validate()

        return my_offset
Example #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, option_len = self.parse_option_header(buffer, offset, length)

        # Parse the domain labels
        parsed_len, self.domain_names = parse_domain_list_bytes(buffer, offset=offset + my_offset, length=option_len)
        my_offset += parsed_len

        return my_offset
Example #3
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)

        # Parse the domain labels
        parsed_len, self.domain_names = parse_domain_list_bytes(buffer, offset=offset + my_offset, length=option_len)
        my_offset += parsed_len

        self.validate()

        return my_offset
Example #4
0
    def load_from(self,
                  buffer: bytes,
                  offset: int = 0,
                  length: int = None) -> int:
        my_offset, option_len = self.parse_option_header(
            buffer, offset, length)
        header_offset = my_offset

        # Parse the domain labels
        max_offset = option_len + header_offset  # The option_len field counts bytes *after* the header fields
        domain_names_len, self.search_list = parse_domain_list_bytes(
            buffer, offset=offset + my_offset, length=option_len)
        my_offset += domain_names_len

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

        self.validate()

        return my_offset
Example #5
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)
        header_offset = my_offset

        # Parse the domain labels
        max_offset = option_len + header_offset  # The option_len field counts bytes *after* the header fields
        parsed_len, self.domain_names = parse_domain_list_bytes(buffer, offset=offset + my_offset, length=option_len)
        my_offset += parsed_len

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

        self.validate()

        return my_offset
Example #6
0
 def test_parse_good(self):
     offset, domain_names = parse_domain_list_bytes(self.good_domains_bytes)
     self.assertEqual(offset, len(self.good_domains_bytes))
     self.assertListEqual(domain_names, self.good_domains_list)
Example #7
0
 def test_parse_good(self):
     offset, domain_names = parse_domain_list_bytes(self.good_domains_bytes)
     self.assertEqual(offset, len(self.good_domains_bytes))
     self.assertListEqual(domain_names, self.good_domains_list)