
    wg\j                     ,   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 r	S r
S rS r " S	 S
\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r\" SS5      r " S S\5      rg)    N)urlsafe_b64decodeurlsafe_b64encode)
namedtuple)MutableMappingc                     [        U [        5      (       d  U R                  S5      n [        U 5      nUR	                  S5      R                  S5      $ )Nutf-8=)
isinstancebytesencoder   decoderstrip)payloadr   s     J/home/edenadmin/noVNC/venv/lib/python3.13/site-packages/jwcrypto/common.pybase64url_encoder      sA    gu%%..)w'F==!((--    c                     [        U 5      S-  nUS:X  a  U S-  n OUS:X  a  U S-  n OUS:w  a  [        S5      e[        U R                  S5      5      $ )	N      z==   r	   r   zInvalid base64 stringr   )len
ValueErrorr   r   )r   sizes     r   base64url_decoder      sW    w<!Dqy4	3	011W^^G455r   c                 z    [        U [        5      (       a  U R                  S5      n [        R                  " U SSS9$ )Nr   ),:T)
separators	sort_keys)r
   r   r   jsondumpsstrings    r   json_encoder$   !   s0    &%  w'::ftDDr   c                 z    [        U [        5      (       a  U R                  S5      n [        R                  " U 5      $ )Nr   )r
   r   r   r    loadsr"   s    r   json_decoder'   '   s,    &%  w'::fr   c                       \ rS rSrSrg)JWException-    N)__name__
__module____qualname____firstlineno____static_attributes__r+   r   r   r)   r)   -   s    r   r)   c                   ,   ^  \ rS rSrSU 4S jjrSrU =r$ )InvalidJWAAlgorithm1   c                 N   > SnU(       a  USU-  -  n[         [        U ]  U5        g )NzInvalid JWA Algorithm namez (%s))superr2   __init__selfmessagemsg	__class__s      r   r6   InvalidJWAAlgorithm.__init__2   s*    *7W$$C!41#6r   r+   N)r,   r-   r.   r/   r6   r0   __classcell__r;   s   @r   r2   r2   1   s    7 7r   r2   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )InvalidCEKeyLength9   ztInvalid CEK Key Length.

This exception is raised when a Content Encryption Key does not match
the required length.
c                 8   > SX4-  n[         [        U ]  U5        g )Nz&Expected key of length %d bits, got %d)r5   rA   r6   r8   expectedobtainedr:   r;   s       r   r6   InvalidCEKeyLength.__init__@   s     6(9MM $05r   r+   r,   r-   r.   r/   __doc__r6   r0   r>   r?   s   @r   rA   rA   9   s    6 6r   rA   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )InvalidJWEOperationE   zzInvalid JWS Object.

This exception is raised when a requested operation cannot
be execute due to unsatisfied conditions.
c                 x   > S nU(       a  UnOSnU(       a  US[        U5      -  -  n[        [        U ]  U5        g NzUnknown Operation Failurez {%s})reprr5   rK   r6   r8   r9   	exceptionr:   r;   s       r   r6   InvalidJWEOperation.__init__L   s;    C-C7T)_,,C!41#6r   r+   NNrH   r?   s   @r   rK   rK   E   s    7 7r   rK   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )InvalidJWEKeyTypeW   zInvalid JWE Key Type.

This exception is raised when the provided JWK Key does not match
the type required by the specified algorithm.
c                 @   > SU< SU< 3n[         [        U ]  U5        g )NzExpected key type z, got )r5   rU   r6   rD   s       r   r6   InvalidJWEKeyType.__init__^   s    08(C/4r   r+   rH   r?   s   @r   rU   rU   W   s    5 5r   rU   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )InvalidJWEKeyLengthc   zInvalid JWE Key Length.

This exception is raised when the provided JWK Key does not match
the length required by the specified algorithm.
c                 8   > SX4-  n[         [        U ]  U5        g )Nz!Expected key of length %d, got %d)r5   rZ   r6   rD   s       r   r6   InvalidJWEKeyLength.__init__j   s     1X4HH!41#6r   r+   rH   r?   s   @r   rZ   rZ   c   s    7 7r   rZ   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )InvalidJWSERegOperationo   zInvalid JWSE Header Registry Operation.

