B
    hT                 @   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               @   sr   e Zd ZdZdejddfeeee	e e	e ddddZ
eeddd	Zed
ddZedeeedddZdS )OTPz&
    Base class for OTP handlers.
       N)sdigitsdigestnameissuerreturnc             C   s&   || _ || _|| _|pd| _|| _d S )NZSecret)r   r   secretr	   r
   )selfr   r   r   r	   r
    r   FC:\Users\sanjo\AppData\Local\Qlobot\Launcher\ext_packages\pyotp\otp.py__init__   s
    
zOTP.__init__)inputr   c             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| j  }xt	|| jk rd| }qW |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                           
   0)

ValueErrorhmacnewbyte_secretint_to_bytestringr   	bytearraystrr   len)r   r   hasherZ	hmac_hashoffsetcodeZstr_coder   r   r   generate_otp   s    6zOTP.generate_otp)r   c             C   s8   | j }t|d }|dkr*|dd|  7 }tj|ddS )Nr   r   =T)casefold)r   r%   base64	b32decode)r   r   missing_paddingr   r   r   r!   '   s
    zOTP.byte_secretr   )ipaddingr   c             C   sB   t  }x"| dkr(|| d@  | dL } qW 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)r/   r0   resultr   r   r   r"   .   s
    
zOTP.int_to_bytestring)r   )__name__
__module____qualname____doc__hashlibsha1r$   intr   r   r   r)   r3   r!   staticmethodr"   r   r   r   r   r      s   $r   )r,   r;   r   typingr   r   objectr   r   r   r   r   <module>   s   