<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def exportpriv(self, format="PEM", password=None, cipher=None):
 """ Returns private key as PEM or DER Structure. If password and cipher are specified, encrypts key on given password, using given algorithm. Cipher must be an ctypescrypto.cipher.CipherType object Password can be either string or function with one argument, which returns password. It is called with argument True, which means, that we are encrypting key, and password should be verified (requested twice from user, for example). """

        bio = Membio()
        if cipher is None:
            evp_cipher = None
        else:
            evp_cipher = cipher.cipher
        if format == "PEM":
            ret = libcrypto.PEM_write_bio_PrivateKey(bio.bio, self.key,
                                         evp_cipher, None, 0,
                                         _password_callback(password),
                                         None)
            if ret ==0:
                raise PKeyError("error serializing private key")
            return str(bio)
        else:
            ret = libcrypto.i2d_PKCS8PrivateKey_bio(bio.bio, self.key,
                                               evp_cipher, None, 0,
                                              _password_callback(password),
                                               None)
            if ret ==0:
                raise PKeyError("error serializing private key")
            return bintype(bio)