def dump_privatekey(type, pkey, cipher=None, passphrase=None):
 bio = _new_mem_buf()
 if (cipher is not None):
  if (passphrase is None):
   raise TypeError('if a value is given for cipher one must also be given for passphrase')
  cipher_obj = _lib.EVP_get_cipherbyname(_byte_string(cipher))
  if (cipher_obj == _ffi.NULL):
   raise ValueError('Invalid cipher name')
 else:
  cipher_obj = _ffi.NULL
 helper = _PassphraseHelper(type, passphrase)
 if (type == FILETYPE_PEM):
  result_code = _lib.PEM_write_bio_PrivateKey(bio, pkey._pkey, cipher_obj, _ffi.NULL, 0, helper.callback, helper.callback_args)
  helper.raise_if_problem()
 elif (type == FILETYPE_ASN1):
  result_code = _lib.i2d_PrivateKey_bio(bio, pkey._pkey)
 elif (type == FILETYPE_TEXT):
  rsa = _lib.EVP_PKEY_get1_RSA(pkey._pkey)
  result_code = _lib.RSA_print(bio, rsa, 0)
 else:
  raise ValueError('type argument must be FILETYPE_PEM, FILETYPE_ASN1, or FILETYPE_TEXT')
 if (result_code == 0):
  _raise_current_error()
 return _bio_to_string(bio)

def dump_privatekey ( type , pkey , cipher = None , passphrase = None ) : bio = _new_mem_buf ( ) if ( cipher is not None ) : if ( passphrase is None ) : raise TypeError ( 'if a value is given for cipher one must also be given for passphrase' ) cipher_obj = _lib . EVP_get_cipherbyname ( _byte_string ( cipher ) ) if ( cipher_obj == _ffi . NULL ) : raise ValueError ( 'Invalid cipher name' ) else : cipher_obj = _ffi . NULL helper = _PassphraseHelper ( type , passphrase ) if ( type == FILETYPE_PEM ) : result_code = _lib . PEM_write_bio_PrivateKey ( bio , pkey . _pkey , cipher_obj , _ffi . NULL , 0 , helper . callback , helper . callback_args ) helper . raise_if_problem ( ) elif ( type == FILETYPE_ASN1 ) : result_code = _lib . i2d_PrivateKey_bio ( bio , pkey . _pkey ) elif ( type == FILETYPE_TEXT ) : rsa = _lib . EVP_PKEY_get1_RSA ( pkey . _pkey ) result_code = _lib . RSA_print ( bio , rsa , 0 ) else : raise ValueError ( 'type argument must be FILETYPE_PEM, FILETYPE_ASN1, or FILETYPE_TEXT' ) if ( result_code == 0 ) : _raise_current_error ( ) return _bio_to_string ( bio )
dump a private key to a buffer .