def load_privatekey(type, buffer, passphrase=None):
if isinstance(buffer, _text_type):<EOL><INDENT>buffer = buffer.encode("<STR_LIT:ascii>")<EOL><DEDENT>bio = _new_mem_buf(buffer)<EOL>helper = _PassphraseHelper(type, passphrase)<EOL>if type == FILETYPE_PEM:<EOL><INDENT>evp_pkey = _lib.PEM_read_bio_PrivateKey(<EOL>bio, _ffi.NULL, helper.callback, helper.callback_args)<EOL>helper.raise_if_problem()<EOL><DEDENT>elif type == FILETYPE_ASN1:<EOL><INDENT>evp_pkey = _lib.d2i_PrivateKey_bio(bio, _ffi.NULL)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if evp_pkey == _ffi.NULL:<EOL><INDENT>_raise_current_error()<EOL><DEDENT>pkey = PKey.__new__(PKey)<EOL>pkey._pkey = _ffi.gc(evp_pkey, _lib.EVP_PKEY_free)<EOL>return pkey<EOL>
Load a private key (PKey) from the string *buffer* encoded with the type
*type*.

:param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1)
:param buffer: The buffer the key is stored in
:param passphrase: (optional) if encrypted PEM format, this can be
                   either the passphrase to use, or a callback for
                   providing the passphrase.

:return: The PKey object