This exception is raised when there is an error in trying to add a JW
Signature or Encryption header to the Registry.
c                 x   > S nU(       a  UnOSnU(       a  US[        U5      -  -  n[        [        U ]  U5        g rN   )rO   r5   r_   r6   rP   s       r   r6    InvalidJWSERegOperation.__init__v   s;    C-C7T)_,,C%t5c:r   r+   rS   rH   r?   s   @r   r_   r_   o   s    ; ;r   r_   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )JWKeyNotFound   zThe key needed to complete the operation was not found.

This exception is raised when a JWKSet is used to perform
some operation and the key required to successfully complete
the operation is not found.
c                 D   > U(       a  UnOSn[         [        U ]  U5        g )NzKey Not Found)r5   rd   r6   r7   s      r   r6   JWKeyNotFound.__init__   s    C!CmT+C0r   r+   r=   rH   r?   s   @r   rd   rd      s    1 1r   rd   	Parameterz*description mustprotect supported check_fnc                   B    \ rS rSrSS jrS rS rS rS rS r	S	 r
S
rg)JWSEHeaderRegistry   Nc                     U(       a<  [        U[        5      (       a  [        R                  " U5      U l        O[        S5      e0 U l        [        R                  " U 5        g )NzUnknown input type)r
   dictcopydeepcopy	_registryr_   r   r6   )r8   init_registrys     r   r6   JWSEHeaderRegistry.__init__   sC    -..!%}!=-.BCCDN%r   c                     XR                   ;  a  [        SU-  5      eU R                   U   nUR                  c  gUR                  U5      $ )Nz No header "%s" found in registryT)rp   r_   check_fn)r8   hvalueparams       r   check_headerJWSEHeaderRegistry.check_header   sP    NN")*L,-+. / / q!>>!>>%((r   c                 8    U R                   R                  U5      $ r=   )rp   __getitem__r8   keys     r   r{   JWSEHeaderRegistry.__getitem__   s    ~~))#..r   c                 6    U R                   R                  5       $ r=   )rp   __iter__r8   s    r   r   JWSEHeaderRegistry.__iter__   s    ~~&&((r   c                     U R                   U   R                  (       d  U R                   U   R                  (       a  [        S5      eU R                   R	                  U5        g )Nz-Unable to delete protected or supported field)rp   mustprotect	supportedr_   __delitem__r|   s     r   r   JWSEHeaderRegistry.__delitem__   sL    >>#**>>#(() +< = = NN&&s+r   c                    XR                   ;   ae  U R                   U   nUR                  (       a  [        S5      eUR                  (       a  UR                  (       d  [        S5      eU R                   U	 X R                   U'   g )Nz+Supported header already exists in registryz,Header specified should bea protected header)rp   r   r_   r   )r8   ru   jwse_header_paramps       r   __setitem__JWSEHeaderRegistry.__setitem__   sr    q!A{{- /= > >'8'D'D- /C D D NN1%-qr   c                 6    U R                   R                  5       $ r=   )rp   __len__r   s    r   r   JWSEHeaderRegistry.__len__   s    ~~%%''r   )rp   r=   )r,   r-   r.   r/   r6   rx   r{   r   r   r   r   r0   r+   r   r   rj   rj      s%    	&	)/),.(r   rj   )rn   r    base64r   r   collectionsr   collections.abcr   r   r   r$   r'   	Exceptionr)   r2   rA   rK   rU   rZ   r_   rd   JWSEHeaderParameterrj   r+   r   r   <module>r      s      7 " *.6E	) 	7+ 7	6 	67+ 7$	5 	5	7+ 	7;k ;$1K 1( !!MO 5( 5(r   