o
    uh                     @   s<   d dl Z d dlZd dlZd dlmZmZ G dd deZdS )    N)AnyOptionalc                   @   s   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
dZ
ded	efddZd	efddZeddeded	efddZdS )OTPz&
    Base class for OTP handlers.
       Nsdigitsdigestnameissuerreturnc                 C   s6   || _ |dkrtd|| _|| _|pd| _|| _d S )N
   z!digits must be no greater than 10Secret)r   
ValueErrorr   secretr	   r
   )selfr   r   r   r	   r
    r   </var/www/html/venv/lib/python3.10/site-packages/pyotp/otp.py__init__   s   

zOTP.__init__inputc                 C   s   |dk rt dt|  | || j}t| }|d d@ }|| d@ d> ||d  d@ d	> B ||d
  d@ d> B ||d  d@ B }td|d| j   }|| 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_coder   r   r   generate_otp   s   zOTP.generate_otpc                 C   s8   | j }t|d }|dkr|dd|  7 }tj|ddS )Nr   r   =T)casefold)r   lenbase64	b32decode)r   r   missing_paddingr   r   r   r!   /   s
   zOTP.byte_secretr   ipaddingc                 C   sD   t  }| dkr|| d@  | dL } | dkstt t||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)r1   r2   resultr   r   r   r"   6   s   zOTP.int_to_bytestring)r   )__name__
__module____qualname____doc__hashlibsha1r$   intr   r   r   r*   r5   r!   staticmethodr"   r   r   r   r   r      s.    
r   )r.   r=   r   typingr   r   objectr   r   r   r   r   <module>   s
    