
    \Ah                        S SK r S SKr S SKJr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Jr  S\R&                  4S	 jrSS
 jrS rS rS rSS jrS rS rS rS rS rSS jrg! \ a    S SKJrJr   Nkf = f)    N)IterableMapping)r   r   )jwk)Key)
ALGORITHMS)JWSErrorJWSSignatureError)base64url_decodebase64url_encodec                     U[         R                  ;  a  [        SU-  5      e[        X2S9n[	        U 5      n[        XEX15      nU$ )a3  Signs a claims set and returns a JWS string.

Args:
    payload (str or dict): A string to sign
    key (str or dict): The key to use for signing the claim set. Can be
        individual JWK or JWK set.
    headers (dict, optional): A set of headers that will be added to
        the default headers.  Any headers that are added as additional
        headers will override the default headers.
    algorithm (str, optional): The algorithm to use for signing the
        the claims.  Defaults to HS256.

Returns:
    str: The string representation of the header, claims, and signature.

Raises:
    JWSError: If there is an error signing the token.

Examples:

    >>> jws.sign({'a': 'b'}, 'secret', algorithm='HS256')
    'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhIjoiYiJ9.jiMyrsmD8AoHWeQgmxZ5yq8z0lXS67_QGs52AzC8Ru8'

zAlgorithm %s not supported.)additional_headers)r   	SUPPORTEDr   _encode_header_encode_payload_sign_header_and_claims)payloadkeyheaders	algorithmencoded_headerencoded_payloadsigned_outputs          OC:\Users\julio\Documents\inmobiliaria_backend\env\Lib\site-packages\jose/jws.pysignr      sI    4 
,,,4y@AA#IJN%g.O+NY\M    c                 J    [        U 5      u  pEpgU(       a  [        XdXqU5        U$ )ao  Verifies a JWS string's signature.

Args:
    token (str): A signed JWS to be verified.
    key (str or dict): A key to attempt to verify the payload with. Can be
        individual JWK or JWK set.
    algorithms (str or list): Valid algorithms that should be used to verify the JWS.

Returns:
    str: The str representation of the payload, assuming the signature is valid.

Raises:
    JWSError: If there is an exception verifying a token.

Examples:

    >>> token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhIjoiYiJ9.jiMyrsmD8AoHWeQgmxZ5yq8z0lXS67_QGs52AzC8Ru8'
    >>> jws.verify(token, 'secret', algorithms='HS256')

)_load_verify_signature)tokenr   
algorithmsverifyheaderr   signing_input	signatures           r   r!   r!   4   s&    , 16e-F]-LNr   c                 "    [        U 5      u  pp4U$ )a  Returns the decoded headers without verification of any kind.

Args:
    token (str): A signed JWS to decode the headers from.

Returns:
    dict: The dict representation of the token headers.

Raises:
    JWSError: If there is an exception decoding the token.
r   r   r"   claimsr#   r$   s        r   get_unverified_headerr)   R        05U|,FMMr   c                     [        U 5      $ )aW  Returns the decoded headers without verification of any kind.

This is simply a wrapper of get_unverified_header() for backwards
compatibility.

Args:
    token (str): A signed JWS to decode the headers from.

Returns:
    dict: The dict representation of the token headers.

Raises:
    JWSError: If there is an exception decoding the token.
)r)   )r   s    r   get_unverified_headersr,   b   s     !''r   c                 "    [        U 5      u  pp4U$ )a  Returns the decoded claims without verification of any kind.

Args:
    token (str): A signed JWS to decode the headers from.

Returns:
    str: The str representation of the token claims.

Raises:
    JWSError: If there is an exception decoding the token.
r&   r'   s        r   get_unverified_claimsr.   t   r*   r   c                     SU S.nU(       a  UR                  U5        [        R                  " USSS9R                  S5      n[	        U5      $ )NJWT)typalg,:T)
separators	sort_keysutf-8)updatejsondumpsencoder   )r   r   r"   json_headers       r   r   r      sN    9-F()** fWo	  K((r   c                     [        U [        5      (       a%   [        R                  " U SS9R	                  S5      n [        U 5      $ ! [
         a     Nf = f)Nr3   )r6   r8   )
