a
    dbF                     @   sr   d Z ddlZddlZzddlZW n ey6   dZY n0 dZG dd deZdddZd	d
 Z	dd Z
dd ZdS )zJThe match_hostname() function from Python 3.3.3, essential when using SSL.    Nz3.5.0.1c                   @   s   e Zd ZdS )CertificateErrorN)__name__
__module____qualname__ r   r   /home/tom/ab/renpy-build/tmp/install.linux-x86_64/lib/python3.9/site-packages/urllib3/packages/ssl_match_hostname/_implementation.pyr      s   r      c           
      C   s   g }| sdS |  d}|d }|dd }|d}||krLtdt|  |s`|  | kS |dkrt|d n>|d	s|d	r|t| n|t|	d
d |D ]}|t| qt
dd| d tj}	|	|S )zhMatching according to RFC 6125, section 6.4.3

    http://tools.ietf.org/html/rfc6125#section-6.4.3
    F.r   r   N*z,too many wildcards in certificate DNS name: z[^.]+zxn--z\*z[^.]*z\Az\.z\Z)splitcountr   reprlowerappend
startswithreescapereplacecompilejoin
IGNORECASEmatch)
dnhostnameZmax_wildcardsZpatspartsZleftmost	remainder	wildcardsfragpatr   r   r   _dnsname_match   s,    


r   c                 C   s&   t | tr"tjdk r"t| ddd} | S )N)   asciistrict)encodingerrors)
isinstancestrsysversion_infounicode)objr   r   r   _to_unicodeO   s    r+   c                 C   s   t t|  }||kS )zExact matching of IP addresses.

    RFC 6125 explicitly doesn't define an algorithm for this
    (section 1.7.2 - "Out of Scope").
    )	ipaddress
ip_addressr+   rstrip)ipnamehost_ipipr   r   r   _ipaddress_matchT   s    r2   c                 C   s  | st dztt|}W nJ t y4   d}Y n6 tyH   d}Y n" tyh   tdu rbd}n Y n0 g }| dd}|D ]^\}}|dkr|du rt||r dS || q~|dkr~|durt	||r dS || q~|s*| ddD ]8}|D ].\}}|dkrt||r  dS || qqt
|d	krVtd
|dtt|f n,t
|d	krztd||d f ntddS )a)  Verify that *cert* (in decoded format as returned by
    SSLSocket.getpeercert()) matches the *hostname*.  RFC 2818 and RFC 6125
    rules are followed, but IP addresses are not accepted for *hostname*.

    CertificateError is raised on failure. On success, the function
    returns nothing.
    ztempty or no certificate, match_hostname needs a SSL socket or SSL context with either CERT_OPTIONAL or CERT_REQUIREDNsubjectAltNamer   DNSz
IP Addresssubject
commonNamer   z&hostname %r doesn't match either of %sz, zhostname %r doesn't match %rr   z=no appropriate commonName or subjectAltName fields were found)
ValueErrorr,   r-   r+   UnicodeErrorAttributeErrorgetr   r   r2   lenr   r   mapr   )certr   r0   dnsnamessankeyvaluesubr   r   r   match_hostname`   sN    
rC   )r   )__doc__r   r'   r,   ImportError__version__r7   r   r   r+   r2   rC   r   r   r   r   <module>   s   

5