#NEWLINE# def _load_rsa_private_key( pem ) : #NEWLINE# #INDENT# 'PEM encoded PKCS#8 private key -> rsa.PrivateKey.' #NEWLINE# try : #NEWLINE# #INDENT# der = rsa . pem . load_pem ( pem , 'PRIVATE KEY' ) #NEWLINE# ( keyinfo , _ ) = decoder . decode ( der ) #NEWLINE# if ( keyinfo [ 1 ] [ 0 ] != univ . ObjectIdentifier ( '1.2.840.113549.1.1.1' ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Not a DER-encoded OpenSSL private RSA key' ) #NEWLINE# #UNINDENT# private_key_der = keyinfo [ 2 ] . asOctets ( ) #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# raise ValueError ( 'Not a DER-encoded OpenSSL private RSA key' ) #NEWLINE# #UNINDENT# return rsa . PrivateKey . load_pkcs1 ( private_key_der , format = 'DER' )