#NEWLINE# def parsePEMKey( s , private = False , public = False , passwordCallback = None , implementations = [ 'openssl' , 'python' ] ) : #NEWLINE# #INDENT# 'Parse a PEM-format key.\n\n    The PEM format is used by OpenSSL and other tools.  The\n    format is typically used to store both the public and private\n    components of a key.  For example::\n\n       -----BEGIN RSA PRIVATE KEY-----\n        MIICXQIBAAKBgQDYscuoMzsGmW0pAYsmyHltxB2TdwHS0dImfjCMfaSDkfLdZY5+\n        dOWORVns9etWnr194mSGA1F0Pls/VJW8+cX9+3vtJV8zSdANPYUoQf0TP7VlJxkH\n        dSRkUbEoz5bAAs/+970uos7n7iXQIni+3erUTdYEk2iWnMBjTljfgbK/dQIDAQAB\n        AoGAJHoJZk75aKr7DSQNYIHuruOMdv5ZeDuJvKERWxTrVJqE32/xBKh42/IgqRrc\n        esBN9ZregRCd7YtxoL+EVUNWaJNVx2mNmezEznrc9zhcYUrgeaVdFO2yBF1889zO\n        gCOVwrO8uDgeyj6IKa25H6c1N13ih/o7ZzEgWbGG+ylU1yECQQDv4ZSJ4EjSh/Fl\n        aHdz3wbBa/HKGTjC8iRy476Cyg2Fm8MZUe9Yy3udOrb5ZnS2MTpIXt5AF3h2TfYV\n        VoFXIorjAkEA50FcJmzT8sNMrPaV8vn+9W2Lu4U7C+K/O2g1iXMaZms5PC5zV5aV\n        CKXZWUX1fq2RaOzlbQrpgiolhXpeh8FjxwJBAOFHzSQfSsTNfttp3KUpU0LbiVvv\n        i+spVSnA0O4rq79KpVNmK44Mq67hsW1P11QzrzTAQ6GVaUBRv0YS061td1kCQHnP\n        wtN2tboFR6lABkJDjxoGRvlSt4SOPr7zKGgrWjeiuTZLHXSAnCY+/hr5L9Q3ZwXG\n        6x6iBdgLjVIe4BZQNtcCQQDXGv/gWinCNTN3MPWfTW/RGzuMYVmyBFais0/VrgdH\n        h1dLpztmpQqfyH/zrBXQ9qL/zR4ojS6XYneO/U18WpEe\n        -----END RSA PRIVATE KEY-----\n\n    To generate a key like this with OpenSSL, run::\n\n        openssl genrsa 2048 > key.pem\n\n    This format also supports password-encrypted private keys.  TLS\n    Lite can only handle password-encrypted private keys when OpenSSL\n    and M2Crypto are installed.  In this case, passwordCallback will be\n    invoked to query the user for the password.\n\n    @type s: str\n    @param s: A string containing a PEM-encoded public or private key.\n\n    @type private: bool\n    @param private: If True, a L{SyntaxError} will be raised if the\n    private key component is not present.\n\n    @type public: bool\n    @param public: If True, the private key component (if present) will\n    be discarded, so this function will always return a public key.\n\n    @type passwordCallback: callable\n    @param passwordCallback: This function will be called, with no\n    arguments, if the PEM-encoded private key is password-encrypted.\n    The callback should return the password string.  If the password is\n    incorrect, SyntaxError will be raised.  If no callback is passed\n    and the key is password-encrypted, a prompt will be displayed at\n    the console.\n\n    @rtype: L{tlslite.utils.RSAKey.RSAKey}\n    @return: An RSA key.\n\n    @raise SyntaxError: If the key is not properly formatted.\n    ' #NEWLINE# for implementation in implementations : #NEWLINE# #INDENT# if ( ( implementation == 'openssl' ) and cryptomath . m2cryptoLoaded ) : #NEWLINE# #INDENT# key = OpenSSL_RSAKey . parse ( s , passwordCallback ) #NEWLINE# break #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( implementation == 'python' ) : #NEWLINE# #INDENT# key = Python_RSAKey . parsePEM ( passwordCallback ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( 'No acceptable implementations' ) #NEWLINE# #UNINDENT# return _parseKeyHelper ( key , private , public )