
    U\h                     B    d dl Z d dlZd dlZd dlmZmZ  G d de      Zy)    N)AnyOptionalc                       e Zd ZdZdej
                  ddfdededede	e   de	e   d	dfd
Z
ded	efdZd	efdZeddeded	efd       Zy)OTPz&
    Base class for OTP handlers.
       Nsdigitsdigestnameissuerreturnc                 r    || _         |dkD  rt        d      || _        || _        |xs d| _        || _        y )N
   z!digits must be no greater than 10Secret)r	   
ValueErrorr
   secretr   r   )selfr   r	   r
   r   r   s         E/var/www/html/trade_iq/venv/lib/python3.12/site-packages/pyotp/otp.py__init__zOTP.__init__   s?     B;@AA$H	    inputc                    |dk  rt        d      t        j                  | j                         | j	                  |      | j
                        }t        |j                               }|d   dz  }||   dz  dz  ||dz      dz  d	z  z  ||d
z      dz  dz  z  ||dz      dz  z  }t        d|d| j                  z  z  z         }|| j                   d S )z
        :param input: the HMAC counter value to use as the OTP input.
            Usually either the counter, or the computed integer based on the Unix timestamp
        r   zinput must be positive integer                           l    d(	 r   N)	r   hmacnewbyte_secretint_to_bytestringr
   	bytearraystrr	   )r   r   hasher	hmac_hashoffsetcodestr_codes          r   generate_otpzOTP.generate_otp   s    
 19=>>$**,d.D.DU.KT[[Yfmmo.	2$v%",!$t+23!$t+12 !$t+- 	 ~DKK)?@A''r   c                     | j                   }t        |      dz  }|dk7  r|dd|z
  z  z  }t        j                  |d      S )Nr!   r   =T)casefold)r   lenbase64	b32decode)r   r   missing_paddings      r   r%   zOTP.byte_secret/   sG    f+/acQ011F66r   ipaddingc                     t               }| dk7  r|j                  | dz         | dz  } | dk7  rt        t        t        |            j	                  |d            S )z
        Turns an integer to the OATH specified
        bytestring, which is fed to the HMAC
        along with the secret
        r   r   r!       )r'   appendbytesreversedrjust)r6   r7   results      r   r&   zOTP.int_to_bytestring6   sX     1fMM!d(#!GA 1f Yx/066wFGGr   )r!   )__name__
__module____qualname____doc__hashlibsha1r(   intr   r   r   r.   r;   r%   staticmethodr&    r   r   r   r      s     ll" $  	
 sm  
 (# (# (&7U 7 HS H3 Hu H Hr   r   )r3   rC   r#   typingr   r   objectr   rG   r   r   <module>rJ      s        =H& =Hr   