File: //opt/cppython/lib/python3.8/site-packages/oauth2client/__pycache__/_pkce.cpython-38.pyc
U
KD�g� � @ s2 d Z ddlZddlZddlZddd�Zdd� ZdS ) 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|�dk r,td��nt|�dkrBtd��n|S dS )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)Zn_bytes�verifier� r �?/opt/cppython/lib/python3.8/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