def __validate_signature(self, data, saml_type, raise_exceptions=False):
try:<EOL><INDENT>signature = data.get('<STR_LIT>', None)<EOL>if signature is None:<EOL><INDENT>if self.__settings.is_strict() and self.__settings.get_security_data().get('<STR_LIT>', False):<EOL><INDENT>raise OneLogin_Saml2_ValidationError(<EOL>'<STR_LIT>' % saml_type,<EOL>OneLogin_Saml2_ValidationError.NO_SIGNED_MESSAGE<EOL>)<EOL><DEDENT>return True<EOL><DEDENT>idp_data = self.get_settings().get_idp_data()<EOL>exists_x509cert = '<STR_LIT>' in idp_data and idp_data['<STR_LIT>']<EOL>exists_multix509sign = '<STR_LIT>' in idp_data and'<STR_LIT>' in idp_data['<STR_LIT>'] andidp_data['<STR_LIT>']['<STR_LIT>']<EOL>if not (exists_x509cert or exists_multix509sign):<EOL><INDENT>error_msg = '<STR_LIT>' % saml_type<EOL>self.__errors.append(error_msg)<EOL>raise OneLogin_Saml2_Error(<EOL>error_msg,<EOL>OneLogin_Saml2_Error.CERT_NOT_FOUND<EOL>)<EOL><DEDENT>sign_alg = data.get('<STR_LIT>', OneLogin_Saml2_Constants.RSA_SHA1)<EOL>if isinstance(sign_alg, bytes):<EOL><INDENT>sign_alg = sign_alg.decode('<STR_LIT:utf8>')<EOL><DEDENT>lowercase_urlencoding = False<EOL>if '<STR_LIT>' in self.__request_data.keys():<EOL><INDENT>lowercase_urlencoding = self.__request_data['<STR_LIT>']<EOL><DEDENT>signed_query = self.__build_sign_query(data[saml_type],<EOL>data.get('<STR_LIT>', None),<EOL>sign_alg,<EOL>saml_type,<EOL>lowercase_urlencoding<EOL>)<EOL>if exists_multix509sign:<EOL><INDENT>for cert in idp_data['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>if OneLogin_Saml2_Utils.validate_binary_sign(signed_query,<EOL>OneLogin_Saml2_Utils.b64decode(signature),<EOL>cert,<EOL>sign_alg):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>raise OneLogin_Saml2_ValidationError(<EOL>'<STR_LIT>' % saml_type,<EOL>OneLogin_Saml2_ValidationError.INVALID_SIGNATURE<EOL>)<EOL><DEDENT>else:<EOL><INDENT>cert = idp_data['<STR_LIT>']<EOL>if not OneLogin_Saml2_Utils.validate_binary_sign(signed_query,<EOL>OneLogin_Saml2_Utils.b64decode(signature),<EOL>cert,<EOL>sign_alg,<EOL>self.__settings.is_debug_active()):<EOL><INDENT>raise OneLogin_Saml2_ValidationError(<EOL>'<STR_LIT>' % saml_type,<EOL>OneLogin_Saml2_ValidationError.INVALID_SIGNATURE<EOL>)<EOL><DEDENT><DEDENT>return True<EOL><DEDENT>except Exception as e:<EOL><INDENT>self.__error_reason = str(e)<EOL>if raise_exceptions:<EOL><INDENT>raise e<EOL><DEDENT>return False<EOL><DEDENT>
Validate Signature

:param data: The Request data
:type data: dict

:param cert: The certificate to check signature
:type cert: str

:param saml_type: The target URL the user should be redirected to
:type saml_type: string  SAMLRequest | SAMLResponse

:param raise_exceptions: Whether to return false on failure or raise an exception
:type raise_exceptions: Boolean