ó
[³XMc           @   sY   d  Z  d d l m Z m Z i e d 6e d 6e d 6Z d	 d „ Z d „  Z d „  Z d	 S(
   s^   
Calculations for HTTP Digest authentication.

@see: U{http://www.faqs.org/rfcs/rfc2617.html}
iÿÿÿÿ(   t   md5t   sha1R    s   md5-sesst   shac   	      C   s  | r' | s | s | r' t  d ƒ ‚ n  | d k r t |  ƒ  } | j | ƒ | j d ƒ | j | ƒ | j d ƒ | j | ƒ | j ƒ  } n | j d ƒ } |  d k rt |  ƒ  } | j | ƒ | j d ƒ | j | ƒ | j d ƒ | j | ƒ | j ƒ  } n  | j d ƒ S(   s:  
    Compute H(A1) from RFC 2617.

    @param pszAlg: The name of the algorithm to use to calculate the digest.
        Currently supported are md5, md5-sess, and sha.
    @param pszUserName: The username
    @param pszRealm: The realm
    @param pszPassword: The password
    @param pszNonce: The nonce
    @param pszCNonce: The cnonce

    @param preHA1: If available this is a str containing a previously
       calculated H(A1) as a hex string.  If this is given then the values for
       pszUserName, pszRealm, and pszPassword must be C{None} and are ignored.
    sP   preHA1 is incompatible with the pszUserName, pszRealm, and pszPassword argumentst   :t   hexs   md5-sessN(   t	   TypeErrort   Nonet
   algorithmst   updatet   digestt   decodet   encode(	   t   pszAlgt   pszUserNamet   pszRealmt   pszPasswordt   pszNoncet	   pszCNoncet   preHA1t   mt   HA1(    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/_digest.pyt   calcHA1!   s(    c         C   sp   t  |  ƒ  } | j | ƒ | j d ƒ | j | ƒ | d k r] | j d ƒ | j | ƒ n  | j ƒ  j d ƒ S(   s÷  
    Compute H(A2) from RFC 2617.

    @param pszAlg: The name of the algorithm to use to calculate the digest.
        Currently supported are md5, md5-sess, and sha.
    @param pszMethod: The request method.
    @param pszDigestUri: The request URI.
    @param pszQop: The Quality-of-Protection value.
    @param pszHEntity: The hash of the entity body or C{None} if C{pszQop} is
        not C{'auth-int'}.
    @return: The hash of the A2 value for the calculation of the response
        digest.
    R   s   auth-intR   (   R   R   R	   R   (   t   algot	   pszMethodt   pszDigestUrit   pszQopt
   pszHEntityR   (    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/_digest.pyt   calcHA2P   s    c   	      C   sÄ   t  | ƒ  } | j |  ƒ | j d ƒ | j | ƒ | j d ƒ | rž | rž | j | ƒ | j d ƒ | j | ƒ | j d ƒ | j | ƒ | j d ƒ n  | j | ƒ | j ƒ  j d ƒ } | S(   s  
    Compute the digest for the given parameters.

    @param HA1: The H(A1) value, as computed by L{calcHA1}.
    @param HA2: The H(A2) value, as computed by L{calcHA2}.
    @param pszNonce: The challenge nonce.
    @param pszNonceCount: The (client) nonce count value for this response.
    @param pszCNonce: The client nonce.
    @param pszQop: The Quality-of-Protection value.
    R   R   (   R   R   R	   R   (	   R   t   HA2R   R   t   pszNonceCountR   R   R   t   respHash(    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/_digest.pyt   calcResponseh   s    N(	   t   __doc__t   twisted.python.hashlibR    R   R   R   R   R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/twisted/cred/_digest.pyt   <module>	   s   	
.	