B
    h                 @   s`   d dl Z d dlZd dlZd dlZd dlmZmZmZ ddlm	Z	 ddl
mZ G dd deZdS )    N)AnyUnionOptional   )utils)OTPc            	       s   e Zd ZdZdejdddfeeee	e e	e edd fddZ
deeejf eed	d
dZedddZdee	ej eedddZde	e e	e e	e edddZejedddZ  ZS )TOTPz.
    Handler for time-based OTP counters.
       N   )sdigitsdigestnameissuerintervalreturnc                s    || _ t j|||||d dS )a  
        :param s: secret in base32 format
        :param interval: the time interval in seconds for OTP. This defaults to 30.
        :param digits: number of integers in the OTP. Some apps expect this to be 6 digits, others support more.
        :param digest: digest function to use in the HMAC (expected to be sha1)
        :param name: account name
        :param issuer: issuer
        )r   r   r   r   r   N)r   super__init__)selfr   r   r   r   r   r   )	__class__ GC:\Users\sanjo\AppData\Local\Qlobot\Launcher\ext_packages\pyotp\totp.pyr      s    
zTOTP.__init__r   )for_timecounter_offsetr   c             C   s0   t |tjstjt|}| | || S )a  
        Accepts either a Unix timestamp integer or a datetime object.

        To get the time until the next timecode change (seconds until the current OTP expires), use this instead::

            totp = pyotp.TOTP(...)
            time_remaining = totp.interval - datetime.datetime.now().timestamp() % totp.interval

        :param for_time: the time to generate an OTP for
        :param counter_offset: the amount of ticks to add to the time counter
        :returns: OTP value
        )
isinstancedatetimefromtimestampintgenerate_otptimecode)r   r   r   r   r   r   at   s    zTOTP.at)r   c             C   s   |  | tj S )zL
        Generate the current time OTP

        :returns: OTP value
        )r   r   r   now)r   r   r   r   r!   -   s    zTOTP.now)otpr   valid_windowr   c          	   C   sn   |dkrt j  }|rTx8t| |d D ]$}tt|t| ||r(dS q(W dS tt|t| |S )ah  
        Verifies the OTP passed in against the current time OTP.

        :param otp: the OTP to check against
        :param for_time: Time to check OTP at (defaults to now)
        :param valid_window: extends the validity to this many counter ticks before and after the current one
        :returns: True if verification succeeded, False otherwise
        Nr   TF)r   r!   ranger   strings_equalstrr    )r   r"   r   r#   ir   r   r   verify5   s    	
zTOTP.verify)r   issuer_nameimager   c          	   C   s8   t j| j|r|n| j|r|n| j|  j| j| j|dS )a  
        Returns the provisioning URI for the OTP.  This can then be
        encoded in a QR Code and used to provision an OTP app like
        Google Authenticator.

        See also:
            https://github.com/google/google-authenticator/wiki/Key-Uri-Format

        )r   	algorithmr   periodr*   )r   	build_urisecretr   r   r   r   r   )r   r   r)   r*   r   r   r   provisioning_uriI   s    zTOTP.provisioning_uri)r   r   c             C   s:   |j rtt| | j S tt| | j S dS )z
        Accepts either a timezone naive (`for_time.tzinfo is None`) or
        a timezone aware datetime as argument and returns the
        corresponding counter value (timecode).

        N)	tzinfor   calendartimegmutctimetupler   timemktime	timetuple)r   r   r   r   r   r   Z   s    zTOTP.timecode)r   )Nr   )NNN)__name__
__module____qualname____doc__hashlibsha1r&   r   r   r   r   r   r   r    r!   boolr(   r/   r   __classcell__r   r   )r   r   r      s   , "r   )r1   r   r;   r4   typingr   r   r    r   r"   r   r   r   r   r   r   <module>   s   