Пример #1
0
    def _parse_frame_content_length(self, byte_array, off):
        self.frame_content_length = utils.bytes_to_int(byte_array[off:off + 4])

        if self.frame_content_length < 0:
            raise exceptions.BadCipherTextError(
                'Invalid frame length ({})'.format(self.frame_content_length))

        return 4
Пример #2
0
    def _parse_type(self, byte_array, off):
        self.type = utils.bytes_to_int(byte_array[off])

        if self.type != 0x80:
            raise exceptions.BadCipherTextError(
                'Invalid message type ({})'.format(self.type))

        return 1
Пример #3
0
    def _parse_iv_length(self, byte_array, off):
        self._iv_length = utils.bytes_to_int(byte_array[off])

        if self._iv_length < 0:
            raise exceptions.BadCipherTextError(
                'Invalid IV length ({})'.format(self._iv_length))

        return 1
Пример #4
0
    def _parse_content_type(self, byte_array, off):
        self.content_type = utils.bytes_to_int(byte_array[off])

        if self.content_type not in (1, 2):
            raise exceptions.BadCipherTextError(
                'Invalid content type ({})'.format(self.content_type))

        return 1
Пример #5
0
    def _parse_version(self, byte_array, off):
        self.version = utils.bytes_to_int(byte_array[off])

        if self.version != 1:
            raise exceptions.BadCipherTextError(
                'Invalid version number ({})'.format(self.version))

        return 1
Пример #6
0
    def _parse_reserved_field(self, byte_array, off):
        self.reserved_field = utils.bytes_to_int(byte_array[off:off + 4])

        if self.reserved_field != 0:
            raise exceptions.BadCipherTextError(
                'Invalid value for reserved field ({})'.format(
                    self.reserved_field))

        return 4
Пример #7
0
    def _parse_encryption_context_length(self, byte_array, off):
        self._encryption_context_length = utils.bytes_to_int(
            byte_array[off:off + 2])

        if self._encryption_context_length < 0:
            raise exceptions.BadCipherTextError(
                'Invalid encryption context length ({})'.format(
                    self._encryption_context_length))

        return 2
Пример #8
0
 def _parse_encrypted_data_key_length(self, byte_array, off):
     self._encrypted_data_key_length = utils.bytes_to_int(
         byte_array[off:off + 2])
     return 2
Пример #9
0
 def _parse_key_provider_info_length(self, byte_array, off):
     self._key_provider_info_length = utils.bytes_to_int(
         byte_array[off:off + 2])
     return 2
Пример #10
0
 def _parse_value_length(self, byte_array, off):
     self._value_length = utils.bytes_to_int(byte_array[off:off + 2])
     return 2
Пример #11
0
 def _parse_key_value_pair_count(self, byte_array, off):
     self._key_value_pair_count = utils.bytes_to_int(byte_array[off:off +
                                                                2])
     return 2
Пример #12
0
 def _parse_algorithm_id(self, byte_array, off):
     self.algorithm_id = utils.bytes_to_int(byte_array[off:off + 2])
     return 2
Пример #13
0
 def _parse_sequence_number(self, byte_array, off):
     self.sequence_number = utils.bytes_to_int(byte_array[off:off + 4])
     return 4
Пример #14
0
def test_bytes_to_int(byte_string, expected_int):
    result = utils.bytes_to_int(byte_string)

    assert result == expected_int