U
    ßM‘f~  ã                   @  sl   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d	„Zddd
œdd„Z	ddddœdd„Z
dS )é    )ÚannotationsNÚ
accept_keyÚ
apply_maskz$258EAFA5-E914-47DA-95CA-C5AB0DC85B11Ústr)Úreturnc                  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   ú4/tmp/pip-unpacked-wheel-yzabpfcc/websockets/utils.pyÚgenerate_key   s    
r   )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    Úbytes)ÚdataÚmaskr   c                 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    	$)Ú
__future__r   r	   r   r   r   Ú__all__r   r   r   r   r   r   r   r   Ú<module>   s   	