def _parse_iv(self, byte_array, off): length = len(byte_array) - off if length < self._iv_length: raise exceptions.ParseError('Not enough bytes to parse IV') self.iv = byte_array[off:off + self._iv_length] return self._iv_length
def _parse_encryption_context(self, byte_array, off): length = len(byte_array) - off if length < self._encryption_context_length: raise exceptions.ParseError( 'Not enough bytes to parse encryption context') self._encryption_context = _EncryptionContext() parsed_bytes = self._encryption_context.deserialize(byte_array, off) self.encryption_context = self._encryption_context.to_dict() if parsed_bytes != self._encryption_context_length: raise exceptions.ParseError( 'Did not properly parse encryption context') return self._encryption_context_length
def _parse_encrypted_data_key(self, byte_array, off): length = len(byte_array) - off if length < self._encrypted_data_key_length: raise exceptions.ParseError( 'Not enough bytes to parse encrypted data key') self.encrypted_data_key = byte_array[off:off + self._encrypted_data_key_length] return self._encrypted_data_key_length
def _parse_key_provider_info(self, byte_array, off): length = len(byte_array) - off if length < self._key_provider_info_length: raise exceptions.ParseError( 'Not enough bytes to parse key provider info') self.key_provider_info = byte_array[off:off + self._key_provider_info_length] return self._key_provider_info_length
def _parse_authentication_tag(self, byte_array, off): length = len(byte_array) - off if length < self._authentication_tag_length: raise exceptions.ParseError( 'Not enough bytes to parse authentication tag') self.authentication_tag = byte_array[off:off + self._authentication_tag_length] return self._authentication_tag_length
def deserialize(self, byte_array, off): """Loads information from ``byte_array`` into this object.""" parsed_bytes = 0 self.header = Header() parsed_bytes += self.header.deserialize(byte_array, off + parsed_bytes) if self.header.content_type == 2: self.body = FrameBody(header=self.header) parsed_bytes += self.body.deserialize(byte_array, off + parsed_bytes) else: raise NotImplementedError('Non-framed content not supported yet') if len(byte_array) - parsed_bytes > 0: self.footer = Footer() parsed_bytes += self.footer.deserialize(byte_array, off + parsed_bytes) if parsed_bytes != len(byte_array): raise exceptions.ParseError('Did not parse all the bytes') return parsed_bytes
def _parse_signature(self, byte_array, off): length = len(byte_array) - off if length < self._signature_length: raise exceptions.ParseError('Not enough bytes to parse signature') self.signature = byte_array[off:off + self._signature_length] return self._signature_length