isinstancer   r:   r;   r<   
ValueErrorr   )r   s    r   r   r      sW    '7##	jj% fWo  G$$  		s   $A 
AAc                 8   SR                  X/5      n [        U[        5      (       d  [        R                  " X25      nUR                  U5      n[        U5      nSR                  XU/5      nUR                  S5      $ ! [         a  n[        U5      eS nAff = f)N   .r8   )
joinr?   r   r   	constructr   	Exceptionr   r   decode)	r   encoded_claimsr   r   r#   r$   eencoded_signatureencoded_strings	            r   r   r      s    II~>?M#s##--/CHH]+	 )3YY@QRSN  ))  qks   <A? ?
B	BBc                    [        U [        5      (       a  U R                  S5      n  U R                  SS5      u  pUR	                  SS5      u  p4[        U5      n [        R                  " UR                  S5      5      n[        U[        5      (       d  [        S5      e [        U5      n [        U5      n	XhX4$ ! [         a    [        S5      e[        [        R                  4 a    [        S5      ef = f! [         a  n[        SU-  5      eS nAff = f! [        [        R                  4 a    [        S5      ef = f! [        [        R                  4 a    [        S	5      ef = f)
Nr8   rB      zNot enough segmentszInvalid header paddingzInvalid header string: %sz,Invalid header string: must be a json objectzInvalid payload paddingzInvalid crypto padding)r?   strr<   rsplitsplitr
   r@   r   	TypeErrorbinasciiErrorr:   loadsrF   r   )
jwtr#   crypto_segmentheader_segmentclaims_segmentheader_datar"   rH   r   r$   s
             r   r   r      s^   #sjj!1(+

4(;%)6)<)<T1)E&&~68K..w78 fg&&EFF2">21$^4	 ]66/  .,--x~~& 1/001
  82Q6778 x~~& 20112
 x~~& 1/001s;   3B= %C: "D .E =:C7:
DDD&E &E)c                     U  HG  n[        U[        5      (       d  [        R                  " XC5      n UR	                  X5      (       a    gMI     g! [
         a     MY  f = f)NTF)r?   r   r   rD   r!   rE   )keysr#   r$   r2   r   s        r   _sig_matches_keysr[      s\    #s##--)C	zz-33 4	    		s   A
AAc                    [        U [        5      (       a  U 4$  [        R                  " U [        [        S9n [        U [        5      (       a0  SU ;   a  U S   $ SU ;   a  U 4$ U R                  5       nU(       a  U$ U 4$ [        U [        5      (       a,  [        U [        5      (       d  [        U [        5      (       d  U $ U 4$ ! [
         a     Nf = f)N)	parse_intparse_floatrZ   kty)
r?   r   r:   rS   rM   rE   r   valuesr   bytes)r   r`   s     r   	_get_keysrb      s    #svjj= #wS=v;c\6M ZZ\F6M 
C	"	"JsC,@,@JsTYDZDZ
 v/  s   C 
CCc                    UR                  S5      nU(       d  [        S5      eUb  XT;  a  [        S5      e[        U5      n [        X`X%5      (       d
  [	        5       eg ! [         a    [        S5      e[         a    [        SU-  5      ef = f)Nr2   z-No algorithm was specified in the JWS header.z&The specified alg value is not allowedzSignature verification failed.z$Invalid or unsupported algorithm: %s)getr   rb   r[   r	   )r#   r"   r$   r   r    r2   rZ   s          r   r   r      s    
**U
CFGG#"7?@@S>DE iEE#%% F 9788 E=CDDEs   A -B)T)N) N) rQ   r:   collections.abcr   r   ImportErrorcollectionsjoser   jose.backends.baser   jose.constantsr   jose.exceptionsr   r	   
jose.utilsr
   r   HS256r   r!   r)   r,   r.   r   r   r   r   r[   rb   r    r   r   <module>rp      s     .1  " % 7 9  $z/?/? !H< ($ )
%* 7B	@Eo  .--.s   A- -A>=A>