def load_pkcs12(source, password=None):
if password is not None:<EOL><INDENT>if isinstance(password, str_cls):<EOL><INDENT>password = password.encode('<STR_LIT:utf-8>')<EOL><DEDENT>if not isinstance(password, byte_cls):<EOL><INDENT>raise TypeError(pretty_message(<EOL>'''<STR_LIT>''',<EOL>type_name(password)<EOL>))<EOL><DEDENT><DEDENT>if isinstance(source, str_cls):<EOL><INDENT>with open(source, '<STR_LIT:rb>') as f:<EOL><INDENT>source = f.read()<EOL><DEDENT><DEDENT>elif not isinstance(source, byte_cls):<EOL><INDENT>raise TypeError(pretty_message(<EOL>'''<STR_LIT>''',<EOL>type_name(source)<EOL>))<EOL><DEDENT>key_info, cert_info, extra_certs_info = parse_pkcs12(source, password)<EOL>key = None<EOL>cert = None<EOL>if key_info:<EOL><INDENT>key = _load_key(key_info)<EOL><DEDENT>if cert_info:<EOL><INDENT>cert = _load_x509(cert_info)<EOL><DEDENT>extra_certs = [_load_x509(info) for info in extra_certs_info]<EOL>return (key, cert, extra_certs)<EOL>
Loads a .p12 or .pfx file into a PrivateKey object and one or more
Certificates objects

:param source:
    A byte string of file contents or a unicode string filename

:param password:
    A byte or unicode string to decrypt the PKCS12 file. Unicode strings
    will be encoded using UTF-8.

:raises:
    ValueError - when any of the parameters contain an invalid value
    TypeError - when any of the parameters are of the wrong type
    oscrypto.errors.AsymmetricKeyError - when a contained key is incompatible with the OS crypto library
    OSError - when an error is returned by the OS crypto library

:return:
    A three-element tuple containing (PrivateKey, Certificate, [Certificate, ...])