Ë
    +Œ:jC/  ã                  óJ  — d dl mZ d dl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mZ ddlmZmZmZmZ ddlmZmZ dd	lmZmZmZmZ  ed
«      Zeeeef   df   Zeedf   Z G d„ de«      Z  ed¬«       G d„ de«      «       Z! ed¬«       G d„ dee!   «      «       Z"y)é    )ÚannotationsN)Ú	dataclass)Úwraps)ÚAnyÚCallableÚMappingÚTupleÚTypeVaré   )ÚBrokenResourceErrorÚEndOfStreamÚaclose_forcefullyÚget_cancelled_exc_class)ÚTypedAttributeSetÚtyped_attribute)ÚAnyByteStreamÚ
ByteStreamÚListenerÚ	TaskGroupÚT_Retval.c                  ó  — e Zd ZU dZ e«       Zded<    e«       Zded<    e«       Zded<    e«       Z	ded	<    e«       Z
d
ed<    e«       Zded<    e«       Zded<    e«       Zded<    e«       Zded<    e«       Zded<   y)ÚTLSAttributez5Contains Transport Layer Security related attributes.ú
str | NoneÚalpn_protocolÚbytesÚchannel_binding_tls_uniqueztuple[str, str, int]Úcipherz*dict[str, str | _PCTRTTT | _PCTRTT] | NoneÚpeer_certificatezbytes | NoneÚpeer_certificate_binaryÚboolÚserver_sidez!list[tuple[str, str, int]] | NoneÚshared_ciphersússl.SSLObjectÚ
ssl_objectÚstandard_compatibleÚstrÚtls_versionN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú__annotations__r   r   r   r   r!   r"   r$   r%   r'   © ó    úS/var/www/html/tokenscope/api/venv/lib/python3.12/site-packages/anyio/streams/tls.pyr   r      s™   … Ù?ñ !0Ó 1€M�:Ó1á(7Ó(9Ð Ó9á#2Ó#4€FÐ Ó4ñ DSÓCTÐÐ@ÓTá,;Ó,=Ð˜\Ó=á'Ó)€K�Ó)ñ 9HÓ8I€NÐ5ÓIá /Ó 1€J�Ó1ñ !0Ó 1Ð˜Ó1á&Ó(€K�Ô(r.   r   F)Úeqc                  óÈ   — e Zd ZU dZded<   ded<   ded<   ded	<   ded
<   edddddœ	 	 	 	 	 	 	 	 	 	 	 dd„«       Z	 	 	 	 	 	 dd„Zdd„Zdd„Z	ddd„Z
dd„Zdd„Zedd„«       Zy)Ú	TLSStreama  
    A stream wrapper that encrypts all sent data and decrypts received data.

    This class has no public initializer; use :meth:`wrap` instead.
    All extra attributes from :class:`~TLSAttribute` are supported.

    :var AnyByteStream transport_stream: the wrapped stream

    r   Útransport_streamr    r%   r#   Ú_ssl_objectzssl.MemoryBIOÚ	_read_bioÚ
_write_bioNT)r!   ÚhostnameÚssl_contextr%   c             ƒ  óø  K  — |€| }|s|rt         j                  j                  nt         j                  j                  }t        j                  |«      }t        t         d«      r$|xj                  t         j                   z  c_        t        j                  «       }t        j                  «       }|j                  ||||¬«      }	 | |||	||¬«      }
|
j                  |	j                  «      ƒ d{  –—†  |
S 7 Œ­w)aÈ  
        Wrap an existing stream with Transport Layer Security.

        This performs a TLS handshake with the peer.

        :param transport_stream: a bytes-transporting stream to wrap
        :param server_side: ``True`` if this is the server side of the connection,
            ``False`` if this is the client side (if omitted, will be set to ``False``
            if ``hostname`` has been provided, ``False`` otherwise). Used only to create
            a default context when an explicit context has not been provided.
        :param hostname: host name of the peer (if host name checking is desired)
        :param ssl_context: the SSLContext object to use (if not provided, a secure
            default will be created)
        :param standard_compatible: if ``False``, skip the closing handshake when closing the
            connection, and don't raise an exception if the peer does the same
        :raises ~ssl.SSLError: if the TLS handshake fails

        NÚOP_IGNORE_UNEXPECTED_EOF)r!   Úserver_hostname)r3   r%   r4   r5   r6   )ÚsslÚPurposeÚCLIENT_AUTHÚSERVER_AUTHÚcreate_default_contextÚhasattrÚoptionsr:   Ú	MemoryBIOÚwrap_bioÚ_call_sslobject_methodÚdo_handshake)Úclsr3   r!   r7   r8   r%   ÚpurposeÚbio_inÚbio_outr$   Úwrappers              r/   ÚwrapzTLSStream.wrapF   sç   è ø€ ð8 ÐØ&˜,ˆKáá+6”—‘×'Ò'¼C¿K¹K×<SÑ<Sð ô ×4Ñ4°WÓ=ˆKô ”sÐ6Ô7Ø×#Ò#¬×(DÑ(DÐ'DÑDÕ#ä—‘“ˆÜ—-‘-“/ˆØ ×)Ñ)Ø�G¨Àhð *ó 
