
    h                     H    S r SSKJr  SSKJrJr  \\\S.r S	S jrS rS r	g)
z^
Calculations for HTTP Digest authentication.

@see: U{http://www.faqs.org/rfcs/rfc2617.html}
    )hexlify)md5sha1)s   md5   md5-sesss   shaNc                 \   U(       a   U(       d  U(       d  U(       a  [        S5      eUc}  [        U    " 5       nUR                  U5        UR                  S5        UR                  U5        UR                  S5        UR                  U5        [        UR	                  5       5      nOUnU S:X  a|  [        U    " 5       nUR                  U5        UR                  S5        UR                  U5        UR                  S5        UR                  U5        [        UR	                  5       5      nU$ )a
  
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 L{None} and are ignored.
zPpreHA1 is incompatible with the pszUserName, pszRealm, and pszPassword arguments   :r   )	TypeError
algorithmsupdater   digest)	pszAlgpszUserNamepszRealmpszPasswordpszNonce	pszCNoncepreHA1mHA1s	            [/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/cred/_digest.pycalcHA1r   !   s    & ;(k2
 	

 ~v 					ahhj! v 					ahhj!J    c                    [         U    " 5       nUR                  U5        UR                  S5        UR                  U5        US:X  a"  UR                  S5        UR                  U5        [        UR                  5       5      $ )a  
Compute H(A2) from RFC 2617.

@param algo: 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 L{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-intr
   r   r   r   )algo	pszMethodpszDigestUripszQop
pszHEntityr   s         r   calcHA2r    S   sd     	4AHHYHHTNHH\		188:r   c                    [         U   " 5       nUR                  U 5        UR                  S5        UR                  U5        UR                  S5        U(       am  U(       af  UR                  U5        UR                  S5        UR                  U5        UR                  S5        UR                  U5        UR                  S5        UR                  U5        [        UR                  5       5      nU$ )aa  
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   HA2r   r   pszNonceCountr   r   r   respHashs	            r   calcResponser%   k   s     	4AHHSMHHTNHHXHHTN						HHSMqxxz"HOr   )N)
__doc__binasciir   hashlibr   r   r
   r   r    r%    r   r   <module>r*      s=   
  
  
" MQ/d0r   