o
    ˆì_c~  ã                   @  sZ   d dl mZ d dlZd dlZd dlZd dlZddgZdZddd	„Zddd„Z	ddd„Z
dS )é    )ÚannotationsNÚ
accept_keyÚ
apply_maskz$258EAFA5-E914-47DA-95CA-C5AB0DC85B11ÚreturnÚstrc                  C  s   t  d¡} t | ¡ ¡ S )zB
    Generate a random key for the Sec-WebSocket-Key header.

    é   )ÚsecretsZtoken_bytesÚbase64Ú	b64encodeÚdecode)Úkey© r   ú;/usr/local/lib/python3.10/dist-packages/websockets/utils.pyÚgenerate_key   s   
r   r   c                 C  s$   t  | t  ¡ ¡ ¡ }t |¡ ¡ S )z
    Compute the value of the Sec-WebSocket-Accept header.

    Args:
        key: value of the Sec-WebSocket-Key header.

    )ÚhashlibÚsha1ÚGUIDÚencodeÚdigestr	   r
   r   )r   r   r   r   r   r      s   ÚdataÚbytesÚmaskc                 C  sj   t |ƒdkr
tdƒ‚t | tj¡}|t | ƒd  |dt | ƒd …  }t |tj¡}||A  t | ƒtj¡S )z
    Apply masking to the data of a WebSocket message.

    Args:
        data: data to mask.
        mask: 4-bytes mask.

    é   zmask must contain 4 bytesN)ÚlenÚ
ValueErrorÚintÚ
from_bytesÚsysÚ	byteorderÚto_bytes)r   r   Zdata_intZmask_repeatedZmask_intr   r   r   r   $   s   	$)r   r   )r   r   r   r   )r   r   r   r   r   r   )Ú
__future__r   r	   r   r   r   Ú__all__r   r   r   r   r   r   r   r   Ú<module>   s    

	