
    J/i0                         S SK r S SKJr  S SKJrJrJr  S SKJrJ	r	J
r
        SS\S\S\\   S\\   S	\\   S
\\   S\\   S\\   S\4S jjrS\S\S\4S jrg)    N)compare_digest)DictOptionalUnion)quote	urlencodeurlparsesecretnameinitial_countissuer	algorithmdigitsperiodimagereturnc                 f   USLnUSL=(       a    US:g  n	USL=(       a    US:g  n
USL=(       a    US:g  nU(       a  SOSnSnSU 0n[        U5      nUb  [        U5      S	-   U-   nX>S
'   U(       a  X.S'   U	(       a  UR                  5       US'   U
(       a  X^S'   U(       a  XnS'   U(       a[  [        U5      nUR                  S:w  d"  UR                  (       a  UR
                  (       d  [        SR                  U5      5      eX~S'   UR                  X[        U5      R                  SS5      5      nU$ )ab  
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                     E/home/james-whalen/.local/lib/python3.13/site-packages/pyotp/utils.py	build_urir/      s2   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!
//(9X+>+F+FsE+R
SCJ    s1s2c                     [         R                  " SU 5      n [         R                  " SU5      n[        U R                  S5      UR                  S5      5      $ )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   