
    J/i                      f    S SK r S SKrS SKrS SKrS SKJrJrJr  SSKJ	r	  SSK
Jr   " S S\5      rg)    N)AnyOptionalUnion   )utils)OTPc                   <  ^  \ rS rSrSr     SS\S\S\S\\   S\\   S	\S
S4U 4S jjjr	SS\
\\R                  4   S\S
\4S jjrS
\4S jrSS\S\\R                     S\S
\4S jjr SS\\   S\\   S\\   S
\4S jjrS\R                  S
\4S jrSrU =r$ )TOTP   z&
Handler for time-based OTP counters.
Nsdigitsdigestnameissuerintervalreturnc                 V   > Uc  [         R                  nX`l        [        TU ]  XX4US9  g)aP  
: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          D/home/james-whalen/.local/lib/python3.13/site-packages/pyotp/totp.pyr   TOTP.__init__   s,    " >\\F 1FfU    for_timecounter_offsetc                     [        U[        R                  5      (       d(  [        R                  R                  [        U5      5      nU R	                  U R                  U5      U-   5      $ )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   atTOTP.at'   sP     (H$5$566((66s8}EH  x!8>!IJJr   c                 z    U R                  U R                  [        R                  R                  5       5      5      $ )z4
Generate the current time OTP

:returns: OTP value
)r$   r%   r!   now)r   s    r   r)   TOTP.now:   s-       x/@/@/D/D/F!GHHr   otpvalid_windowc           
      p   Uc  [         R                   R                  5       nU(       aW  [        U* US-   5       HB  n[        R                  " [        U5      [        U R                  X$5      5      5      (       d  MB    g   g[        R                  " [        U5      [        U R                  U5      5      5      $ )a8  
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
r   TF)r!   r)   ranger   strings_equalstrr&   )r   r+   r   r,   is        r   verifyTOTP.verifyB   s     ((,,.HL=,*:;&&s3xTWWX5I1JKK < ""3s8S1B-CDDr   issuer_nameimagec           
          [         R                  " U R                  U(       a  UOU R                  U(       a  UOU R                  U R                  5       R                  U R                  U R                  US9$ )z
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   periodr5   )r   	build_urisecretr   r   r   r   r   )r   r   r4   r5   s       r   provisioning_uriTOTP.provisioning_uriV   sR     KKDdii"-;4;;kkm((;;==
 	
r   c                    UR                   (       a:  [        [        R                  " UR	                  5       5      U R
                  -  5      $ [        [        R                  " UR                  5       5      U R
                  -  5      $ )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%   TOTP.timecodem   sW     ??xx'<'<'>?$--OPPt{{8#5#5#784==HIIr   )r   )   NNN   )r   )Nr   )NNN)__name__
__module____qualname____firstlineno____doc__r0   r#   r   r   r   r   r!   r&   r)   boolr2   r;   r%   __static_attributes____classcell__)r   s   @r   r
   r
      sD    " $VV V 	V
 smV V V 
V V.K5h&7&7!78 K# KVY K&IS IE# E(2C2C)D E[^ Egk E* ei
SM
7?}
T\]`Ta
	
.
J!2!2 
Js 
J 
Jr   r
   )r?   r!   r   rB   typingr   r   r    r   r+   r   r
    r   r   <module>rS      s-        ' '  lJ3 lJr   