
    !h                        S r SSKJr  SSKrSSKJr  SSKJrJrJ	r	J
r
JrJrJr  SSKJr  SSKJr  SSKJr  S	S
KJr  S	SKJrJrJrJrJrJrJrJr  S/r      SS jr       SS jr!\" S5      r"SS jr#SS jr$g)zL
`cryptography.x509 <https://github.com/pyca/cryptography>`_-specific code.
    )annotationsN)Sequence)CertificateDNSNameExtensionOID	IPAddressObjectIdentifier	OtherNameUniformResourceIdentifier)ExtensionNotFound)decode)	IA5String   )CertificateError)DNS_IDCertificatePattern
DNSPatternIPAddress_IDIPAddressPattern
SRVPattern
URIPatternverify_service_identityverify_certificate_hostnamec                @    [        [        U 5      [        U5      // S9  g)aX  
Verify whether *certificate* is valid for *hostname*.

.. note::
    Nothing is verified about the *authority* of the certificate;
    the caller must verify that the certificate chains to an appropriate
    trust root themselves.

Args:
    certificate: A *cryptography* X509 certificate object.

    hostname: The hostname that *certificate* should be valid for.

Raises:
    service_identity.VerificationError:
        If *certificate* is not valid for *hostname*.

    service_identity.CertificateError:
        If *certificate* 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`.
cert_patternsobligatory_idsoptional_idsN)r   extract_patternsr   )certificatehostnames     d/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/service_identity/cryptography.pyr   r   (   s"    : &{3x()    c                @    [        [        U 5      [        U5      // S9  g)a  
Verify whether *certificate* is valid for *ip_address*.

.. note::
    Nothing is verified about the *authority* of the certificate;
    the caller must verify that the certificate chains to an appropriate
    trust root themselves.

Args:
    certificate: A *cryptography* X509 certificate object.

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

Raises:
    service_identity.VerificationError:
        If *certificate* is not valid for *ip_address*.

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

.. 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    
ip_addresss     r"   verify_certificate_ip_addressr&   L   s#    B &{3$Z01r#   z1.3.6.1.5.5.7.8.7c           
        / n U R                   R                  [        R                  5      nUR	                  UR
                  R                  [        5       Vs/ s H(  n[        R                  " UR                  S5      5      PM*     sn5        UR	                  UR
                  R                  [        5       Vs/ s H(  n[        R                  " UR                  S5      5      PM*     sn5        UR	                  UR
                  R                  [        5       Vs/ s H  n[        U5      PM     sn5        UR
                  R                  [        5       H  nUR                   ["        :X  d  M  [%        UR
                  5      u  px['        U[(        5      (       a5  UR+                  [,        R                  " UR/                  5       5      5        Mz  Sn	[1        U	5      e   U$ s  snf s  snf s  snf ! [2         a     U$ f = f)z
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.
zutf-8zUnexpected certificate content.)
extensionsget_extension_for_oidr   SUBJECT_ALTERNATIVE_NAMEextendvalueget_values_for_typer   r   
from_bytesencoder   r   r   r   r
   type_idID_ON_DNS_SRVr   
isinstancer   appendr   asOctetsr   r   )
certidsextnameuriipothersrv_msgs
             r"   r   r   w   s    %'C"0oo3311
 	

  II99'BBD %%dkk'&:;B	
 	

 9988-C %%cjj&9:	
 	

 ))77	BBB !$B	
 YY229=E}}-,c9--JJz44S\\^DE;C*3// > J9%  > JAs#   )G2 /G#;/G(G-2
H ?H c                L    [         R                  " [        SSS9  [        U 5      $ )za
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   )r5   s    r"   extract_idsrG      s&     MM#Q
 D!!r#   )r    r   r!   strreturnNone)r    r   r%   rH   rI   rJ   )r5   r   rI   zSequence[CertificatePattern])%__doc__
__future__r   rD   typingr   cryptography.x509r   r   r   r   r	   r
   r   cryptography.x509.extensionsr   pyasn1.codec.der.decoderr   pyasn1.type.charr   
exceptionsr   hazmatr   r   r   r   r   r   r   r   __all__r   r&   r1   r   rG    r#   r"   <module>rV      s    #     ; + & (	 	 	 )
)!!(+!	!H%%*-%	%P !!452j"r#   