
    Pqh                         d dl Z d dlZd dlZd dlZd dlZ ej
                  e      Zd Z G d de	      Z
 G d de	      Z G d de
      Ze
ZeZej                  e_        y)	    Nc                 :    	 | j                  d      S #  | cY S xY w)Nzutf-8)encoding)encode)raws    Y/srv/www/ollama/chat-ollama/venv/lib/python3.12/site-packages/msal/oauth2cli/assertion.py
_str2bytesr      s$    zz7z++
s    c                   "    e Zd Z	 	 ddZ	 ddZy)AssertionCreatorNc                     t        d      )a+  Create an assertion in bytes, based on the provided claims.

        All parameter names are defined in https://tools.ietf.org/html/rfc7521#section-5
        except the expires_in is defined here as lifetime-in-seconds,
        which will be automatically translated into expires_at in UTC.
        z Will be implemented by sub-class)NotImplementedError)	selfaudienceissuersubject
expires_at
expires_in	issued_atassertion_idkwargss	            r   create_normal_assertionz(AssertionCreator.create_normal_assertion   s     ""DEE    c                 J     t        |||||f fd	t        |dz
  d            S )zCreate an assertion as a callable,
        which will then compute the assertion later when necessary.

        This is a useful optimization to reuse the client assertion.
        c                 2     j                   | ||fd|i|S )Nr   )r   )aiser   r   s        r   <lambda>z@AssertionCreator.create_regenerative_assertion.<locals>.<lambda>'   s&    ,,,Q1MMfM r   <   r   )r   )AutoRefreshermax)r   r   r   r   r   r   s   `     r   create_regenerative_assertionz.AssertionCreator.create_regenerative_assertion   s1     7j N:b=!,. 	.r   )NX  NN)Nr#   )__name__
__module____qualname__r   r"    r   r   r
   r
      s    IL)-	F >A
.r   r
   c                       e Zd ZdZddZd Zy)r    a  Cache the output of a factory, and auto-refresh it when necessary. Usage::

        r = AutoRefresher(time.time, expires_in=5)
        for i in range(15):
            print(r())  # the timestamp change only after every 5 seconds
            time.sleep(1)
    c                 .    || _         || _        i | _        y )N)_factory_expires_in_buf)r   factoryr   s      r   __init__zAutoRefresher.__init__4   s    %	r   c                 J   d\  }}t        j                          }| j                  j                  |d      |k  r<t        j	                  d       || j                         ||| j                  z   i| _        nt        j	                  d       | j                  j                  |      S )N)r   valuer   zRegenerating new assertionzReusing still valid assertion)timer,   getloggerdebugr*   r+   )r   
EXPIRES_ATVALUEnows       r   __call__zAutoRefresher.__call__8   s|    1
Eiik99==Q'3.LL56S4CSCS=STDILL89yy}}U##r   N)i  )r$   r%   r&   __doc__r.   r8   r'   r   r   r    r    ,   s    $r   r    c                   "    e Zd ZddZ	 	 	 ddZy)JwtAssertionCreatorNc                     || _         || _        |xs i | _        |rDt        j                  t        j                  |            j                         | j                  d<   yy)a  Construct a Jwt assertion creator.

        Args:

            key (str):
                An unencrypted private key for signing, in a base64 encoded string.
                It can also be a cryptography ``PrivateKey`` object,
                which is how you can work with a previously-encrypted key.
                See also https://github.com/jpadilla/pyjwt/pull/525
            algorithm (str):
                "RS256", etc.. See https://pyjwt.readthedocs.io/en/latest/algorithms.html
                RSA and ECDSA algorithms require "pip install cryptography".
            sha1_thumbprint (str): The x5t aka X.509 certificate SHA-1 thumbprint.
            headers (dict): Additional headers, e.g. "kid" or "x5c" etc.
        x5tN)key	algorithmheadersbase64urlsafe_b64encodebinasciia2b_hexdecode)r   r>   r?   sha1_thumbprintr@   s        r   r.   zJwtAssertionCreator.__init__D   sV      "}""(":":  1#33968 LL r   c
           	         ddl }t        j                         }|||xs ||xs ||z   |xs ||xs t        t        j                               d}|r||d<   |j                  |	xs i        	 |j                  || j                  | j                  | j                        }t        |      S #  | j                  j                  d      s| j                  j                  d      rt        j                  d        xY w)	zCreate a JWT Assertion.

        Parameters are defined in https://tools.ietf.org/html/rfc7523#section-3
        Key-value pairs in additional_claims will be added into payload as-is.
        r   N)audisssubexpiatjtinbf)r?   r@   RSESzSome algorithms requires "pip install cryptography". See https://pyjwt.readthedocs.io/en/latest/installation.html#cryptographic-dependencies-optional)jwtr1   struuiduuid4updater   r>   r?   r@   r   
startswithr3   	exception)r   r   r   r   r   r   r   r   
not_beforeadditional_claimsr   rQ   r7   payloadstr_or_bytess                  r   r   z+JwtAssertionCreator.create_normal_assertion[   s     	iik$f3#
"2#43tzz|#4 'GEN(.B/		::T^^T\\ & SLl++	~~((.$..2K2KD2Q  wx s   -=B+ +AC9)NN)NNr#   NNNN)r$   r%   r&   r.   r   r'   r   r   r;   r;   C   s    <0 OR:>"r   r;   )r1   rC   rA   rS   logging	getLoggerr$   r3   r   objectr
   r    r;   Signer	JwtSignerr   sign_assertionr'   r   r   <module>rb      sm         
		8	$.v .2$F $.7* 7v 
	.FF	 r   