def PEM_cert_to_DER_cert(pem_cert_string):
 if (not pem_cert_string.startswith(PEM_HEADER)):
  raise ValueError(('Invalid PEM encoding; must start with %s' % PEM_HEADER))
 if (not pem_cert_string.strip().endswith(PEM_FOOTER)):
  raise ValueError(('Invalid PEM encoding; must end with %s' % PEM_FOOTER))
 d = pem_cert_string.strip()[len(PEM_HEADER):(- len(PEM_FOOTER))]
 return base64.decodestring(d)

def PEM_cert_to_DER_cert ( pem_cert_string ) : if ( not pem_cert_string . startswith ( PEM_HEADER ) ) : raise ValueError ( ( 'Invalid PEM encoding; must start with %s' % PEM_HEADER ) ) if ( not pem_cert_string . strip ( ) . endswith ( PEM_FOOTER ) ) : raise ValueError ( ( 'Invalid PEM encoding; must end with %s' % PEM_FOOTER ) ) d = pem_cert_string . strip ( ) [ len ( PEM_HEADER ) : ( - len ( PEM_FOOTER ) ) ] return base64 . decodestring ( d )
takes a certificate in ascii pem format and returns the der-encoded version of it as a byte sequence .