

def certificateOptionsFromPEMs(pemObjects, **kw):
    '\n    Load a CertificateOptions from the given collection of PEM objects\n    (already-loaded private keys and certificates).\n\n    In those PEM objects, identify one private key and its corresponding\n    certificate to use as the primary certificate.  Then use the rest of the\n    certificates found as chain certificates.  Raise a ValueError if no\n    certificate matching a private key is found.\n\n    :return: A TLS context factory using *pemObjects*\n    :rtype: `twisted.internet.ssl.CertificateOptions`_\n\n    .. _`twisted.internet.ssl.CertificateOptions`:         https://twistedmatrix.com/documents/current/api/        twisted.internet.ssl.CertificateOptions.html\n    '
    keys = [key for key in pemObjects if isinstance(key, Key)]
    if (not len(keys)):
        raise ValueError('Supplied PEM file(s) does *not* contain a key.')
    if (len(keys) > 1):
        raise ValueError('Supplied PEM file(s) contains *more* than one key.')
    privateKey = ssl.KeyPair.load(str(keys[0]), FILETYPE_PEM)
    certs = [cert for cert in pemObjects if isinstance(cert, Certificate)]
    if (not len(certs)):
        raise ValueError('*At least one* certificate is required.')
    certificates = [ssl.Certificate.loadPEM(str(certPEM)) for certPEM in certs]
    certificatesByFingerprint = dict([(certificate.getPublicKey().keyHash(), certificate) for certificate in certificates])
    if (privateKey.keyHash() not in certificatesByFingerprint):
        raise ValueError('No certificate matching {fingerprint} found.'.format(fingerprint=privateKey.keyHash()))
    primaryCertificate = certificatesByFingerprint.pop(privateKey.keyHash())
    if ('dhParameters' in kw):
        warnings.warn('Passing DH parameters as a keyword argument instead of a PEM object is deprecated as of pem 16.1.0.', DeprecationWarning)
    else:
        dhparams = [o for o in pemObjects if isinstance(o, DHParameters)]
        if (len(dhparams) > 1):
            raise ValueError('Supplied PEM file(s) contain(s) *more* than one set of DH parameters.')
        elif (len(dhparams) == 1):
            kw['dhParameters'] = DiffieHellmanParameters(str(dhparams[0]))
    fakeEDHSupport = (('dhParameters' in kw) and (not _DH_PARAMETERS_SUPPORTED))
    if fakeEDHSupport:
        dhParameters = kw.pop('dhParameters')
    if (_DH_PARAMETERS_SUPPORTED is False):
        warnings.warn('Using pem with Twisted older than 14.0.0 is deprecated as of pem 15.0.0.  The backport of DiffieHellmanParameters will be removed.', DeprecationWarning)
    ctxFactory = ssl.CertificateOptions(privateKey=privateKey.original, certificate=primaryCertificate.original, extraCertChain=[chain.original for chain in certificatesByFingerprint.values()], **kw)
    if fakeEDHSupport:
        return _DHParamContextFactory(ctxFactory, dhParameters)
    else:
        return ctxFactory

dataset/ETHPy150Open hynek/pem/src/pem/twisted.py certificateOptionsFromPEMs/original