+
    TŎiD                       a  R# t20 t R t^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHtH	t	H
t
HtHtHtHtHtHt ^ RIHt ^RIHt ^RIHt ^RIHt ^RIHtHt ^RIHt  ! R	 R
]RR7      tR]P>                  R]P>                  R]P@                  R]P@                  R]PB                  R]PB                  R]PB                  R]PB                  R]PD                  R]PD                  R]PD                  R]PD                  /t#] ^ k ]PH                  ! ]PJ                  R$8  d   RMR4      t&R%t'] ^k ](! ])! ]#PU                  4       4      4      t+] ^k ],! 0 R&m4      t-] ^k R R lt.R R lt/R R  lt0 ! R! R"4      t1R# )'av  
Digest authentication middleware for aiohttp client.

This middleware implements HTTP Digest Authentication according to RFC 7616,
providing a more secure alternative to Basic Authentication. It supports all
standard hash algorithms including MD5, SHA, SHA-256, SHA-512 and their session
variants, as well as both 'auth' and 'auth-int' quality of protection (qop) options.
N)	CallableDictFinal	FrozenSetListLiteralTuple	TypedDictUnion)URL)hdrs)ClientError)ClientHandlerType)ClientRequestClientResponse)Payloadc                   ,   a  ] tR t^$t o V 3R ltRtV tR# )DigestAuthChallengec                n   < V ^8  d   Qh/ S[ ;R&   S[ ;R&   S[ ;R&   S[ ;R&   S[ ;R&   S[ ;R&   S[ ;R&   # )   realmnonceqop	algorithmopaquedomainstalestr)format__classdict__s   "t/Users/ahmad/.openclaw/workspace/scripts/.venv/lib/python3.14/site-packages/aiohttp/client_middleware_digest_auth.py__annotate__ DigestAuthChallenge.__annotate__$   sU     J J  
H  N	 
 K  K  J      N)__name__
__module____qualname____firstlineno____annotate_func____static_attributes____classdictcell__r    s   @r!   r   r   $   s      r$   r   F)totalMD5zMD5-SESSSHAzSHA-SESSSHA256zSHA256-SESSzSHA-256zSHA-256-SESSSHA512zSHA512-SESSzSHA-512zSHA-512-SESSz:(?:^|\s|,\s*)(\w+)\s*=\s*(?:"((?:[^"\\]|\\.)*)"|([^\s,]+))z>(?:^|\s|,\s*)((?>\w+))\s*=\s*(?:"((?:[^"\\]|\\.)*)"|([^\s,]+))c                0    V ^8  d   QhR\         R\         /# r   valuereturnr   )r   s   "r!   r"   r"   u   s     % % % %r$   c                &    V P                  RR4      # )z,Escape double quotes for HTTP header values."\"replacer5   s   &r!   escape_quotesr=   u   s    ==e$$r$   c                0    V ^8  d   QhR\         R\         /# r4   r   )r   s   "r!   r"   r"   z   s     % %3 %3 %r$   c                &    V P                  RR4      # )z-Unescape double quotes in HTTP header values.r9   r8   r:   r<   s   &r!   unescape_quotesr@   z   s    ==$$r$   c                R    V ^8  d   QhR\         R\        \         \         3,          /# )r   headerr6   )r   r   )r   s   "r!   r"   r"      s"      s tCH~ r$   c           	         \         P                  V 4       UUUu/ uF5  w  rpVP                  4       ;p'       g   K   YB'       d   \        V4      MTbK7  	  uppp# u upppi )aI  
Parse key-value pairs from WWW-Authenticate or similar HTTP headers.

This function handles the complex format of WWW-Authenticate header values,
supporting both quoted and unquoted values, proper handling of commas in
quoted values, and whitespace variations per RFC 7616.

Examples of supported formats:
  - key1="value1", key2=value2
  - key1 = "value1" , key2="value, with, commas"
  - key1=value1,key2="value2"
  - realm="example.com", nonce="12345", qop="auth"

Args:
    header: The header value string to parse

Returns:
    Dictionary mapping parameter names to their values
)_HEADER_PAIRS_PATTERNfindallstripr@   )rB   key
quoted_valunquoted_valstripped_keys   &    r!   parse_header_pairsrK      s\    , .C-J-J6-R-R)C\IIK'L' 	RZoj1\Q-R  s
   AAc                      a  ] tR t^t o RtRV 3R lR lltV 3R lR ltV 3R lR ltV 3R lR	 ltV 3R
 lR lt	Rt
