
    U\h0                         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ZdededefdZy)    N)compare_digest)DictOptionalUnion)quote	urlencodeurlparsesecretnameinitial_countissuer	algorithmdigitsperiodimagereturnc                     |du}|duxr |dk7  }	|duxr |dk7  }
|duxr |dk7  }|rdnd}d}d| i}t        |      }|t        |      d	z   |z   }||d
<   |r||d<   |	r|j                         |d<   |
r||d<   |r||d<   |rQt        |      }|j                  dk7  s|j                  r|j
                  st        dj                  |            ||d<   |j                  ||t        |      j                  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uris                     G/var/www/html/trade_iq/venv/lib/python3.12/site-packages/pyotp/utils.py	build_urir/      s>   F  -D8 !,Df1D$&66Q;M$&76R<M1vvH&H2:F1CH$KEf#e+#+ ) 1##UO	w&i.>.>inn4;;IFGG!
//(E9X+>+F+FsE+R
SCJ    s1s2c                     t        j                  d|       } t        j                  d|      }t        | j                  d      |j                  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)r1   r2   s     r.   strings_equalr8   M   sG     
		vr	*B			vr	*B"))G,bii.@AAr0   )NNNNNN)r5   hmacr   typingr   r   r   urllib.parser   r   r	   strintr/   boolr8    r0   r.   <module>r@      s      ( ( 3 3 $( #  CC
C C=C SM	C
 }C SMC SMC C=C 	CLBc Bs Bt Br0   