← back to Atmos Game

assets/gen/.venv/lib/python3.12/site-packages/anyio/streams/__pycache__/tls.cpython-312.pyc

153 lines

�

c�bj�=��*�UddlmZdZddlZddlZddlZddlZddlmZm	Z	ddl
mZddlm
Z
ddlmZddlmZmZmZd	d
lmZmZmZmZmZd	dlmZmZd	dlmZmZmZm Z m!Z!m"Z"ejFd
k\r	ddlm$Z$m%Z%nddl&m$Z$m%Z%ejFdk\rddlm'Z'nddl&m'Z'ed�Z(e$d�Z)e*e*e+e+fdfZ,de-d<e*e,dfZ.de-d<Gd�de�Z/ed��Gd�de��Z0ed��Gd�de!e0��Z1Gd�d e �Z2y)!�)�annotations)�TLSAttribute�TLSConnectable�TLSListener�	TLSStreamN)�Callable�Mapping)�	dataclass)�wraps)�
SSLContext)�Any�	TypeAlias�TypeVar�)�BrokenResourceError�EndOfStream�aclose_forcefully�get_cancelled_exc_class�	to_thread)�TypedAttributeSet�typed_attribute)�
AnyByteStream�AnyByteStreamConnectable�
ByteStream�ByteStreamConnectable�Listener�	TaskGroup)��)�TypeVarTuple�Unpack)r�)�override�T_Retval�PosArgsT.r�_PCTRTT�_PCTRTTTc��eZdZUdZe�Zded<e�Zded<e�Zded<e�Z	ded	<e�Z
d
ed<e�Zded
<e�Zded<e�Z
ded<e�Zded<e�Zded<y)rz5Contains Transport Layer Security related attributes.�
str | None�
alpn_protocol�bytes�channel_binding_tls_uniqueztuple[str, str, int]�cipherz*None | dict[str, str | _PCTRTTT | _PCTRTT]�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__rr*�__annotations__r,r-r.r/r1r2r4r5r7���h/Users/macstudio3/Projects/atmos-game/assets/gen/.venv/lib/python3.12/site-packages/anyio/streams/tls.pyrr5s���?�!0� 1�M�:�1�(7�(9���9�#2�#4�F� �4�FU�EV��B�V�,;�,=��\�=�'�)�K��)�9H�8I�N�5�I� /� 1�J�
�1�!0� 1���1�&�(�K��(r>rF)�eqc���eZdZUdZded<ded<ded<ded	<ded
<eddddd
�											dd��Z						dd�Zdd�Zdd�Z	ddd�Z
dd�Zdd�Ze
dd��Zy)ra
    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_streamr0r5r3�_ssl_objectz
ssl.MemoryBIO�	_read_bio�
_write_bioNT)r1�hostname�ssl_contextr5c��K�|�|}|s|rtjjntjj}tj|�}ttd�r$|xjtjzc_tj�}tj�}|�ddl	m
}	|	|�}
nd}
t|�tjur|j||||
��}n,tj|j||||
d��d{���}||||||��}|j!|j"��d{���|S7�67��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_EOFr)�idna2008_resolve)r1�server_hostname)rBr5rCrDrE)�ssl�Purpose�CLIENT_AUTH�SERVER_AUTH�create_default_context�hasattr�optionsrI�	MemoryBIO�_core._socketsrJ�typer�wrap_bior�run_sync�_call_sslobject_method�do_handshake)
�clsrBr1rFrGr5�purpose�bio_in�bio_outrJrKr4�wrappers
             r?�wrapzTLSStream.wrapcsL����:��&�,�K��+6����'�'�C�K�K�<S�<S�
��4�4�W�=�K��s�6�7��#�#��(D�(D�'D�D�#�������-�-�/����9�,<�X�,F�O�"�O�������.�$�-�-���'� /�	.��J� )�1�1��$�$������
 ��J��-� 3�"���
���,�,�Z�-D�-D�E�E�E���#�� 	F�s$�DE�E�/E�E�
E�Ec��tK�		||�}|jjr;|jj|jj	���d{���|S7�#t
j$�r	|jjr<|jj|jj	���d{���7|jj��d{���7}|jj|�np#t$r|jj�YnKt$r@}|jj�|jj�t|�d}~wwxYwY�n>t
j$r?|jj|jj	���d{���7Yn�t
j$r@}|jj�|jj�t|�d}~wt
j $r�}|jj�|jj�t#|t
j$�s|j&r(d|j&vr|j(rt|�td��d}~wwxYw����w)N�UNEXPECTED_EOF_WHILE_READING)rE�pendingrB�send�readrL�SSLWantReadError�receiverD�writer�	write_eof�OSErrorr�SSLWantWriteError�SSLSyscallError�SSLError�
isinstance�SSLEOFError�strerrorr5)�self�func�args�result�data�excs      r?rXz TLSStream._call_sslobject_method�s
�����(
��t���H�?�?�*�*��/�/�4�4�T�_�_�5I�5I�5K�L�L�L��
�M��I�'�'�
/�
/����.�.�"�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���<�<�
����(�(�*����)�)�+��c�3�?�?�3��L�L�%C�s�|�|�%S��/�/�1�s�:�)�t�3���
��1�s��J8�A�AJ8�A�J8�J3�4AD�C�"D�#C&�$D�)J3�#E2�(J3�*E2�2;E-�-E2�2J3�5J8�8AJ3�G�J3�J8�J3�;H�J3�+BJ.�.J3�3J8c��K�|j|jj��d{���|jj	�|j
j	�|j|jj�fS7�^�w)z�
        Does the TLS closing handshake.

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

        N)rXrC�unwraprDrhrErBrd�rps r?rwzTLSStream.unwrap�sl�����)�)�$�*:�*:�*A�*A�B�B�B���� � �"����!�!�#��$�$�d�n�n�&9�&9�&;�;�;�	C�s�)B�B
