@staticmethod<EOL><INDENT>def add_x509_key_descriptors(metadata, cert=None, add_encryption=True):<DEDENT>
if cert is None or cert == '<STR_LIT>':<EOL><INDENT>return metadata<EOL><DEDENT>try:<EOL><INDENT>root = OneLogin_Saml2_XML.to_etree(metadata)<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise Exception('<STR_LIT>' + str(e))<EOL><DEDENT>assert root.tag == '<STR_LIT>' % OneLogin_Saml2_Constants.NS_MD<EOL>try:<EOL><INDENT>sp_sso_descriptor = next(root.iterfind('<STR_LIT>', namespaces=OneLogin_Saml2_Constants.NSMAP))<EOL><DEDENT>except StopIteration:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>if add_encryption:<EOL><INDENT>OneLogin_Saml2_Metadata.__add_x509_key_descriptors(sp_sso_descriptor, cert, False)<EOL><DEDENT>OneLogin_Saml2_Metadata.__add_x509_key_descriptors(sp_sso_descriptor, cert, True)<EOL>return OneLogin_Saml2_XML.to_string(root)<EOL>
Adds the x509 descriptors (sign/encryption) to the metadata
The same cert will be used for sign/encrypt

:param metadata: SAML Metadata XML
:type metadata: string

:param cert: x509 cert
:type cert: string

:param add_encryption: Determines if the KeyDescriptor[use="encryption"] should be added.
:type add_encryption: boolean

:returns: Metadata with KeyDescriptors
:rtype: string