ó
    Û°›jáL  ã                   ó  • % S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJ	r	J
r
Jr  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJrJr  SSKJr   " S S\SS9r\R4                  \R4                  \R6                  \R6                  \R8                  \R8                  \R8                  \R8                  \R:                  \R:                  \R:                  \R:                  S.r\\ \\!/S4   4   \"S'   \RF                  " \RH                  S:  a  SOS5      r%Sr&\	\'\
S   S4      \"S'   \'" \(" \RS                  5       5      5      r*\	\'\ S4      \"S'   \+" 1 Sk5      r,\	\+\       \"S'   S\ S\ 4S jr-S\ S\ 4S jr.S \ S\\ \ 4   4S! jr/ " S" S#5      r0g)$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)ÚFinalÚLiteralÚ	TypedDict)ÚURLé   )Úhdrs)ÚClientError)ÚClientHandlerType)ÚClientRequestÚClientResponse)ÚPayloadc                   ó\   • \ rS rSr% \\S'   \\S'   \\S'   \\S'   \\S'   \\S'   \\S'   S	rg
)ÚDigestAuthChallengeé   ÚrealmÚnonceÚqopÚ	algorithmÚopaqueÚdomainÚstale© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__ÚstrÚ__annotations__Ú__static_attributes__r   ó    Úb/home/mande/repo/quber/.venv/lib/python3.13/site-packages/aiohttp/client_middleware_digest_auth.pyr   r      s%   ‡ ØƒJØƒJØ	ƒHØƒNØƒKØƒKØ†Jr!   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hashlib._HashÚDigestFunctions)é   é   z?(?:^|\s|,\s*)(\w+)(?:\s*=\s*(?:"((?:[^"\\]|\\.)*)"|([^\s,]+)))?zC(?:^|\s|,\s*)((?>\w+))(?:\s*=\s*(?:"((?:[^"\\]|\\.)*)"|([^\s,]+)))?)r   r   r   r   r   r   r   .ÚCHALLENGE_FIELDSÚSUPPORTED_ALGORITHMS>   Úurir   r   Úcnoncer   ÚresponseÚusernameÚQUOTED_AUTH_FIELDSÚvalueÚreturnc                 óF   • U R                  SS5      R                  SS5      $ )z=Escape backslashes and double quotes for HTTP quoted-strings.Ú\ú\\Ú"ú\"©Úreplace©r2   s    r"   Úescape_quotesr<   h   s    € à�=‰=˜˜vÓ&×.Ñ.¨s°EÓ:Ð:r!   c                 óF   • U R                  SS5      R                  SS5      $ )z>Unescape backslashes and double quotes in HTTP quoted-strings.r8   r7   r6   r5   r9   r;   s    r"   Úunescape_quotesr>   m   s    € à�=‰=˜ Ó$×,Ñ,¨V°TÓ:Ð:r!   Úheaderc                 óî   • 0 n[         R                  U 5       HY  nUR                  S5      nUR                  S5      UR                  S5      pTUc  Uc  U(       a    U$ MG  Ub  [        U5      OUX'   M[     U$ )aU  
Parse key-value pairs from the first challenge of a WWW-Authenticate header.

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.

A single header may carry several challenges
(https://www.rfc-editor.org/rfc/rfc7235#section-4.1). Parsing
stops at the next auth-scheme token so a later challenge's parameters cannot
overwrite the first challenge's values; a leading scheme token is skipped.

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
r   é   r)   )Ú_HEADER_PAIRS_PATTERNÚfinditerÚgroupr>   )r?   ÚpairsÚmatchÚkeyÚ
quoted_valÚunquoted_vals         r"   Úparse_header_pairsrJ   r   s~   € ð2 €EÜ&×/Ñ/°Ö7ˆØ�k‰k˜!‹nˆØ#(§;¡;¨q£>°5·;±;¸q³>�LØÑ ,Ñ"6ö Øð
 €Lñ	 à+5Ñ+AŒO˜JÔ'À|ð 	‹
