o
    e                  	   @   s   d dl 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 d dl	m
Z
mZ dedeeef fdd	Zdd
ededefddZee fdedededefddZdedefddZdS )    N)time)Dict)sha1)	b64encode	b64decodesteam_guardreturnc                 C   sZ   t j| r&t| d}tj| tdW  d   S 1 sw   Y  dS tj| tdS )ae  Load Steam Guard credentials from json (file or string).

    Arguments:
        steam_guard (str): If this string is a path to a file, then its contents will be parsed as a json data.
            Otherwise, the string will be parsed as a json data.
    Returns:
        Dict[str, str]: Parsed json data as a dictionary of strings (both key and value).
    r)	parse_intN)ospathisfileopenjsonloadsreadstr)r   f r   8/usr/local/lib/python3.10/dist-packages/steampy/guard.pyload_steam_guard   s
   	$r   shared_secret	timestampc           
      C   s   |d u r	t t }td|d }tjt| |td }t	|dd d@ }t
d|||d  d	 d
@ }d}d}tdD ]}t|t|\}}	|||	 7 }q?|S )N>Q   	digestmod         z>I   r   i23456789BCDFGHJKMNPQRTVWXY    )intr   structpackhmacnewr   r   digestordunpackrangedivmodlen)
r   r   time_buffer	time_hmacbegin	full_codecharscode_ir   r   r   generate_one_time_code   s   
 r7   identity_secrettagc                 C   s2   t d||d }ttjt| |td S )Nr   asciir   )	r%   r&   encoder   r'   r(   r   r   r)   )r8   r9   r   bufferr   r   r   generate_confirmation_key,   s   r=   steam_idc              
   C   sR   t | d }dd|d d |dd |dd |dd |dd f S )	Nr:   zandroid:-         r       )r   r;   	hexdigestjoin)r>   hexed_steam_idr   r   r   generate_device_id2   s   




rG   )N)r   r'   r   r%   r   typingr   hashlibr   base64r   r   r   r   r$   r7   bytesr=   rG   r   r   r   r   <module>   s    $