ó
Dª\c           @   sC   d  Z  d d l Z d d l Z d d l Z d d „ Z d „  Z d S(   sm   
Utility functions for implementing Proof Key for Code Exchange (PKCE) by OAuth
Public Clients

See RFC7636.
iÿÿÿÿNi@   c         C   sb   t  j t j |  ƒ ƒ } t | ƒ d k  r9 t d ƒ ‚ n% t | ƒ d k rZ t d ƒ ‚ n | Sd S(   sŸ  
    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.
    i+   s)   Verifier too short. n_bytes must be > 30.i€   s(   Verifier too long. n_bytes must be < 97.N(   t   base64t   urlsafe_b64encodet   ost   urandomt   lent
   ValueError(   t   n_bytest   verifier(    (    sQ   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/oauth2client/_pkce.pyt   code_verifier   s    c         C   s   t  j t j |  ƒ j ƒ  ƒ S(   sr  
    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.
    (   R    R   t   hashlibt   sha256t   digest(   R   (    (    sQ   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/oauth2client/_pkce.pyt   code_challenge4   s    (   t   __doc__R    R	   R   R   R   (    (    (    sQ   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/oauth2client/_pkce.pyt   <module>   s
   