def validate_key_csr(privkey, csr=None):
 if (privkey.pem and (not crypto_util.valid_privkey(privkey.pem))):
  raise errors.Error('The provided key is not a valid key')
 if csr:
  if (csr.form == 'der'):
   csr_obj = OpenSSL.crypto.load_certificate_request(OpenSSL.crypto.FILETYPE_ASN1, csr.data)
   csr = util.CSR(csr.file, OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, csr_obj), 'pem')
  if (csr.data and (not crypto_util.valid_csr(csr.data))):
   raise errors.Error('The provided CSR is not a valid CSR')
  if (csr.data and privkey.pem):
   if (not crypto_util.csr_matches_pubkey(csr.data, privkey.pem)):
    raise errors.Error('The key and CSR do not match')

def validate_key_csr ( privkey , csr = None ) : if ( privkey . pem and ( not crypto_util . valid_privkey ( privkey . pem ) ) ) : raise errors . Error ( 'The provided key is not a valid key' ) if csr : if ( csr . form == 'der' ) : csr_obj = OpenSSL . crypto . load_certificate_request ( OpenSSL . crypto . FILETYPE_ASN1 , csr . data ) csr = util . CSR ( csr . file , OpenSSL . crypto . dump_certificate ( OpenSSL . crypto . FILETYPE_PEM , csr_obj ) , 'pem' ) if ( csr . data and ( not crypto_util . valid_csr ( csr . data ) ) ) : raise errors . Error ( 'The provided CSR is not a valid CSR' ) if ( csr . data and privkey . pem ) : if ( not crypto_util . csr_matches_pubkey ( csr . data , privkey . pem ) ) : raise errors . Error ( 'The key and CSR do not match' )
validate key and csr files .