ˆ
ñ Ø-Ø 3Ø"ØØô
ˆð ×,Ñ,¨Z×-DÑ-DÓE×EÐEØˆð 	Fús   ‚C/C:Ã1C8Ã2C:c              ‡  ó\  K  — 	 	  ||Ž }| j                   j                  r;| j                  j                  | j                   j	                  «       «      ƒ d {  –—†  |S 7 Œ# t
        j                  $ �r 	 | j                   j                  r<| j                  j                  | j                   j	                  «       «      ƒ d {  –—†7   | j                  j                  «       ƒ d {  –—†7  }| j                  j                  |«       np# t        $ r | j                  j                  «        Y nKt        $ r@}| j                  j                  «        | j                   j                  «        t        |‚d }~ww xY wY �n2t
        j                  $ r? | j                  j                  | j                   j	                  «       «      ƒ d {  –—†7   Y nât
        j                  $ r@}| j                  j                  «        | j                   j                  «        t        |‚d }~wt
        j                   $ r|}| j                  j                  «        | j                   j                  «        t#        |t
        j$                  «      sd|j&                  v r| j(                  rt        |‚t        d ‚‚ d }~ww xY w�Œ¨­w)NÚUNEXPECTED_EOF_WHILE_READING)r6   Úpendingr3   ÚsendÚreadr<   ÚSSLWantReadErrorÚreceiver5   Úwriter   Ú	write_eofÚOSErrorr   ÚSSLWantWriteErrorÚSSLSyscallErrorÚSSLErrorÚ
isinstanceÚSSLEOFErrorÚstrerrorr%   )ÚselfÚfuncÚargsÚresultÚdataÚexcs         r/   rE   z TLSStream._call_sslobject_method~   s  è ø€ ð ð)Ù˜t˜�ðJ —?‘?×*Ò*Ø×/Ñ/×4Ñ4°T·_±_×5IÑ5IÓ5KÓL×LÐLà�ð MùôK ×'Ñ'ó /ð/à—‘×.Ò.Ø"×3Ñ3×8Ñ8¸¿¹×9MÑ9MÓ9OÓP×PÑPà!%×!6Ñ!6×!>Ñ!>Ó!@×@Ð@�Dð —N‘N×(Ñ(¨Õ.øô #ò /Ø—N‘N×,Ñ,Ö.Üò 7Ø—N‘N×,Ñ,Ô.Ø—O‘O×-Ñ-Ô/Ü-°3Ð6ûð7ýô ×(Ñ(ò IØ×+Ñ+×0Ñ0°·±×1EÑ1EÓ1GÓH×HÓHÜ×&Ñ&ò 3Ø—‘×(Ñ(Ô*Ø—‘×)Ñ)Ô+Ü)¨sÐ2ûÜ—<‘<ò Ø—‘×(Ñ(Ô*Ø—‘×)Ñ)Ô+ä˜s¤C§O¡OÔ4Ø5¸¿¹ÑEà×/Ò/Ü1°sÐ:ä)¨tÐ3àûðúñ1 ùs¯   ‚J,…A ŠAJ,ÁAÁJ,ÁJ'Á4ADÃ CÃ"DÃ#C&Ã$DÃ)J'Ä#E2Ä(J'Ä*E2Ä2;E-Å-E2Å2J'Å5J,Å8AJ'Ç GÇJ'ÇJ,ÇJ'Ç;HÈJ'È+A7J"Ê"J'Ê'J,c              ƒ  ó  K  — | j                  | j                  j                  «      ƒ d{  –—†  | j                  j	                  «        | j
                  j	                  «        | j                  | j                  j                  «       fS 7 Œ^­w)z„
        Does the TLS closing handshake.

        :return: a tuple of (wrapped byte stream, bytes left in the read buffer)

        N)rE   r4   Úunwrapr5   rU   r6   r3   rQ   ©r]   s    r/   rd   zTLSStream.unwrap­   sl   è ø€ ð ×)Ñ)¨$×*:Ñ*:×*AÑ*AÓB×BÐBØ�‰× Ñ Ô"Ø�‰×!Ñ!Ô#Ø×$Ñ$ d§n¡n×&9Ñ&9Ó&;Ð;Ð;ð 	Cús   ‚)B«B
