U
    ˆjc  ã                	   @  sÌ   d Z ddlmZ ddlZddlZddlmZ ddlmZ	 ddl
mZmZmZmZ e e¡� ddlmZ dd	lmZ W 5 Q R X d
gZddddœdd
„Zddddœdd„Zdddœdd„Zdddœdd„ZdS )zA
`pyOpenSSL <https://github.com/pyca/pyopenssl>`_-specific code.
é    )ÚannotationsN)ÚSequenceé   )Úextract_patterns)ÚDNS_IDÚCertificatePatternÚIPAddress_IDÚverify_service_identity)ÚX509)Ú
ConnectionÚverify_hostnamer   ÚstrÚNone)Ú
connectionÚhostnameÚreturnc                 C  s    t t|  ¡ ƒt|ƒgg d� dS )a;  
    Verify whether the certificate of *connection* is valid for *hostname*.

    Args:
        connection: A pyOpenSSL connection object.

        hostname: The hostname that *connection* should be connected to.

    Raises:
        service_identity.VerificationError:
            If *connection* does not provide a certificate that is valid for
            *hostname*.

        service_identity.CertificateError:
            If certificate provided by *connection* contains invalid /
            unexpected data. This includes the case where the certificate
            contains no ``subjectAltName``\ s.

    .. versionchanged:: 24.1.0
        :exc:`~service_identity.CertificateError` is raised if the certificate
        contains no ``subjectAltName``\ s instead of
        :exc:`~service_identity.VerificationError`.
    ©Zcert_patternsZobligatory_idsZoptional_idsN)r	   r   Úget_peer_certificater   )r   r   © r   ú>/tmp/pip-unpacked-wheel-vtgpntt2/service_identity/pyopenssl.pyr      s    ÿû)r   Ú
ip_addressr   c                 C  s    t t|  ¡ ƒt|ƒgg d� dS )aX  
    Verify whether the certificate of *connection* is valid for *ip_address*.

    Args:
        connection: A pyOpenSSL connection object.

        ip_address:
            The IP address that *connection* should be connected to. Can be an
            IPv4 or IPv6 address.

    Raises:
        service_identity.VerificationError:
            If *connection* does not provide a certificate that is valid for
            *ip_address*.

        service_identity.CertificateError:
            If the certificate chain of *connection* contains a certificate
            that contains invalid/unexpected data.

    .. versionadded:: 18.1.0

    .. versionchanged:: 24.1.0
        :exc:`~service_identity.CertificateError` is raised if the certificate
        contains no ``subjectAltName``\ s instead of
        :exc:`~service_identity.VerificationError`.
    r   N)r	   r   r   r   )r   r   r   r   r   Úverify_ip_address?   s    ÿûr   r
   zSequence[CertificatePattern])Úcertr   c                 C  s   t |  ¡ ƒS )a
  
    Extract all valid ID patterns from a certificate for service verification.

    Args:
        cert: The certificate to be dissected.

    Returns:
        List of IDs.

    .. versionchanged:: 23.1.0
       ``commonName`` is not used as a fallback anymore.
    )Ú_cryptography_extract_patternsZto_cryptography©r   r   r   r   r   c   s    r   c                 C  s   t jtddd� t| ƒS )zm
    Deprecated and never public API.  Use :func:`extract_patterns` instead.

    .. deprecated:: 23.1.0
    z?`extract_ids()` is deprecated, please use `extract_patterns()`.é   )ÚcategoryÚmessageÚ
stacklevel)ÚwarningsÚwarnÚDeprecationWarningr   r   r   r   r   Úextract_idss   s    ýr"   )Ú__doc__Ú
__future__r   Ú
contextlibr   Útypingr   Zcryptographyr   r   Zhazmatr   r   r   r	   ÚsuppressÚImportErrorZOpenSSL.cryptor
   ZOpenSSL.SSLr   Ú__all__r   r   r"   r   r   r   r   Ú<module>   s   !$