o
    uäh0  ã                   @   sª   d dl Z d dlmZ d dlmZmZmZ d dlmZm	Z	m
Z
 						ddededee dee d	ee d
ee dee dee defdd„Zdededefdd„ZdS )é    N)Úcompare_digest)ÚDictÚOptionalÚUnion)ÚquoteÚ	urlencodeÚurlparseÚsecretÚnameÚinitial_countÚissuerÚ	algorithmÚdigitsÚperiodÚimageÚreturnc                 C   s  |du}|duo|dk}	|duo|dk}
|duo|dk}|r dnd}d}d| i}t |ƒ}|dur<t |ƒd	 | }||d
< |rB||d< |	rJ| ¡ |d< |
rP||d< |rV||d< |rrt|ƒ}|jdksg|jrg|jsntd |¡ƒ‚||d< | ||t|ƒ 	dd¡¡}|S )a®  
    Returns the provisioning URI for the OTP; works for either TOTP or HOTP.

    This can then be encoded in a QR Code and used to provision the Google
    Authenticator app.

    For module-internal use.

    See also:
        https://github.com/google/google-authenticator/wiki/Key-Uri-Format

    :param secret: the hotp/totp secret used to generate the URI
    :param name: name of the account
    :param initial_count: starting counter value, defaults to None.
        If none, the OTP type will be assumed as TOTP.
    :param issuer: the name of the OTP issuer; this will be the
        organization title of the OTP entry in Authenticator
    :param algorithm: the algorithm used in the OTP generation.
    :param digits: the length of the OTP generated code.
    :param period: the number of seconds the OTP generator is set to
        expire every code.
    :param image: optional logo image url
    :returns: provisioning uri
    NÚsha1é   é   ÚhotpÚtotpzotpauth://{0}/{1}?{2}r	   ú:r   Úcounterr   r   r   Úhttpsz{} is not a valid urlr   ú+z%20)
r   Úupperr   ÚschemeÚnetlocÚpathÚ
ValueErrorÚformatr   Úreplace)r	   r
   r   r   r   r   r   r   Úis_initial_count_presentÚis_algorithm_setÚis_digits_setÚis_period_setÚotp_typeÚbase_uriÚurl_argsÚlabelÚ	image_uriÚuri© r,   ú>/var/www/html/venv/lib/python3.10/site-packages/pyotp/utils.pyÚ	build_uri   s4   #r.   Ús1Ús2c                 C   s.   t  d| ¡} t  d|¡}t|  d¡| d¡ƒS )a  
    Timing-attack resistant string comparison.

    Normal comparison using == will short-circuit on the first mismatching
    character. This avoids that by scanning the whole string, though we
    still reveal to a timing attack whether the strings are the same
    length.
    ÚNFKCzutf-8)ÚunicodedataÚ	normalizer   Úencode)r/   r0   r,   r,   r-   Ústrings_equalM   s   	r5   )NNNNNN)r2   Úhmacr   Útypingr   r   r   Úurllib.parser   r   r   ÚstrÚintr.   Úboolr5   r,   r,   r,   r-   Ú<module>   s<    øÿþýüûúùø	
÷F