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
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
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
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
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
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
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
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
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
def _parse_value_length(self, byte_array, off): self._value_length = utils.bytes_to_int(byte_array[off:off + 2]) return 2
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
def _parse_algorithm_id(self, byte_array, off): self.algorithm_id = utils.bytes_to_int(byte_array[off:off + 2]) return 2
def _parse_sequence_number(self, byte_array, off): self.sequence_number = utils.bytes_to_int(byte_array[off:off + 4]) return 4
def test_bytes_to_int(byte_string, expected_int): result = utils.bytes_to_int(byte_string) assert result == expected_int