�ABc���K�|jr	|j��d{���|jj��d{���y7�'#t$r t|j��d{���7�wxYw7�3�w�N)r5rw�
BaseExceptionrrB�acloserxs r?r|zTLSStream.aclose�sm�����#�#�
��k�k�m�#�#�
�#�#�*�*�,�,�,�$�� �
�'��(=�(=�>�>�>��
��	-�sC�
A;�A
�A�A
�A;�A9�A;�A
�
!A6�.A1�/A6�6A;c��K�|dkrtd��|j|jj|��d{���}|st�|S7��w)N�z$max_bytes must be a positive integer)�
ValueErrorrXrCrdr)rp�	max_bytesrts   r?rfzTLSStream.receive�sN�����q�=��C�D�D��0�0��1A�1A�1F�1F�	�R�R�������	S�s�:A
�A�A
c��lK�|j|jj|��d{���y7��wrz)rXrCrg)rp�items  r?rczTLSStream.sends(�����)�)�$�*:�*:�*@�*@�$�G�G�G�s�*4�2�4c��(K�|jtj�}tjd|�}|rMt|j
d��t|j
d�xsd�}}||fdkrtd|����td���w)NzTLSv(\d+)(?:\.(\d+))?r~rr)r~rz;send_eof() requires at least TLSv1.3; current session uses z7send_eof() has not yet been implemented for TLS streams)�extrarr7�re�match�int�group�NotImplementedError)rpr7r��major�minors     r?�send_eofzTLSStream.send_eofs������j�j��!9�!9�:�����1�;�?����u�{�{�1�~�.��E�K�K��N�4G�a�0H�5�E��u�~��&�)�$�$/�=�2���
"�E�
�	
�s�BBc�<��i�jj�tj�jj
tj�jjtj�jjtj�fd�tj�fd�tj�fd�tj�fd�tj�fd�tj�fd�tj�jj i
�S)Nc�:���jjd�S)NF�rC�getpeercertrxs�r?�<lambda>z,TLSStream.extra_attributes.<locals>.<lambda>s���4�3C�3C�3O�3O�PU�3Vr>c�:���jjd�S)NTr�rxs�r?r�z,TLSStream.extra_attributes.<locals>.<lambda> s���$�:J�:J�:V�:V��;r>c�0���jjSrz)rCr1rxs�r?r�z,TLSStream.extra_attributes.<locals>.<lambda>#s���d�.>�.>�.J�.Jr>c�h���jjr�jj�SdSrz)rCr1r2rxs�r?r�z,TLSStream.extra_attributes.<locals>.<lambda>$s3����#�#�/�/�� � �/�/�1���r>c����jSrz�r5rxs�r?r�z,TLSStream.extra_attributes.<locals>.<lambda>)����d�6N�6Nr>c����jSrz)rCrxs�r?r�z,TLSStream.extra_attributes.<locals>.<lambda>*s���T�-=�-=r>)rB�extra_attributesrr*rC�selected_alpn_protocolr,�get_channel_bindingr-r.r/r1r2r5r4r7�versionrxs`r?r�zTLSStream.extra_attributess����
��#�#�4�4�
��&�&��(8�(8�(O�(O��3�3�� � �4�4�����!1�!1�!8�!8��)�)�+V��0�0�3�
�$�$�&J��'�'�*�

�,�,�.N��#�#�%=��$�$�d�&6�&6�&>�&>�'
�	
r>)rBrr1zbool | NonerFr)rG�ssl.SSLContext | Noner5r0�returnr)rqz&Callable[[Unpack[PosArgsT]], T_Retval]rrzUnpack[PosArgsT]r�r$)r�ztuple[AnyByteStream, bytes]�r��None)i)r�r�r�r+)r�r+r�r��r�zMapping[Any, Callable[[], Any]])r8r9r:r;r<�classmethodr_rXrwr|rfrcr��propertyr�r=r>r?rrQs����$�#����������
$(�#�-1�$(�P�'�P�!�	P�
�P�+�
P�"�P�
�P��P�d,�:�,�CS�,�	�,�\
<�-��H�

��
��
r>rc��eZdZUdZded<ded<dZded<d	Zd
ed<edd��Z	d					dd�Z	dd�Z
edd��Zy
)ra�
    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]�listenerzssl.SSLContextrGTr0r5��float�handshake_timeoutc���K�t|��d{���t|t��s*tjt
�j
d|��t|t�rt|t��r�y7�h�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

        NzError during TLS handshake)�exc_info)rrmr�logging�	getLoggerr8�	exception�	Exception)ru�streams  r?�handle_handshake_errorz"TLSListener.handle_handshake_errorGsr����  ��'�'�'��#�6�8�9�

