
    VeIi                      n    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e          ZdS )    N)AnyOptionalUnion   )utils)OTPc                   *    e Zd ZdZ	 	 	 	 	 ddedededee         d	ee         d
eddf fdZdde	ee
j
        f         dedefdZdefdZddedee
j
                 dedefdZ	 ddee         dee         dee         defdZde
j
        defdZ xZS )TOTPz.
    Handler for time-based OTP counters.
       N   sdigitsdigestnameissuerintervalreturnc                 ~    |t           j        }|| _        t                                          |||||           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
        N)r   r   r   r   r   )hashlibsha1r   super__init__)selfr   r   r   r   r   r   	__class__s          O/var/www/html/MCyber-Diagnostic/venv/lib/python3.11/site-packages/pyotp/totp.pyr   zTOTP.__init__   sA    " >\F 1VFfUUUUU    r   for_timecounter_offsetc                     t          |t          j                  s,t          j                            t          |                    }|                     |                     |          |z             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:

        .. code:: python

            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   s      r   atzTOTP.at'   s[     (H$566 	F(66s8}}EEH  x!8!8>!IJJJr   c                     |                      |                     t          j                                                            S )zL
        Generate the current time OTP

        :returns: OTP value
        )r$   r%   r!   now)r   s    r   r(   zTOTP.now:   s3       x/@/D/D/F/F!G!GHHHr   otpvalid_windowc           
         |t           j                                         }|r_t          | |dz             D ]H}t          j        t          |          t          |                     ||                              r dS IdS t          j        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*   is        r   verifyzTOTP.verifyB   s     (,,..H 	L=,*:;;    &s3xxTWWXq5I5I1J1JKK  44 5"3s88S1B1B-C-CDDDr   issuer_nameimagec           	          t          j        | j        |r|n| j        |r|n| j        |                                 j        | j        | j        |          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   periodr2   )r   	build_urisecretr   r   r   r   r   )r   r   r1   r2   s       r   provisioning_urizTOTP.provisioning_uriV   sY     K'DDdi"->;;4;kkmm(;=
 
 
 	
r   c                     |j         r;t          t          j        |                                          | j        z            S t          t          j        |                                          | j        z            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).

        )	tzinfor#   calendartimegmutctimetupler   timemktime	timetuple)r   r   s     r   r%   zTOTP.timecodem   se     ? 	Jxx'<'<'>'>??$-OPPPt{8#5#5#7#7884=HIIIr   )r   NNNr   )r   )Nr   )NNN)__name__
__module____qualname____doc__r.   r#   r   r   r   r   r!   r&   r(   boolr0   r8   r%   __classcell__)r   s   @r   r
   r
      s         " $V VV V 	V
 smV V V 
V V V V V V.K K5h&7!78 K# KVY K K K K&IS I I I IE E# E(2C)D E[^ Egk E E E E* ei
 
SM
7?}
T\]`Ta
	
 
 
 
.
J!2 
Js 
J 
J 
J 
J 
J 
J 
J 
Jr   r
   )r;   r!   r   r>   typingr   r   r    r   r)   r   r
    r   r   <module>rJ      s        ' ' ' ' ' ' ' ' ' '            lJ lJ lJ lJ lJ3 lJ lJ lJ lJ lJr   