a
    ñ»jp
  ã                   @   sD   d dl Z d dlmZmZ ddlmZ ddlmZ G dd„ deƒZdS )é    N)ÚAnyÚOptionalé   )Úutils)ÚOTPc                	       s†   e Zd ZdZdeeeee ee eddœ‡ fdd„Zeedœd	d
„Z	eee
dœdd„Zdee ee ee ee edœdd„Z‡  ZS )ÚHOTPz.
    Handler for HMAC-based OTP counters.
    é   Nr   )ÚsÚdigitsÚdigestÚnameÚissuerÚinitial_countÚreturnc                    s.   |du rt j}|| _tƒ j|||||d� dS )a}  
        :param s: secret in base32 format
        :param initial_count: starting HMAC counter value, defaults to 0
        :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__© ú0E:\soccer\ml_env\Lib\site-packages\pyotp/hotp.pyr      s    zHOTP.__init__)Úcountr   c                 C   s   |   | j| ¡S )zz
        Generates the OTP for the given count.

        :param count: the OTP HMAC counter
        :returns: OTP
        )Zgenerate_otpr   )r   r   r   r   r   Úat$   s    zHOTP.at)ÚotpÚcounterr   c                 C   s   t  t|ƒt|  |¡ƒ¡S )z¨
        Verifies the OTP passed in against the current counter OTP.

        :param otp: the OTP to check against
        :param counter: the OTP HMAC counter
        )r   Zstrings_equalÚstrr   )r   r   r   r   r   r   Úverify-   s    zHOTP.verify)r   r   Úissuer_nameÚimager   c              	   C   s@   t j| j|r|n| j|r|n| j|r(|n| j|  ¡ j| j|d�S )a5  
        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

        :param name: name of the user account
        :param initial_count: starting HMAC counter value, defaults to 0
        :param issuer_name: the name of the OTP issuer; this will be the
            organization title of the OTP entry in Authenticator
        :returns: provisioning URI
        )r   r   r   Ú	algorithmr
   r    )r   Z	build_uriÚsecretr   r   r   r   r
   )r   r   r   r   r    r   r   r   Úprovisioning_uri6   s    ùzHOTP.provisioning_uri)r   NNNr   )NNNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úintr   r   r   r   Úboolr   r#   Ú__classcell__r   r   r   r   r      s8        ùø	    ûúr   )	r   Útypingr   r   Ú r   r   r   r   r   r   r   r   Ú<module>   s   