V tR# )DigestAuthMiddlewarea  
HTTP digest authentication middleware for aiohttp client.

This middleware intercepts 401 Unauthorized responses containing a Digest
authentication challenge, calculates the appropriate digest credentials,
and automatically retries the request with the proper Authorization header.

Features:
- Handles all aspects of Digest authentication handshake automatically
- Supports all standard hash algorithms:
  - MD5, MD5-SESS
  - SHA, SHA-SESS
  - SHA256, SHA256-SESS, SHA-256, SHA-256-SESS
  - SHA512, SHA512-SESS, SHA-512, SHA-512-SESS
- Supports 'auth' and 'auth-int' quality of protection modes
- Properly handles quoted strings and parameter parsing
- Includes replay attack protection with client nonce count tracking
- Supports preemptive authentication per RFC 7616 Section 3.6

Standards compliance:
- RFC 7616: HTTP Digest Access Authentication (primary reference)
- RFC 2617: HTTP Authentication (deprecated by RFC 7616)
- RFC 1945: Section 11.1 (username restrictions)

Implementation notes:
The core digest calculation is inspired by the implementation in
https://github.com/requests/requests/blob/v2.18.4/requests/auth.py
with added support for modern digest auth features and error handling.
c                0   < V ^8  d   QhRS[ RS[ RS[RR/# )r   loginpassword
preemptiver6   N)r   bool)r   r    s   "r!   r"   !DigestAuthMiddleware.__annotate__   s3     / // / 	/
 
/r$   c                   Vf   \        R4      hVf   \        R4      hRV9   d   \        R4      hWn        VP                  R4      V n        VP                  R4      V n        RV n        ^ V n        / V n        W0n        . V n	        R # )Nz"None is not allowed as login valuez%None is not allowed as password value:z8A ":" is not allowed in username (RFC 1945#section-11.1)utf-8r$   )

ValueError
_login_strencode_login_bytes_password_bytes_last_nonce_bytes_nonce_count
_challenge_preemptive_protection_space)selfrO   rP   rQ   s   &&&&r!   __init__DigestAuthMiddleware.__init__   s     =ABBDEE%<WXX&+*/,,w*?-5__W-E!$/1!+,.r$   c          	      V   < V ^8  d   QhRS[ RS[RS[S[S[R,          3,          RS[ /# )r   methodurlbodyr$   r6   )r   r   r
   r   r   )r   r    s   "r!   r"   rS      sA     a, a,a, #a,+0'#,1F+Ga,	a,r$   c                	  a#a$"   V P                   pRV9  d   \        R4      hRV9  d   \        R4      hVR,          pVR,          pV'       g   \        R4      hVP                  RR4      pVP                  RR	4      pVP                  4       p	VP                  R
R4      p
VP	                  R4      pVP	                  R4      p\        V4      P                  pRpRpV'       d   RR0P                  VP                  R4       Uu0 uF+  pVP                  4       '       g   K  VP                  4       kK-  	  up4      pV'       g   \        RV 24      hRV9   d   RMRpVP	                  R4      pV	\        9  d%   \        RV	 RRP                  \        4       24      h\        V	,          o$R V$3R llo#R V#3R llpRP                  V P                  WP                  34      pVP                  4        RV 2P	                  4       pVR8X  dM   \        V\         4      '       d   VP#                  4       G Rj  xL
 pMTpS#! V4      pRP                  VV34      pS#! V4      pS#! V4      pWP$                  8X  d   V ;P&                  ^,          un        M^V n        Wn        V P&                  R pVP	                  R4      p\(        P*                  ! RP                  \-        V P&                  4      P	                  R4      V\.        P0                  ! 4       P	                  R4      \2        P4                  ! ^4      .4      4      P7                  4       R,          pVP	                  R4      pV	P                  4       P9                  R4      '       d   S#! RP                  VVV34      4      pV'       d!   RP                  VVVVV34      pV! VV4      pMV! VRP                  VV34      4      pR\;        V P<                  4      R\;        V4      R\;        V4      RVR VP?                  4       RV/pV
'       d   \;        V
4      VR
&   V'       d   VVR&   VVR!&   VVR"&   . p VPA                  4        F@  w  p!p"V!\B        9   d   V PE                  V! R#V" R$24       K*  V PE                  V! R%V" 24       KB  	  R&RP                  V 4       2# u upi  EL5i)'a}  
Build digest authorization header for the current challenge.

Args:
    method: The HTTP method (GET, POST, etc.)
    url: The request URL
    body: The request body (used for qop=auth-int)

Returns:
    A fully formatted Digest authorization header string

Raises:
    ClientError: If the challenge is missing required parameters or
                 contains unsupported values

r   z:Malformed Digest auth challenge: Missing 'realm' parameterr   z:Malformed Digest auth challenge: Missing 'nonce' parameterzBSecurity issue: Digest auth challenge contains empty 'nonce' valuer    r   r/   r   rV   r$   authzauth-int,zEDigest auth error: Unsupported Quality of Protection (qop) value(s): z/Digest auth error: Unsupported hash algorithm: z. Supported algorithms: z, c                0    V ^8  d   QhR\         R\         /# )r   xr6   bytes)r   s   "r!   r"   2DigestAuthMiddleware._encode.<locals>.__annotate__  s     	3 	3 	35 	3r$   c                L   < S! V 4      P                  4       P                  4       # )z<RFC 7616 Section 3: Hash function H(data) = hex(hash(data)).)	hexdigestrY   )rm   hash_fns   &r!   H'DigestAuthMiddleware._encode.<locals>.H  s    1:'')0022r$   c                <    V ^8  d   QhR\         R\         R\         /# )r   sdr6   rn   )r   s   "r!   r"   rp      s!     	( 	(% 	(E 	(e 	(r$   c                4   < S! RP                  W34      4      # )zDRFC 7616 Section 3: KD(secret, data) = H(concat(secret, ":", data)).   :)join)rw   rx   rt   s   &&r!   KD(DigestAuthMiddleware._encode.<locals>.KD   s    TYYv&''r$   rz   rU   N08x:N   Nz-SESSusernameuriresponsenccnoncez="r8   =zDigest )#r^   r   getupperrY   r   path_qsintersectionsplitrF   DigestFunctionsr{   SUPPORTED_ALGORITHMSrZ   r[   
isinstancer   as_bytesr\   r]   hashlibsha1r   timectimeosurandomrr   endswithr=   rX   decodeitemsQUOTED_AUTH_FIELDSappend)%ra   re   rf   rg   	challenger   r   qop_rawalgorithm_originalr   r   nonce_bytesrealm_bytespathr   	qop_bytesq
valid_qopsr|   A1A2entity_bytesentity_hashHA1HA2ncvaluencvalue_bytesr   cnonce_bytesnoncebitresponse_digestheader_fieldspairsfieldr5   rt   rs   s%   &&&&                               @@r!   _encodeDigestAuthMiddleware._encode   s    & OO	)#L  )#L 
 '"'" T  --r*&]];>&,,.	x, ll7+ll7+3x 	 *-::$+MM#$6D$6q!'')$6DJ ![\c[de  !+j 8*fC

7+IO+A) M))-3G)H(IK  )3	3 	3	( 	(
 YY));8L8LMNq'..0*$((%)]]_4#L/KB,-Bee 000" !D!,&&s+w/ HH))*11':JJL''0JJqM		
 )+c	 }}W- ??%%g..DIIsK>?@C yym\9cJH !h/O diic0B&CDO doo6]5)]5)4..0+
 &3F&;M(# #&M% ")M$&,M(# )//1LE5**wbq12waw/0	 2 5)*++S E<  5sA   A
SB4SR> R>4SC2S5S6E5S,BSA?Sc                &   < V ^8  d   QhRS[ RS[/# )r   rf   r6   )r   rR   )r   r    s   "r!   r"   rS   v  s        r$   c                    \        V4      pV P                   F`  pVP                  V4      '       g   K  \        V4      \        V4      8X  g   VR,          R8X  d    R# V\        V4      ,          R8X  g   K_   R# 	  R# )z
Check if the given URL is within the current protection space.

According to RFC 7616, a URI is in the protection space if any URI
in the protection space is a prefix of it (after both have been made absolute).
/TF)r   r`   
startswithlen)ra   rf   request_str	space_strs   &&  r!   _in_protection_space)DigestAuthMiddleware._in_protection_spacev  si     #h//I)))44;3y>1Yr]c5I3y>*c1 0 r$   c                &   < V ^8  d   QhRS[ RS[/# )r   r   r6   )r   rR   )r   r    s   "r!   r"   rS     s     9% 9%n 9% 9%r$   c           
        VP                   R8w  d   R# VP                  P                  RR4      pV'       g   R# VP                  R4      w  r4pV'       g   R# VP	                  4       R8w  d   R# V'       g   R# \        V4      ;p'       g   R# / V n        \         F,  pVP                  V4      ;p'       g   K  WP                  V&   K.  	  VP                  P                  4       p	V P                  P                  R4      ;p
'       d   . V n
        V
P                  4        F  pVP                  R4      pVP                  R	4      '       d?   V P                  P                  \        V	P!                  \#        V4      4      4      4       Ki  V P                  P                  \        \#        V4      4      4       K  	  M\        V	4      .V n
        \%        V P                  4      # )
zr
Takes the given response and tries digest-auth, if needed.

Returns true if the original request must be resent.
i  Fzwww-authenticateri    digestr   r8   r   )statusheadersr   	partitionlowerrK   r^   CHALLENGE_FIELDSrf   originr`   r   rF   r   r   r   r{   r   rR   )ra   r   auth_headerre   sepr   header_pairsr   r5   r   r   r   s   &&          r!   _authenticate"DigestAuthMiddleware._authenticate  sx    ??c!&&**+=rB*44S9W<<>X% !37 ;;; %E$((//u//).& &
 $$&__((2262%'D"||~iin>>#&&**11#fkk#c(6K2LM **11#c#h-@ & '*&k]D" DOO$$r$   c                ,   < V ^8  d   QhRS[ RS[RS[/# )r   requesthandlerr6   )r   r   r   )r   r    s   "r!   r"   rS     s%      $/@	r$   c                  "   Rp\        ^4       F  pV^ 8  gF   V P                  '       d   V P                  '       dv   V P                  VP                  4      '       dU   V P                  VP                  VP                  VP                  4      G Rj  xL
 VP                  \        P                  &   V! V4      G Rj  xL
 pV P                  V4      '       d   K   M	  Vf   Q hV#  LT L+5i)zRun the digest auth middleware.N)ranger_   r^   r   rf   r   re   rg   r   r   AUTHORIZATIONr   )ra   r   r   r   retry_counts   &&&  r!   __call__DigestAuthMiddleware.__call__  s       8K Q   OOO--gkk::<@LLNNGKK= 7 2 23
 %W--H %%h//% $* ###7
 .s9   )C,C, C,4C,C(*C,>C*?C,C,*C,)r^   r\   rZ   rX   r]   r[   r_   r`   N)T)r&   r'   r(   r)   __doc__rb   r   r   r   r   r+   r,   r-   s   @r!   rM   rM      s@     </ /4a, a,F (9% 9%v r$   rM   c                   V ^8  d   Qh/ ^ \         9   d)   \        \        \        \        .R3,          3,          ;R&   ^\         9   d)   \
        \        \        R,          R3,          ,          ;R&   ^\         9   d"   \
        \        \        R3,          ,          ;R&   ^\         9   d    \
        \        \        ,          ,          ;R&   # )r   zhashlib._Hashr   .r   r   r   r   r   r   r   r   r   r   )	__conditional_annotations__r   r   r   ro   r   r   r   r   )r   s   "r!   r"   r"      s      Z c8UG_$<==> [p %	QRTWW qP U TeE#s(O, TQ^ E)C.) _r$   )      r   >   r   r   r   r   r   r   r   )3r   r   r   r   resysr   typingr   r   r   r   r   r   r   r	   r
   yarlr   ri   r   client_exceptionsr   client_middlewaresr   client_reqrepr   r   payloadr   r   md5r   sha256sha512r   compileversion_inforD   r   tuplesortedkeysr   	frozensetr   r=   r@   rK   rM   r"   )r   s   @r!   <module>r      sM    	 	 
 
 
 
   * 1 8 )5  
7;;	7<<gnn7>>w~~GNNgnn7>>w~~GNNB " 


'! B	J <	    05VO<P<P<R5S/T  T -6I-  
%
%
6F Fr$   