a
    Šxd  ã                   @   s€   g d ¢Z ddlmZ ddlmZmZmZmZ ddlmZ ddl	Z	e	j
e	j ZdZdZedƒZd	d
„ Zedfdd„Zddd„ZdS ))ÚsplitÚmkNonceÚcheckTimestampé    )Ú	cryptutil)ÚstrptimeÚstrftimeÚgmtimeÚtime)ÚtimegmNiPF  z%Y-%m-%dT%H:%M:%SZz0000-00-00T00:00:00Zc                 C   sV   | dt … }ztt|tƒƒ}W n ty4   d}Y n0 |dk rFtdƒ‚|| t d… fS )aZ  Extract a timestamp from the given nonce string

    @param nonce_string: the nonce from which to extract the timestamp
    @type nonce_string: str

    @returns: A pair of a Unix timestamp and the salt characters
    @returntype: (int, str)

    @raises ValueError: if the nonce does not start with a correctly
        formatted time string
    Néÿÿÿÿr   ztime out of range)Útime_str_lenr
   r   Útime_fmtÚAssertionErrorÚ
ValueError)Únonce_stringZtimestamp_strÚ	timestamp© r   úJ/var/www/html/Ranjet/env/lib/python3.9/site-packages/openid/store/nonce.pyr      s    
r   c                 C   s`   zt | ƒ\}}W n ty$   Y dS 0 |du r4tƒ }|| }|| }||  koV|kS   S dS )a8  Is the timestamp that is part of the specified nonce string
    within the allowed clock-skew of the current time?

    @param nonce_string: The nonce that is being checked
    @type nonce_string: str

    @param allowed_skew: How many seconds should be allowed for
        completing the request, allowing for clock skew.
    @type allowed_skew: int

    @param now: The current time, as a Unix timestamp
    @type now: int

    @returntype: bool
    @returns: Whether the timestamp is correctly formatted and within
        the allowed skew of the current time.
    FN)r   r   r	   )r   Zallowed_skewÚnowZstampÚ_ZpastÚfuturer   r   r   r   -   s    r   c                 C   s6   t  dt¡}| du rtƒ }nt| ƒ}tt|ƒ}|| S )a  Generate a nonce with the current timestamp

    @param when: Unix timestamp representing the issue time of the
        nonce. Defaults to the current time.
    @type when: int

    @returntype: str
    @returns: A string that should be usable as a one-way nonce

    @see: time
    é   N)r   ZrandomStringÚNONCE_CHARSr   r   r   )ÚwhenZsaltÚtZtime_strr   r   r   r   R   s    
r   )N)Ú__all__Zopenidr   r	   r   r   r   Úcalendarr
   ÚstringÚascii_lettersÚdigitsr   ZSKEWr   Úlenr   r   r   r   r   r   r   r   Ú<module>   s   %