���h�'�1�1�,�s�
2�
�
�#�y�)�Z��=T�=V�-W��.X�	(�s�A<�A:�A)A<Nc����K�t��d��fd��}�jj||��d{���y7��w)Nc��\�K�ddlm}	|�j�5tj	|�j
�j���d{���}ddd����d{���y7�#1swY�xYw7�#t$r%}�j||��d{���7Yd}~yd}~wwxYw�w)Nr)�
fail_after)rGr5)	�r�r�rr_rGr5r{r�)r�r��wrapped_streamru�handlerrps    ��r?�handler_wrapperz*TLSListener.serve.<locals>.handler_wrapperls������%�

.��� 6� 6�7�+4�>�>��$(�$4�$4�,0�,D�,D�,:�,�&�N�8��n�-�-�-�&��8�7��.��!�
?��1�1�#�v�>�>�>��
?�su�B,�A;�0A-�
A+�A-�A;�B,�%A9�&B,�+A-�-A6�2A;�9B,�;	B)�B$�B�B$�B,�$B)�)B,)r�rr�r�)rr��serve)rpr��
task_groupr�s``  r?r�zTLSListener.servegs;�����

�w��
	.�
�
	.��m�m�!�!�/�:�>�>�>�s�5A�?�Ac��TK�|jj��d{���y7��wrz)r�r|rxs r?r|zTLSListener.aclose~s�����m�m�"�"�$�$�$�s�(�&�(c�.��tj�fd�iS)Nc����jSrzr�rxs�r?r�z.TLSListener.extra_attributes.<locals>.<lambda>�r�r>)rr5rxs`r?r�zTLSListener.extra_attributes�s���
�,�,�.N�
�	
r>)rur{r�rr�r�rz)r�zCallable[[TLSStream], Any]r�zTaskGroup | Noner�r�r�r�)
r8r9r:r;r<r5r��staticmethodr�r�r|r�r�r=r>r?rr/s}���"���� $���$�!��u�!�����D(,�?�+�?�%�?�
�	?�.%��
��
r>rc�F�eZdZdZdddd�									dd�Zedd��Zy)	ra�
    Wraps another connectable and does TLS negotiation after a successful connection.

    :param connectable: the connectable to wrap
    :param hostname: host name of the server (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 server does the same
    NT�rFrGr5c�8�||_|xs-tjtjj�|_t
|j
tj�s+tdt|j
�j����||_||_y)Nz7ssl_context must be an instance of ssl.SSLContext, not )
�connectablerLrPrMrOrGrmr�	TypeErrorrUr8rFr5)rpr�rFrGr5s     r?�__init__zTLSConnectable.__init__�s���'���'2�(
�c�6P�6P��K�K�#�#�7
����$�*�*�C�N�N�;��I���(�(�)�2�2�3�5��
�!��
�#6�� r>c��K�|jj��d{���}	tj||j|j
|j���d{���S7�D7�#t$rt|��d{���7�wxYw�w)Nr�)	r��connectrr_rFrGr5r{r)rpr�s  r?r�zTLSConnectable.connect�s������'�'�/�/�1�1��		�"������� �,�,�$(�$<�$<�	(���
�2�����	�#�F�+�+�+��	�sD�B�A%�B�:A)� A'�!A)�$B�'A)�)B�B�B�B)
r�rrFr)rGr�r5r0r�r�)r�r)r8r9r:r;r�r#r�r=r>r?rr�s[��	� $�-1�$(�
7�-�7��	7�
+�7�"�
7�
�7�(���r>r)3�
__future__r�__all__r�r�rL�sys�collections.abcrr	�dataclassesr
�	functoolsrr�typingr
rrr�rrrrr�_core._typedattrrr�abcrrrrrr�version_infor r!�typing_extensionsr#r$r%�tupler6r&r<r'rrrrr=r>r?�<module>r�s ��"����	�
�
�-�!���*�*���B������w��+�+�6����w���*��:����
�#���5��c��?�C�/�0���0��G�S�L�)��)�)�)�$�)�8�e��Z
�
�Z
��Z
�z�e��U
�(�9�%�U
��U
�p,�*�,r>