ñ 8ð €Lr!   c            	       ó˜   • \ rS rSrSr SS\S\S\SS4S jjrS	\S
\S\	\
S   -  S\4S jrS
\S\4S jrS\S\4S jrS\S\S\4S jrSrg)ÚDigestAuthMiddlewareéœ   a±  
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

Origin scoping:
The credentials are scoped to the origin of the first request the
middleware handles. A request to a different origin is passed through
untouched, so it never receives a digest response computed from those
credentials, unless that origin falls within a protection space the
anchor origin advertised through the RFC 7616 ``domain`` directive. Make
the first request through the middleware against the intended origin, as
the anchor is pinned to it and not reset for the life of the instance.

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.
ÚloginÚpasswordÚ
preemptiver3   Nc                 ó  • Uc  [        S5      eUc  [        S5      eSU;   a  [        S5      eXl        UR                  S5      U l        UR                  S5      U l        SU l        SU l        0 U l        X0l        / U l	        S U l
        g )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!   r   )Ú
ValueErrorÚ
_login_strÚencodeÚ_login_bytesÚ_password_bytesÚ_last_nonce_bytesÚ_nonce_countÚ
_challengeÚ_preemptiveÚ_protection_spaceÚ_origin)ÚselfrN   rO   rP   s       r"   Ú__init__ÚDigestAuthMiddleware.__init__Ä   s�   € ð ‰=ÜÐAÓBÐBàÑÜÐDÓEÐEà�%‹<ÜÐWÓXÐXà&+ŒØ*/¯,©,°wÓ*?ˆÔØ-5¯_©_¸WÓ-EˆÔà!$ˆÔØˆÔØ/1ˆŒØ!+Ôà,.ˆÔà#'ˆ�r!   ÚmethodÚurlÚbodyr!   c           
   ƒ   óx	  ^#^$#   • U R                   nSU;  a  [        S5      eSU;  a  [        S5      eUS   nUS   nU(       d  [        S5      eUR                  SS5      nUR                  SS	5      nUR                  5       n	UR                  S
