o
     JAf%                     @   s   	 d dl Zzd dlZW n ey   dZdZd dlmZ Y n	w ejZe	ej
Zd dlZedd edD Zedd edD ZdZG dd dZdd
dZdd ZdS )    N)_compare_digestc                 c       | ]}|d A V  qdS )\   N .0xr   r   /usr/lib/python3.10/hmac.py	<genexpr>       r
      c                 c   r   )6   Nr   r   r   r   r	   r
      r   c                   @   sd   e Zd Z	 dZdZdddZdd Zd	d
 Zedd Z	dd Z
dd Zdd Zdd Zdd ZdS )HMAC@   )_hmac_inner_outer
block_sizedigest_sizeN c                 C   s   	 t |ttfstdt|j |stdtr=t |ttfr=z
| 	||| W d S  tj
y<   | ||| Y d S w | ||| d S )Nz,key: expected bytes or bytearray, but got %rz'Missing required parameter 'digestmod'.)
isinstancebytes	bytearray	TypeErrortype__name___hashopensslstr	_functype
_init_hmacUnsupportedDigestmodError	_init_oldselfkeymsg	digestmodr   r   r	   __init__&   s   zHMAC.__init__c                 C   s*   t j|||d| _| jj| _| jj| _d S )Nr&   )r   Zhmac_newr   r   r   r"   r   r   r	   r   B   s   
zHMAC._init_hmacc                    s  t  r }nt trd fdd	}nd fdd	}d | _| | _| | _| jj| _t| jdrI| jj}|dk rHt	
d|| jf td | j}nt	
d	| j td | j}t||krb|| }|| _||d
}| j|t | j|t |d ur| | d S d S )N    c                       t  | S N_hashlibnewdr(   r   r	   <lambda>K       z HMAC._init_old.<locals>.<lambda>c                    
     | S r+   r.   r/   r(   r   r	   r1   M      
 r      z:block_size of %d seems too small; using our default of %d.   z<No block_size attribute on given digest object; Assuming %d.    r)   )callabler   r   r   r   r   r   hasattrr   	_warningswarn	blocksizeRuntimeWarninglendigestljustupdate	translatetrans_5Ctrans_36)r#   r$   r%   r&   digest_consr>   r   r(   r	   r!   G   sD   

zHMAC._init_oldc                 C   s   | j r| j jS d| jj S )Nzhmac-)r   namer   )r#   r   r   r	   rH   n   s   z	HMAC.namec                 C   s   	 | j p| j}|| d S r+   )r   r   rC   )r#   r%   instr   r   r	   rC   u   s   zHMAC.updatec                 C   s\   	 | j | j }| j|_| jr| j |_d  |_|_|S d |_| j |_| j |_|S r+   )	__class____new__r   r   copyr   r   )r#   otherr   r   r	   rL   z   s   z	HMAC.copyc                 C   s,   	 | j r| j S | j }|| j  |S r+   )r   r   rL   rC   r   rA   r#   hr   r   r	   _current   s   
zHMAC._currentc                 C      	 |   }| S r+   )rP   rA   rN   r   r   r	   rA      s   zHMAC.digestc                 C   rQ   r+   )rP   	hexdigestrN   r   r   r	   rR      s   zHMAC.hexdigestNr   )r   
__module____qualname__r>   	__slots__r'   r   r!   propertyrH   rC   rL   rP   rA   rR   r   r   r   r	   r      s    
'

r   r   c                 C   s   	 t | ||S r+   )r   )r$   r%   r&   r   r   r	   r.      s   r.   c                    s   	 t d urt ttfrzt | | W S  t jy   Y nw t r& }nt tr3d fdd	}nd fdd	}| }| }t|dd}t| |krR|| 	 } | d|t|    } |
| t |
| t |
| |
|	  |	 S )	Nr)   c                    r*   r+   r,   r/   rA   r   r	   r1      r2   zdigest.<locals>.<lambda>c                    r3   r+   r4   r/   rX   r   r	   r1      r5   r   r   r8   r9   )r   r   r   r   Zhmac_digestr    r:   getattrr@   rA   rC   rD   rF   rE   )r$   r%   rA   rG   innerZouterr>   r   rX   r	   rA      s.   

rA   rS   )warningsr<   r-   r   ImportErrorr   	_operatorr   Zcompare_digestr   Zopenssl_sha256Zhashlibr   rangerE   rF   r   r   r.   rA   r   r   r   r	   <module>   s&    
 
