
    0j:                         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d Z	 G d de
          Z G d de
          Z G d d	e          ZeZeZej        e_        dS )
    Nc                 B    	 |                      d          S #  | cY S xY w)Nzutf-8)encoding)encode)raws    `/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/msal/oauth2cli/assertion.py
_str2bytesr      s-    zz7z+++


s    c                 r    t          j        t          j        |                                                     S N)base64urlsafe_b64encodebinasciia2b_hexdecode)
thumbprints    r   _encode_thumbprintr      s*    #H$4Z$@$@AAHHJJJ    c                   $    e Zd Z	 	 ddZ	 ddZdS )AssertionCreatorNX  c                      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Er   c                 Z     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                 (     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MMfMM r   <   r   )r   )AutoRefreshermax)r   r   r   r   r   r    s   `     r   create_regenerative_assertionz.AssertionCreator.create_regenerative_assertion!   sV     7j N N N N N:b=!,,. . . 	.r   )Nr   NN)Nr   )__name__
__module____qualname__r!   r,    r   r   r   r      sL        IL)-	F 	F 	F 	F >A
. 
. 
. 
. 
. 
.r   r   c                        e Zd ZdZddZd ZdS )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                 0    || _         || _        i | _        d S r
   )_factory_expires_in_buf)r   factoryr   s      r   __init__zAutoRefresher.__init__6   s    %			r   c                 X   d\  }}t          j                     }| j                            |d          |k    r@t                              d           ||                                 ||| j        z   i| _        nt                              d           | j                            |          S )N)r   valuer   zRegenerating new assertionzReusing still valid assertion)timer6   getloggerdebugr4   r5   )r   
EXPIRES_ATVALUEnows       r   __call__zAutoRefresher.__call__:   s    1
Eikk9==Q''3..LL5666S4CS=STDIILL8999y}}U###r   N)r2   )r-   r.   r/   __doc__r8   rB   r0   r   r   r*   r*   .   sA            $ $ $ $ $r   r*   c                   ,    e Zd Z	 ddddZ	 	 	 ddZdS )JwtAssertionCreatorN)sha256_thumbprintc                    || _         || _        |pi | _        |rt          |          | j        d<   |rt          |          | j        d<   dS dS )a6  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.
            sha256_thumbprint (str): The x5t#S256 aka X.509 certificate SHA-256 thumbprint.
        zx5t#S256x5tN)key	algorithmheadersr   )r   rI   rJ   sha1_thumbprintrK   rF   s         r   r8   zJwtAssertionCreator.__init__F   sj    * "}" 	M'9:K'L'LDL$ 	F"4_"E"EDL	F 	Fr   r   c
           	         ddl }t          j                    }|||p||p||z   |p||pt          t          j                              d}|r||d<   |                    |	pi            	 |                    || j        | j        | j	                  }t          |          S #  | j                            d          s| j                            d          rt                              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)rJ   rK   RSESzSome algorithms requires "pip install cryptography". See https://pyjwt.readthedocs.io/en/latest/installation.html#cryptographic-dependencies-optional)jwtr;   struuiduuid4updater   rI   rJ   rK   r   
startswithr=   	exception)r   r   r   r   r   r   r   r   
not_beforeadditional_claimsr    rW   rA   payloadstr_or_bytess                  r   r!   z+JwtAssertionCreator.create_normal_assertionc   s$    	


ikk$f3#
"2#43tz||#4#4   	('GEN(.B///		::T^T\ & S SLl+++	~((.. x$.2K2KD2Q2Q x  wx x x s   )6B   AC1)NN)NNr   NNNN)r-   r.   r/   r8   r!   r0   r   r   rE   rE   E   sa        <@F F F F F F< OR:>"     r   rE   )r;   r   r   rY   logging	getLoggerr-   r=   r   r   objectr   r*   rE   Signer	JwtSignerr!   sign_assertionr0   r   r   <module>rh      s        
	8	$	$  K K K. . . . .v . . .2$ $ $ $ $F $ $ $.= = = = =* = = =B 
	.F	   r   