S5      n
UR	                  S5      nUR	                  S5      n[        U5      R                  nSnSnU(       aˆ  SS1R                  UR                  S5       Vs1 s H*  nUR                  5       (       d  M  UR                  5       iM,     sn5      nU(       d  [        SU 35      eSU;   a  SOSnUR	                  S5      nU	[        ;  a$  [        SU	 SSR                  [        5       35      e[        U	   m$S[        S[        4U$4S jjm#S[        S[        S[        4U#4S jjnSR                  U R                  XÀR                  45      nUR                  5        SU 3R	                  5       nUS:X  aK  [!        U["        5      (       a  UR%                  5       I Sh  v•N nOUnT#" U5      nSR                  UU45      nT#" U5      nT#" U5      nX°R&                  :X  a  U =R(                  S-  sl        OSU l        X°l        U R(                  S nUR	                  S5      n[*        R,                  " SR                  [/        U R(                  5      R	                  S5      U[0        R2                  " 5       R	                  S5      [4        R6                  " S5      /5      5      R9                  5       SS  nUR	                  S5      nU	R                  5       R;                  S!5      (       a  T#" SR                  UUU45      5      nU(       a   SR                  UUUUU45      nU" UU5      nOU" USR                  UU45      5      n[=        U R>                  5      [=        U5      [=        U5      UURA                  5       US".nU
(       a  [=        U
5      US
'   U(       a  UUS'   UUS#'   UUS$'   / n URC                  5        H?  u  n!n"U![D        ;   a  U RG                  U! S%U" S&35        M)  U RG                  U! S'U" 35        MA     S(SR                  U 5       3$ s  snf  GN{7f))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   rS   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, Úxr3   c                 óL   >• T" U 5      R                  5       R                  5       $ )z<RFC 7616 Section 3: Hash function H(data) = hex(hash(data)).)Ú	hexdigestrV   )ri   Úhash_fns    €r"   ÚHÚ'DigestAuthMiddleware._encode.<locals>.H+  s   ø€ á˜1“:×'Ñ'Ó)×0Ñ0Ó2Ð2r!   ÚsÚdc                 ó4   >• T" SR                  X45      5      $ )zDRFC 7616 Section 3: KD(secret, data) = H(concat(secret, ":", data)).ó   :)Újoin)ro   rp   rm   s     €r"   ÚKDÚ(DigestAuthMiddleware._encode.<locals>.KD/  s   ø€ á�T—Y‘Y ˜vÓ&Ó'Ð'r!   rr   rR   Nr   Ú08xé   é   z-SESS)r0   r   r   r-   r/   r   Úncr.   z="r7   Ú=zDigest )$r[   r
   ÚgetÚupperrV   r   Úraw_path_qsÚintersectionÚsplitÚstripr(   rs   r,   ÚbytesrW   rX   Ú
isinstancer   Úas_bytesrY   rZ   ÚhashlibÚsha1r   ÚtimeÚctimeÚosÚurandomrk   Úendswithr<   rU   ÚdecodeÚitemsr1   Úappend)%r_   rb   rc   rd   Ú	challenger   r   Úqop_rawÚalgorithm_originalr   r   Únonce_bytesÚrealm_bytesÚpathr   Ú	qop_bytesÚqÚ
valid_qopsrt   ÚA1ÚA2Úentity_bytesÚentity_hashÚHA1ÚHA2ÚncvalueÚncvalue_bytesr.   Úcnonce_bytesÚnoncebitÚresponse_digestÚheader_fieldsrE   Úfieldr2   rm   rl   s%                                      @@r"   Ú_encodeÚDigestAuthMiddleware._encodeà   s£  ùé € ð" —O‘Oˆ	Ø˜)Ó#ÜØLóð ð ˜)Ó#ÜØLóð ð
 ˜'Ñ"ˆØ˜'Ñ"ˆö ÜØTóð ð —-‘-  rÓ*ˆà&Ÿ]™]¨;¸Ó>ÐØ&×,Ñ,Ó.ˆ	Ø—‘˜x¨Ó,ˆð —l‘l 7Ó+ˆØ—l‘l 7Ó+ˆô
 �3‹x×#Ñ#ˆð ˆØˆ	ÞØ  *Ð-×:Ñ:Ø$+§M¡M°#Ô$6ÓDÒ$6˜q¸!¿'¹'¿)“�—‘–Ñ$6ÑDóˆJö Ü!Ø[Ð\cÐ[dÐeóð ð !+¨jÓ 8‘*¸fˆCØŸ
™
 7Ó+ˆIàœOÓ+ÜØAÀ)Àð M)Ø)-¯©Ô3GÓ)HÐ(IðKóð ô )¨Ñ3ˆð	3”ð 	3œ5÷ 	3ð	(”%ð 	(œEð 	(¤e÷ 	(ð
 �Y‰Y˜×)Ñ)¨;×8LÑ8LÐMÓNˆØ—‘“Ð˜q  Ð'×.Ñ.Ó0ˆØ�*ÓÜ˜$¤×(Ñ(Ø%)§]¡]£_×4‘à#�Ù˜L›/ˆKØ—‘˜B Ð,Ó-ˆBá�‹eˆÙ�‹eˆð ×0Ñ0Ó0Ø×Ò Ñ"Öà !ˆDÔà!,ÔØ×&Ñ& sÐ+ˆØŸ™ wÓ/ˆô —’Ø�H‰Hä˜×)Ñ)Ó*×1Ñ1°'Ó:ØÜ—J’J“L×'Ñ'¨Ó0Ü—J’J˜q“Mð	óó	
÷ ‰)‹+�c�rð	ˆð —}‘} WÓ-ˆð �?‰?Ó×%Ñ% g×.Ñ.Ù�D—I‘I˜s K°Ð>Ó?Ó@ˆCö Ø—y‘yØ˜m¨\¸9ÀcÐJóˆHñ !  hÓ/‰Oá   d§i¡i°¸cÐ0BÓ&CÓDˆOô & d§o¡oÓ6Ü" 5Ó)Ü" 5Ó)ØØ'×.Ñ.Ó0Ø+ñ
ˆö Ü&3°FÓ&;ˆM˜(Ñ#ö Ø#&ˆM˜%Ñ Ø")ˆM˜$ÑØ&,ˆM˜(Ñ#ð ˆØ)×/Ñ/Ö1‰LˆE�5ØÔ*Ó*Ø—‘ ˜w b¨¨¨qÐ1Ö2à—‘ ˜w a¨ wÐ/Ö0ñ	 2ð ˜Ÿ™ 5Ó)Ð*Ð+Ð+ùòS Eò<  5ùs&   „C3R:Ã7R2ÄR2Ä(DR:È<R7È=I;R:c                 óÞ   • [        U5      nU R                   HR  nUR                  U5      (       d  M  [        U5      [        U5      :X  d	  US   S:X  a    gU[        U5         S:X  d  MR    g   g)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)r_   rc   Úrequest_strÚ	space_strs       r"   Ú_in_protection_spaceÚ)DigestAuthMiddleware._in_protection_space…  si   € ô ˜#“hˆØ×/Ô/ˆIà×)Ñ)¨)×4Ñ4Ùä�;Ó¤3 y£>Ó1°Y¸r±]ÀcÓ5IÙàœ3˜y›>Ñ*¨cÕ1Ùñ 0ð r!   r/   c           
      óÌ  • UR                   S:w  a  gUR                  R                  SS5      nU(       d  gUR                  S5      u  p4nU(       d  gUR	                  5       S:w  a  gU(       d  g[        U5      =n(       d  g0 U l        [         H'  nUR                  U5      =nc  M  X€R                  U'   M)     UR                  R                  5       n	/ U l
        U R                  R                  S5      =n
(       a²  U
R                  5        Hž  nUR                  S5      nU(       d  M  UR                  S	5      (       a>  U R                  R                  [        U	R!                  [#        U5      5      5      5        Mq  U R                  R                  [        [#        U5      5      5        M      U R                  (       d  [        U	5      /U l
        [%        U R                  5      $ )
zr
Takes the given response and tries digest-auth, if needed.

Returns true if the original request must be resent.
i‘  Fzwww-authenticaterf   Ú Údigestr   r7   r¨   )ÚstatusÚheadersr{   Ú	partitionÚlowerrJ   r[   r+   rc   Úoriginr]   r   r€   r©   r�   r   rs   r   Úbool)r_   r/   Úauth_headerrb   Úsepr³   Úheader_pairsr£   r2   r¶   r   r-   s               r"   Ú_authenticateÚ"DigestAuthMiddleware._authenticate™  s„  € ð �?‰?˜cÓ!Øà×&Ñ&×*Ñ*Ð+=¸rÓBˆÞØà*×4Ñ4°SÓ9Ñˆ�WÞàà�<‰<‹>˜XÓ%àæàô !3°7Ó ;Ð;�Õ;àð ˆŒß%ˆEØ%×)Ñ)¨%Ó0Ð0�Ó=Ø).—‘ Ó&ñ &ð
 —‘×$Ñ$Ó&ˆØ!#ˆÔà—_‘_×(Ñ(¨Ó2Ð2ˆ6Õ2à—|‘|–~�à—i‘i “n�ÞÙØ—>‘> #×&Ñ&à×*Ñ*×1Ñ1´#°f·k±kÄ#ÀcÃ(Ó6KÓ2LÖMð ×*Ñ*×1Ñ1´#´c¸#³h³-Ö@ñ &ð ×%×%Ü&)¨&£k ]ˆDÔ"ô �D—O‘OÓ$Ð$r!   ÚrequestÚhandlerc              ƒ   ó®  #   • UR                   R                  5       nU R                  c  X0l        O?X0R                  :w  a0  U R                  UR                   5      (       d  U" U5      I Sh  v•N $ Sn[	        S5       HÇ  nUS:”  dB  U R
                  (       a…  U R                  (       at  U R                  UR                   5      (       aT  U R                  UR                  UR                   UR                  5      I Sh  v•N UR                  [        R                  '   U" U5      I Sh  v•N nU R                  U5      (       a  MÇ    O   Uc   eU$  Nã NT N+7f)zRun the digest auth middleware.NrA   r   )rc   r¶   r^   r­   Úranger\   r[   r¤   rb   rd   r³   r	   ÚAUTHORIZATIONr»   )r_   r½   r¾   r¶   r/   Úretry_counts         r"   Ú__call__ÚDigestAuthMiddleware.__call__Ö  s  é € ð —‘×#Ñ#Ó%ˆØ�<‰<ÑØ!�LØ—|‘|Ó#¨D×,EÑ,EÀgÇkÁk×,RÑ,RÙ  Ó)×)Ð)àˆÜ  ž8ˆKð ˜Q‹Ø× × Ø—O—OØ×-Ñ-¨g¯k©k×:Ñ:à<@¿L¹LØ—N‘N G§K¡K°·±ó=÷ 7�—‘¤× 2Ñ 2Ñ3ñ
 % WÓ-×-ˆHð ×%Ñ% h×/Ó/Ùñ% $ð* Ñ#Ð#Ð#Øˆñ3 *ñ7ñ
 .ùs=   ‚A)EÁ+EÁ,BEÃ<EÃ=*EÄ'EÄ(EÅEÅEÅE)	r[   rY   rW   rU   rZ   r^   rX   r\   r]   )T)r   r   r   r   Ú__doc__r   r·   r`   r   r   r   r¤   r­   r   r»   r   r   rÃ   r    r   r!   r"   rL   rL   œ   s­   † ñ%ðV  ñ	(àð(ð ð(ð ð	(ð
 
õ(ð8c, Cð c,¨cð c,¸À7È3Á<Ñ9Oð c,ÐTWô c,ðJ¨ð °ô ð(;% nð ;%¸ô ;%ðz%Ø$ð%Ø/@ð%à	÷%r!   rL   )1rÅ   r„   rˆ   ÚreÚsysr†   Úcollections.abcr   Útypingr   r   r   Úyarlr   rf   r	   Úclient_exceptionsr
   Úclient_middlewaresr   Úclient_reqrepr   r   Úpayloadr   r   Úmd5r…   Úsha256Úsha512r(   Údictr   r�   r   ÚcompileÚversion_inforB   r+   ÚtupleÚsortedÚkeysr,   Ú	frozensetr1   r<   r>   rJ   rL   r   r!   r"   Ú<module>rÙ      s¯  ðòó Û 	Û 	Û 
Û Ý $ß ,Ñ ,å å Ý *Ý 1ß 8Ý ô˜)¨5ò ð �;‰;Ø—‘Ø�<‰<Ø—‘Ø�n‰nØ—>‘>Ø�~‰~Ø—N‘NØ�n‰nØ—>‘>Ø�~‰~Ø—N‘NñB€��c˜8 U G¨_Ð$<Ñ=Ð=Ñ>ó ð" Ÿ
š
à
×Ñ˜'Ó!ñ Gà	OóÐ ð4ð	 �%Ø	ØÐQÑRÐTWÐWññó ñ  05±V¸O×<PÑ<PÓ<RÓ5SÓ/TÐ �e˜E # s (™OÑ,Ó Tñ -6ÚIó-Ð �E˜) C™.Ñ)ó ð
;˜ð ; ô ;ð
;˜3ð ; 3ô ;ð
'˜sð ' t¨C°¨H¡~ô '÷T_ò _r!   