File: //usr/local/CyberCP/lib/python3.10/site-packages/websockets/__pycache__/utils.cpython-310.pyc
o
�h~ � @ sZ d dl mZ d dlZd dlZd dlZd dlZddgZdZddd �Zddd�Z ddd�Z
dS )� )�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.
� )�secrets�token_bytes�base64� b64encode�decode)�key� r �C/usr/local/CyberCP/lib/python3.10/site-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 |�dkr
td��t�| tj�}|t | �d |dt | �d � }t�|tj�}||A �t | �tj�S )z
Apply masking to the data of a WebSocket message.
Args:
data: Data to mask.
mask: 4-bytes mask.
� zmask must contain 4 bytesN)�len�
ValueError�int�
from_bytes�sys� byteorder�to_bytes)r r �data_int�
mask_repeated�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