def is_golem_message_signed_with_key( public_key: bytes, golem_message: message.base.Message, ) -> bool: """ Validates if given Golem message is signed with given public key. :param golem_message: Instance of golem_messages.base.Message object. :param public_key: Client public key in bytes. :return: True if given Golem message is signed with given public key, otherwise False. """ assert isinstance(golem_message, message.base.Message) validate_bytes_public_key(public_key, 'public_key') try: is_valid = golem_message.verify_signature(public_key) except MessageError as exception: is_valid = False log_error_message( logger, f'There was an exception when validating if golem_message {golem_message.__class__.__name__} is signed ' f'with public key {public_key}, exception: {exception}.' ) return is_valid
def validate_golem_message_signed_with_key( golem_message: message.base.Message, public_key: bytes, ): assert isinstance(golem_message, message.base.Message) validate_bytes_public_key(public_key, 'public_key') try: golem_message.verify_signature(public_key) except MessageError as exception: error_message = join_messages( 'There was an exception when validating if golem_message {} is signed with public key {}.' .format( golem_message.TYPE, public_key, ), str(exception)) raise Http400( error_message, error_code=ErrorCode.MESSAGE_SIGNATURE_WRONG, )