@staticmethod<EOL><INDENT>@return_false_on_exception<EOL>def validate_sign(xml, cert=None, fingerprint=None, fingerprintalg='<STR_LIT>', validatecert=False, debug=False, xpath=None, multicerts=None):<DEDENT>
if xml is None or xml == '<STR_LIT>':<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>elif isinstance(xml, etree._Element):<EOL><INDENT>elem = xml<EOL><DEDENT>elif isinstance(xml, Document):<EOL><INDENT>xml = xml.toxml()<EOL>elem = fromstring(str(xml), forbid_dtd=True)<EOL><DEDENT>elif isinstance(xml, Element):<EOL><INDENT>xml.setAttributeNS(<EOL>unicode(OneLogin_Saml2_Constants.NS_SAMLP),<EOL>'<STR_LIT>',<EOL>unicode(OneLogin_Saml2_Constants.NS_SAMLP)<EOL>)<EOL>xml.setAttributeNS(<EOL>unicode(OneLogin_Saml2_Constants.NS_SAML),<EOL>'<STR_LIT>',<EOL>unicode(OneLogin_Saml2_Constants.NS_SAML)<EOL>)<EOL>xml = xml.toxml()<EOL>elem = fromstring(str(xml), forbid_dtd=True)<EOL><DEDENT>elif isinstance(xml, basestring):<EOL><INDENT>elem = fromstring(str(xml), forbid_dtd=True)<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>error_callback_method = None<EOL>if debug:<EOL><INDENT>error_callback_method = print_xmlsec_errors<EOL><DEDENT>xmlsec.set_error_callback(error_callback_method)<EOL>xmlsec.addIDs(elem, ["<STR_LIT>"])<EOL>if xpath:<EOL><INDENT>signature_nodes = OneLogin_Saml2_Utils.query(elem, xpath)<EOL><DEDENT>else:<EOL><INDENT>signature_nodes = OneLogin_Saml2_Utils.query(elem, OneLogin_Saml2_Utils.RESPONSE_SIGNATURE_XPATH)<EOL>if len(signature_nodes) == <NUM_LIT:0>:<EOL><INDENT>signature_nodes = OneLogin_Saml2_Utils.query(elem, OneLogin_Saml2_Utils.ASSERTION_SIGNATURE_XPATH)<EOL><DEDENT><DEDENT>if len(signature_nodes) == <NUM_LIT:1>:<EOL><INDENT>signature_node = signature_nodes[<NUM_LIT:0>]<EOL>if not multicerts:<EOL><INDENT>return OneLogin_Saml2_Utils.validate_node_sign(signature_node, elem, cert, fingerprint, fingerprintalg, validatecert, debug, raise_exceptions=True)<EOL><DEDENT>else:<EOL><INDENT>fingerprint = fingerprintalg = None<EOL>for cert in multicerts:<EOL><INDENT>if OneLogin_Saml2_Utils.validate_node_sign(signature_node, elem, cert, fingerprint, fingerprintalg, validatecert, False, raise_exceptions=False):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>raise OneLogin_Saml2_ValidationError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise OneLogin_Saml2_ValidationError('<STR_LIT>'.format(len(signature_nodes)), OneLogin_Saml2_ValidationError.WRONG_NUMBER_OF_SIGNATURES)<EOL><DEDENT>
Validates a signature (Message or Assertion).

:param xml: The element we should validate
:type: string | Document

:param cert: The pubic cert
:type: string

:param fingerprint: The fingerprint of the public cert
:type: string

:param fingerprintalg: The algorithm used to build the fingerprint
:type: string

:param validatecert: If true, will verify the signature and if the cert is valid.
:type: bool

:param debug: Activate the xmlsec debug
:type: bool

:param xpath: The xpath of the signed element
:type: string

:param multicerts: Multiple public certs
:type: list

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