a
    ù!f–  ã                   @   s2   d Z ddlZddlZddlZddd„Zdd„ ZdS )	zm
Utility functions for implementing Proof Key for Code Exchange (PKCE) by OAuth
Public Clients

See RFC7636.
é    Né@   c                 C   sJ   t  t | ¡¡ d¡}t|ƒdk r,tdƒ‚nt|ƒdkrBtdƒ‚n|S dS )aŸ  
    Generates a 'code_verifier' as described in section 4.1 of RFC 7636.

    This is a 'high-entropy cryptographic random string' that will be
    impractical for an attacker to guess.

    Args:
        n_bytes: integer between 31 and 96, inclusive. default: 64
            number of bytes of entropy to include in verifier.

    Returns:
        Bytestring, representing urlsafe base64-encoded random data.
    ó   =é+   z)Verifier too short. n_bytes must be > 30.é€   z(Verifier too long. n_bytes must be < 97.N)Úbase64Úurlsafe_b64encodeÚosÚurandomÚrstripÚlenÚ
ValueError)Zn_bytesÚverifier© r   úS/var/www/html/python-backend/venv/lib/python3.9/site-packages/oauth2client/_pkce.pyÚcode_verifier   s    

r   c                 C   s   t  | ¡ ¡ }t |¡ d¡S )a“  
    Creates a 'code_challenge' as described in section 4.2 of RFC 7636
    by taking the sha256 hash of the verifier and then urlsafe
    base64-encoding it.

    Args:
        verifier: bytestring, representing a code_verifier as generated by
            code_verifier().

    Returns:
        Bytestring, representing a urlsafe base64-encoded sha256 hash digest,
            without '=' padding.
    r   )ÚhashlibÚsha256Údigestr   r   r
   )r   r   r   r   r   Úcode_challenge4   s    r   )r   )Ú__doc__r   r   r   r   r   r   r   r   r   Ú<module>   s
   
