
    k7i!                         S SK Jr  S SKJr  S SKrS SKJr  S\4S jrS\4S jr	Sr
S	r " S
 S\5      r " S S\5      r " S S\5      r " S S5      r\rg)    )hexlify)EnumN)Optionalreturnc                  x    [        [        [        R                  " 5       5      R	                  S5      5      n SU -  $ )zPrepare an AUTH command line with the current effective user ID.

This is the preferred authentication method for typical D-Bus connections
over a Unix domain socket.
asciis   AUTH EXTERNAL %b
)r   strosgeteuidencode)hex_uids    F/home/james-whalen/.local/lib/python3.13/site-packages/jeepney/auth.pymake_auth_externalr      s/     c"**,'..w78G"W,,    c                  R    SSK Jn   [        SU -  R                  S5      5      nSU-  $ )zFormat an AUTH command line for the ANONYMOUS mechanism

Jeepney's higher-level wrappers don't currently use this mechanism,
but third-party code may choose to.

See <https://tools.ietf.org/html/rfc4505> for details.
   )__version__z
Jeepney %sr   s   AUTH ANONYMOUS %s
) r   r   r   )r   traces     r   make_auth_anonymousr      s,     \K/77@AE#e++r   s   BEGIN
s   NEGOTIATE_UNIX_FD
c                   (    \ rS rSrSrSrSrSrSrSr	g)	ClientState   r                N)
__name__
__module____qualname____firstlineno__WaitingForDataWaitingForOkWaitingForRejectWaitingForAgreeUnixFDSuccess__static_attributes__r   r   r   r   r      s    NLGr   r   c                   (    \ rS rSrSrSS jrS rSrg)AuthenticationError&   z%Raised when DBus authentication failsc                     X l         Xl        g Nmsgdata)selfr0   r/   s      r   __init__AuthenticationError.__init__(   s    	r   c                 :    U R                    SU R                  < 3$ )Nz. Bus sent: r.   r1   s    r   __str__AuthenticationError.__str__,   s    ((<		}55r   )r0   r/   N)zAuthentication failed)r   r    r!   r"   __doc__r2   r6   r(   r   r   r   r*   r*   &   s    /6r   r*   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )FDNegotiationError/   zBRaised when file descriptor support is requested but not availablec                 "   > [         TU ]  USS9  g )Nz%File descriptor support not available)r/   )superr2   )r1   r0   	__class__s     r   r2   FDNegotiationError.__init__1   s    #JKr   r   )r   r    r!   r"   r8   r2   r(   __classcell__)r>   s   @r   r:   r:   /   s    LL Lr   r:   c                   `    \ rS rSrSrSS jr\S 5       rS rS\	\
   4S jrS rS	\
4S
 jrSrg)Authenticator5   a  Process data for the SASL authentication conversation

If enable_fds is True, this includes negotiating support for passing
file descriptors. If inc_null_byte is True, sends the ' ' byte
at the beginning of the negotiations, which was the past behavior,
but which prevents sending the SCM_CREDS ancillary data over the socket,
breaking authentication on *BSD; the caller should rather send that
null byte and ancillary data and pass inc_null_byte=False to prevent
it being done here.
c                     Xl         [        5       U l        U(       a  S[        5       -   U l        O[        5       U l        [
        R                  U l        S U l        g )N    )	
enable_fds	bytearraybufferr   _to_sendr   r$   stateerror)r1   rF   inc_null_bytes      r   r2   Authenticator.__init__@   sA    $k!$6$88DM.0DM --

r   c                 :    U R                   [        R                  L $ r-   )rJ   r   r'   r5   s    r   authenticatedAuthenticator.authenticatedJ   s    zz[0000r   c                 .    [        U R                  S 5      $ r-   )iterdata_to_sendr5   s    r   __iter__Authenticator.__iter__N   s    D%%t,,r   r   c                 t    U R                   (       d  U R                  (       a  gSU R                  sU l        nU$ )al  Get a line of data to send to the server

The data returned should be sent before waiting to receive data.
Returns empty bytes if waiting for more data from the server, and None
if authentication is finished (success or error).

Iterating over the Authenticator object will also yield these lines;
:meth:`feed` should be called with received data inside the loop.
Nr   )rO   rK   rI   )r1   to_sends     r   rS   Authenticator.data_to_sendQ   s-     !$dmmwr   c                    U R                   [        R                  L aT  UR                  S5      (       a=  U R                  (       a  [
        [        R                  4$ [        [        R                  4$ OZU R                   [        R                  L a=  UR                  S5      (       a  [        [        R                  4$ Xl	        [        U5      eXl	        [        U5      e)Ns   OK s   AGREE_UNIX_FD)rJ   r   r$   
startswithrF   NEGOTIATE_UNIX_FDr&   BEGINr'   rK   r:   r*   )r1   lines     r   process_lineAuthenticator.process_line`   s    ::111v&&??,k.O.OOO +"5"555	 ' ZZ;<<</00k1111 J$T**
!$''r   r0   c                 ~   U =R                   U-  sl         SU R                   ;   ai  U R                   R                  SS5      u  o l         U R                   (       a  [        U R                   S5      eU R                  U5      u  U l        U l        g[        U R                   5      S:  a  [        U R                   S5      eg)zProcess received data

Raises AuthenticationError if the incoming data is not as expected for
successful authentication. The connection should then be abandoned.
s   
r   zUnexpected data receivedi    z*Too much data received without line endingN)rH   splitr*   r^   rI   rJ   len)r1   r0   r]   s      r   feedAuthenticator.feedv   s     	tdkk! $ 1 1'1 =D+{{)$++7QRR(,(9(9$(?%DM4: $%I  %r   )rI   rH   rF   rK   rJ   N)FT)r   r    r!   r"   r8   r2   propertyrO   rT   r   bytesrS   r^   rc   r(   r   r   r   rB   rB   5   sF    	 1 1-huo (, r   rB   )binasciir   enumr   r
   typingr   rf   r   r   r\   r[   r   
ValueErrorr*   r:   rB   
SASLParserr   r   r   <module>rl      sq      	 -E -
,U 
, 	, $ 6* 6L, LW Wv 
r   