def dump_private_key(private_key, passphrase, encoding='<STR_LIT>', target_ms=<NUM_LIT:200>):
if encoding not in set(['<STR_LIT>', '<STR_LIT>']):<EOL><INDENT>raise ValueError(pretty_message(<EOL>'''<STR_LIT>''',<EOL>repr(encoding)<EOL>))<EOL><DEDENT>if passphrase is not None:<EOL><INDENT>if not isinstance(passphrase, str_cls):<EOL><INDENT>raise TypeError(pretty_message(<EOL>'''<STR_LIT>''',<EOL>type_name(passphrase)<EOL>))<EOL><DEDENT>if passphrase == '<STR_LIT>':<EOL><INDENT>raise ValueError(pretty_message(<EOL>'''<STR_LIT>'''<EOL>))<EOL><DEDENT><DEDENT>is_oscrypto = isinstance(private_key, PrivateKey)<EOL>if not isinstance(private_key, keys.PrivateKeyInfo) and not is_oscrypto:<EOL><INDENT>raise TypeError(pretty_message(<EOL>'''<STR_LIT>''',<EOL>type_name(private_key)<EOL>))<EOL><DEDENT>if is_oscrypto:<EOL><INDENT>private_key = private_key.asn1<EOL><DEDENT>output = private_key.dump()<EOL>if passphrase is not None:<EOL><INDENT>cipher = '<STR_LIT>'<EOL>key_length = <NUM_LIT:32><EOL>kdf_hmac = '<STR_LIT>'<EOL>kdf_salt = rand_bytes(key_length)<EOL>iterations = pbkdf2_iteration_calculator(kdf_hmac, key_length, target_ms=target_ms, quiet=True)<EOL>if iterations < <NUM_LIT>:<EOL><INDENT>iterations = <NUM_LIT><EOL><DEDENT>passphrase_bytes = passphrase.encode('<STR_LIT:utf-8>')<EOL>key = pbkdf2(kdf_hmac, passphrase_bytes, kdf_salt, iterations, key_length)<EOL>iv, ciphertext = aes_cbc_pkcs7_encrypt(key, output, None)<EOL>output = keys.EncryptedPrivateKeyInfo({<EOL>'<STR_LIT>': {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': {<EOL>'<STR_LIT>': {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': {<EOL>'<STR_LIT>': algos.Pbkdf2Salt(<EOL>name='<STR_LIT>',<EOL>value=kdf_salt<EOL>),<EOL>'<STR_LIT>': iterations,<EOL>'<STR_LIT>': {<EOL>'<STR_LIT>': kdf_hmac,<EOL>'<STR_LIT>': core.Null()<EOL>}<EOL>}<EOL>},<EOL>'<STR_LIT>': {<EOL>'<STR_LIT>': cipher,<EOL>'<STR_LIT>': iv<EOL>}<EOL>}<EOL>},<EOL>'<STR_LIT>': ciphertext<EOL>}).dump()<EOL><DEDENT>if encoding == '<STR_LIT>':<EOL><INDENT>if passphrase is None:<EOL><INDENT>object_type = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>object_type = '<STR_LIT>'<EOL><DEDENT>output = pem.armor(object_type, output)<EOL><DEDENT>return output<EOL>
Serializes a private key object into a byte string of the PKCS#8 format

:param private_key:
    An oscrypto.asymmetric.PrivateKey or asn1crypto.keys.PrivateKeyInfo
    object

:param passphrase:
    A unicode string of the passphrase to encrypt the private key with.
    A passphrase of None will result in no encryption. A blank string will
    result in a ValueError to help ensure that the lack of passphrase is
    intentional.

:param encoding:
    A unicode string of "pem" or "der"

:param target_ms:
    Use PBKDF2 with the number of iterations that takes about this many
    milliseconds on the current machine.

:raises:
    ValueError - when a blank string is provided for the passphrase

:return:
    A byte string of the encoded and encrypted public key