¬ABc              ƒ  óú   K  — | j                   r	 | j                  «       ƒ d {  –—†  | j                  j                  «       ƒ d {  –—†  y 7 Œ'# t        $ r  t        | j                  «      ƒ d {  –—†7   ‚ w xY w7 Œ3­w©N)r%   rd   ÚBaseExceptionr   r3   Úaclosere   s    r/   ri   zTLSStream.aclose¹   sm   è ø€ Ø×#Ò#ðØ—k‘k“m×#Ð#ð
 ×#Ñ#×*Ñ*Ó,×,Ñ,ð $ùÜ ò Ü'¨×(=Ñ(=Ó>×>Ñ>Øðúð 	-úsC   ‚A;�A £A¤A ¨A;ÁA9ÁA;ÁA Á!A6Á.A1Á/A6Á6A;c              ƒ  ó~   K  — | j                  | j                  j                  |«      ƒ d {  –—† }|st        ‚|S 7 Œ­wrg   )rE   r4   rQ   r   )r]   Ú	max_bytesra   s      r/   rS   zTLSStream.receiveÃ   s;   è ø€ Ø×0Ñ0°×1AÑ1A×1FÑ1FÈ	ÓR×RˆÙÜÐàˆð	 Sús   ‚*=¬;­=c              ƒ  ól   K  — | j                  | j                  j                  |«      ƒ d {  –—†  y 7 Œ­wrg   )rE   r4   rT   )r]   Úitems     r/   rP   zTLSStream.sendÊ   s(   è ø€ Ø×)Ñ)¨$×*:Ñ*:×*@Ñ*@À$ÓG×GÒGús   ‚*4¬2­4c              ƒ  ó(  K  — | j                  t        j                  «      }t        j                  d|«      }|rMt        |j                  d«      «      t        |j                  d«      xs d«      }}||fdk  rt        d|› �«      ‚t        d«      ‚­w)NzTLSv(\d+)(?:\.(\d+))?é   r   r   )ro   é   z;send_eof() requires at least TLSv1.3; current session uses z7send_eof() has not yet been implemented for TLS streams)Úextrar   r'   ÚreÚmatchÚintÚgroupÚNotImplementedError)r]   r'   rs   ÚmajorÚminors        r/   Úsend_eofzTLSStream.send_eofÍ   s�   è ø€ Ø—j‘j¤×!9Ñ!9Ó:ˆÜ—‘Ð1°;Ó?ˆÙÜ˜uŸ{™{¨1›~Ó.´°E·K±KÀ³NÒ4GÀaÓ0H�5ˆEØ�uˆ~ Ò&Ü)ð$Ø$/ =ð2óð ô
 "ØEó
ð 	
ùs   ‚BBc                ó<  ‡ — i ‰ j                   j                  ¥t        j                  ‰ j                  j
                  t        j                  ‰ j                  j                  t        j                  ‰ j                  j                  t        j                  ˆ fd„t        j                  ˆ fd„t        j                  ˆ fd„t        j                  ˆ fd„t        j                  ˆ fd„t        j                  ˆ fd„t        j                  ‰ j                  j                   i
¥S )Nc                 ó:   •— ‰ j                   j                  d«      S )NF©r4   Úgetpeercertre   s   €r/   ú<lambda>z,TLSStream.extra_attributes.<locals>.<lambda>ã   s   ø€ °4×3CÑ3C×3OÑ3OÐPUÓ3V€ r.   c                 ó:   •— ‰ j                   j                  d«      S )NTr|   re   s   €r/   r~   z,TLSStream.extra_attributes.<locals>.<lambda>ä   s   ø€ ¸$×:JÑ:J×:VÑ:VØó;€ r.   c                 ó0   •— ‰ j                   j                  S rg   )r4   r!   re   s   €r/   r~   z,TLSStream.extra_attributes.<locals>.<lambda>ç   s   ø€ ¨d×.>Ñ.>×.JÑ.J€ r.   c                 óh   •— ‰ j                   j                  r‰ j                   j                  «       S d S rg   )r4   r!   r"   re   s   €r/   r~   z,TLSStream.extra_attributes.<locals>.<lambda>è   s0   ø€ Ø×Ñ×+Ò+ð 26×1AÑ1A×1PÑ1PÓ1R€ àð r.   c                 ó   •— ‰ j                   S rg   ©r%   re   s   €r/   r~   z,TLSStream.extra_attributes.<locals>.<lambda>ë   ó   ø€ °d×6NÑ6N€ r.   c                 ó   •— ‰ j                   S rg   )r4   re   s   €r/   r~   z,TLSStream.extra_attributes.<locals>.<lambda>ì   s   ø€ ¨T×-=Ñ-=€ r.   )r3   Úextra_attributesr   r   r4   Úselected_alpn_protocolr   Úget_channel_bindingr   r   r   r!   r"   r%   r$   r'   Úversionre   s   `r/   r†   zTLSStream.extra_attributesÜ   sÒ   ø€ ð
Ø×#Ñ#×4Ñ4ð
ä×&Ñ&¨×(8Ñ(8×(OÑ(OÜ×3Ñ3°T×5EÑ5E×5YÑ5YÜ×Ñ ×!1Ñ!1×!8Ñ!8Ü×)Ñ)Ó+VÜ×0Ñ0ó 3ô ×$Ñ$Ó&JÜ×'Ñ'ó *ô ×,Ñ,Ó.NÜ×#Ñ#Ó%=Ü×$Ñ$ d×&6Ñ&6×&>Ñ&>ñ
ð 	
r.   )r3   r   r!   zbool | Noner7   r   r8   zssl.SSLContext | Noner%   r    Úreturnr2   )r^   zCallable[..., T_Retval]r_   ÚobjectrŠ   r   )rŠ   ztuple[AnyByteStream, bytes]©rŠ   ÚNone)i   )rk   rt   rŠ   r   )rm   r   rŠ   r�   ©rŠ   zMapping[Any, Callable[[], Any]])r(   r)   r*   r+   r,   ÚclassmethodrL   rE   rd   ri   rS   rP   ry   Úpropertyr†   r-   r.   r/   r2   r2   4   sÎ   … ñð $Ó#ØÓØÓØÓØÓàð
 $(Ø#Ø-1Ø$(ñ5à'ð5ð !ð	5ð
 ð5ð +ð5ð "ð5ð 
ò5ó ð5ðn-Ø+ð-Ø4:ð-à	ó-ó^
<ó-ôóHó
ð ò
ó ñ
r.   r2   c                  ó„   — e Zd ZU dZded<   ded<   dZded<   d	Zd
ed<   edd„«       Z	 d	 	 	 	 	 dd„Z	dd„Z
edd„«       Zy)ÚTLSListenera–  
    A convenience listener that wraps another listener and auto-negotiates a TLS session on every
    accepted connection.

    If the TLS handshake times out or raises an exception, :meth:`handle_handshake_error` is
    called to do whatever post-mortem processing is deemed necessary.

    Supports only the :attr:`~TLSAttribute.standard_compatible` extra attribute.

    :param Listener listener: the listener to wrap
    :param ssl_context: the SSL context object
    :param standard_compatible: a flag passed through to :meth:`TLSStream.wrap`
    :param handshake_timeout: time limit for the TLS handshake
        (passed to :func:`~anyio.fail_after`)
    zListener[Any]Úlistenerzssl.SSLContextr8   Tr    r%   é   ÚfloatÚhandshake_timeoutc              ƒ  óø   K  — t        |«      ƒ d{  –—†  t        | t        «       «      s(t        j                  t
        «      j                  d«       t        | t        «      rt        | t        «       «      r‚ y7 Œf­w)a½  
        Handle an exception raised during the TLS handshake.

        This method does 3 things:

        #. Forcefully closes the original stream
        #. Logs the exception (unless it was a cancellation exception) using the
           ``anyio.streams.tls`` logger
        #. Reraises the exception if it was a base exception or a cancellation exception

        :param exc: the exception
        :param stream: the original stream

        NzError during TLS handshake)r   rZ   r   ÚloggingÚ	getLoggerr(   Ú	exceptionÚ	Exception)rb   Ústreams     r/   Úhandle_handshake_errorz"TLSListener.handle_handshake_error  sg   è ø€ ô    Ó'×'Ð'ô ˜#Ô6Ó8Ô9Ü×ÑœhÓ'×1Ñ1Ð2NÔOô ˜#œyÔ)¬Z¸Ô=TÓ=VÔ-WØð .Xð 	(ús   ‚A:‘A8’A'A:Nc              ƒ  ó†   ‡ ‡K  — t        ‰«      dˆˆ fd„«       }‰ j                  j                  ||«      ƒ d {  –—†  y 7 Œ­w)Nc              “  ó\  •K  — ddl m} 	  |‰j                  «      5  t        j	                  | ‰j
                  ‰j                  ¬«      ƒ d {  –—† }d d d «        ‰«      ƒ d {  –—†  y 7 Œ# 1 sw Y   ŒxY w7 Œ# t        $ r%}‰j                  || «      ƒ d {  –—†7   Y d }~y d }~ww xY w­w)Nr   )Ú
fail_after)r8   r%   )	Ú r    r–   r2   rL   r8   r%   rh   r�   )rœ   r    Úwrapped_streamrb   Úhandlerr]   s       €€r/   Úhandler_wrapperz*TLSListener.serve.<locals>.handler_wrapper'  s¡   øè ø€ å%ð
.Ù × 6Ñ 6Ó7ñ Ü+4¯>©>ØØ$(×$4Ñ$4Ø,0×,DÑ,Dð ,:ó ,÷ &�N÷ñ ˜nÓ-×-Ñ-ð&ø÷ð úð .ùô !ò ?Ø×1Ñ1°#°vÓ>×>Ö>ûð?üsu   ƒB,‹A; �0A-ÁA+ÁA-ÁA; ÁB,Á%A9Á&B,Á+A-Á-A6Á2A; Á9B,Á;	B)ÂB$ÂBÂB$ÂB,Â$B)Â)B,)rœ   r   rŠ   r�   )r   r“   Úserve)r]   r£   Ú
task_groupr¤   s   ``  r/   r¥   zTLSListener.serve"  s;   ùè ø€ ô
 
ˆw‹õ	.ó 
ð	.ð �m‰m×!Ñ! /°:Ó>×>Ò>ús   „5A¹?ºAc              ƒ  óT   K  — | j                   j                  «       ƒ d {  –—†  y 7 Œ­wrg   )r“   ri   re   s    r/   ri   zTLSListener.aclose9  s   è ø€ Ø�m‰m×"Ñ"Ó$×$Ò$ús   ‚( &¡(c                ó.   ‡ — t         j                  ˆ fd„iS )Nc                 ó   •— ‰ j                   S rg   rƒ   re   s   €r/   r~   z.TLSListener.extra_attributes.<locals>.<lambda>?  r„   r.   )r   r%   re   s   `r/   r†   zTLSListener.extra_attributes<  s   ø€ ô ×,Ñ,Ó.Nð
ð 	
r.   )rb   rh   rœ   r   rŠ   r�   rg   )r£   zCallable[[TLSStream], Any]r¦   zTaskGroup | NonerŠ   r�   rŒ   rŽ   )r(   r)   r*   r+   r,   r%   r–   Ústaticmethodr�   r¥   ri   r�   r†   r-   r.   r/   r’   r’   ñ   s|   … ñð  ÓØÓØ $Ð˜Ó$Ø!Ð�uÓ!àòó ðð8 (,ð?à+ð?ð %ð?ð 
ó	?ó.%ð ò
ó ñ
r.   r’   )#Ú
__future__r   r˜   rr   r<   Údataclassesr   Ú	functoolsr   Útypingr   r   r   r	   r
   r¡   r   r   r   r   Ú_core._typedattrr   r   Úabcr   r   r   r   r   r&   Ú_PCTRTTÚ_PCTRTTTr   r2   r’   r-   r.   r/   ú<module>r³      s»   ðÝ "ã Û 	Û 
Ý !Ý ß 9Õ 9÷ó ÷ Bß @Ó @á�:Ó€Ø
��c˜3�h‘ Ð$Ñ
%€Ø�˜#�Ñ€ô)Ð$ô )ñ8 ˆeÔôy
�
ó y
ó ðy
ñx ˆeÔôN
�(˜9Ñ%ó N
ó ñN
r.   