+
    P(i5                         ^ RI Ht ^ RI Ht ^ RI Ht ^ RI Ht ^ RIHt ^ RIHt ^ RIHt ^ RIH	t	 ^ R	IH
t
 ^ R
IHt ^ RIHt ^ RIHt ^ RIHt ^RIHt ^RIHt  ! R R4      tR tR tR tR# )    )json_b64encode)to_bytes)
to_unicode)urlsafe_b64encode)BadSignatureError)DecodeError)#InvalidCritHeaderParameterNameErrorInvalidHeaderParameterNameError)MissingAlgorithmError)UnsupportedAlgorithmError)ensure_dict)extract_header)extract_segment)	JWSHeader)	JWSObjectc                      a  ] tR t^t o ]! . RO4      tRt/ tRR lt]	R 4       t
R tRR ltR tRR ltR	 tRR
 ltR tR tR tR tR tV 3R ltRtV tR# )JsonWebSignaturei  Nc                    W n         Wn        R # N)_private_headers_algorithms)self
algorithmsprivate_headerss   &&&^/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/authlib/jose/rfc7515/jws.py__init__JsonWebSignature.__init__*   s     /%    c                    V'       d   VP                   R 8w  d   \        RV: 24      hWP                  VP                  &   R# )JWSzInvalid algorithm for JWS, N)algorithm_type
ValueErrorALGORITHMS_REGISTRYname)cls	algorithms   &&r   register_algorithm#JsonWebSignature.register_algorithm.   s7    I44=:9-HII2;	/r   c                V   \        VR4      pV P                  V4       V P                  V4       V P                  WV4      w  rS\	        VP
                  4      p\        \        V4      4      pRP                  Wg.4      p\        VP                  W4      4      p	RP                  WgV	.4      # )a  Generate a JWS Compact Serialization. The JWS Compact Serialization
represents digitally signed or MACed content as a compact, URL-safe
string, per `Section 7.1`_.

.. code-block:: text

    BASE64URL(UTF8(JWS Protected Header)) || '.' ||
    BASE64URL(JWS Payload) || '.' ||
    BASE64URL(JWS Signature)

:param protected: A dict of protected header
:param payload: A bytes/string of payload
:param key: Private key used to generate signature
:return: byte
N   .)
r   _validate_private_headers_validate_crit_headers_prepare_algorithm_keyr   	protectedr   r   joinsign)
r   r/   payloadkey
jws_headerr'   protected_segmentpayload_segmentsigning_input	signatures
   &&&&      r   serialize_compact"JsonWebSignature.serialize_compact4   s      y$/
&&y1##I.44YM	*:+?+?@+HW,=> 		#4"FG%inn]&HI	yy+iHIIr   c                   \        V4      V P                  8  d   \        R4      h \        V4      pVP	                  R^4      w  rEVP                  R^4      w  rg\        T4      p	T P                  T	4       \        T	R4      p
\        T4      pT'       d	   T! T4      p\        T4      p\        YR4      pT P                  YT4      w  rTP                  YLT4      '       d   T# \        T4      h  \         d   p\        R4      ThRp?ii ; i)a  Exact JWS Compact Serialization, and validate with the given key.
If key is not provided, the returned dict will contain the signature,
and signing input values. Via `Section 7.1`_.

:param s: text of JWS Compact Serialization
:param key: key used to verify the signature
:param decode: a function to decode payload data
:return: JWSObject
:raise: BadSignatureError

.. _`Section 7.1`: https://tools.ietf.org/html/rfc7515#section-7.1
zSerialization is too long.r+   zNot enough segmentsNcompact)lenMAX_CONTENT_LENGTHr#   r   rsplitsplitr   _extract_headerr-   r   _extract_payload_extract_signaturer   r.   verifyr   )r   sr3   decoder7   signature_segmentr5   r6   excr/   r4   r2   r8   rvr'   s   &&&&           r   deserialize_compact$JsonWebSignature.deserialize_compactQ   s    q6D+++9::	>A/0xxa/@,M1>1D1DT11M. $$56	##I.y$/
"?3WoG&'89	zI644Z#N	Mc::I##!  	>34#=	>s   3C- -D	8DD	c                2  a aaa \        S4      oVVVV 3R lp\        V\        4      '       d-   V! \        P                  ! V4      4      p\        S4      VR&   V# V Uu. uF  qd! \        P                  ! V4      4      NK   	  ppR\        S4      RV/# u upi )a.  Generate a JWS JSON Serialization. The JWS JSON Serialization
represents digitally signed or MACed content as a JSON object,
per `Section 7.2`_.

:param header_obj: A dict/list of header
:param payload: A string/dict of payload
:param key: Private key used to generate signature
:return: JWSObject

Example ``header_obj`` of JWS JSON Serialization::

    {
        "protected: {"alg": "HS256"},
        "header": {"kid": "jose"}
    }

Pass a dict to generate flattened JSON Serialization, pass a list of
header dict to generate standard JSON Serialization.
c                   < S
P                  V 4       S
P                  V P                  4       S
P                  V P                  4       S
P                  V SS4      w  r\        V P                  4      pR P                  VS	.4      p\        VP                  WB4      4      pR\        V4      R\        V4      /pV P                  e   V P                  VR&   V# )r+   r/   r8   header)r,   _reject_unprotected_critrN   r-   r/   r.   r   r0   r   r1   r   )r4   _alg_keyr5   r7   r8   rI   r3   r2   r6   r   s   &      r   _sign.JsonWebSignature.serialize_json.<locals>._sign   s    **:6 ))**;*;<''
(<(<=44Z#NJD .z/C/C D II'8/&JKM)$))M*HII Z(9:Z	2B   ,)008Ir   r2   
signatures)r   
isinstancedictr   	from_dictr   )	r   
header_objr2   r3   rR   datahrT   r6   s	   f&ff    @r   serialize_jsonJsonWebSignature.serialize_jsonw   s    ( )1	 	* j$'',,Z89D(9DOK=GHZeI//23Z
H:o6jQQ Is   $Bc                   \        VR4      pVP                  R4      pVf   \        R4      h\        V4      p\	        V4      pV'       d	   V! V4      pRV9  d6   V P                  WEW4      w  rg\        WeR4      pV'       d   V# \        V4      h. p	Rp
VR,           F4  pV P                  WEW4      w  rgV	P                  V4       V'       d   K2  Rp
K6  	  \        WR4      pV
'       d   V# \        V4      h)	a  Exact JWS JSON Serialization, and validate with the given key.
If key is not provided, it will return a dict without signature
verification. Header will still be validated. Via `Section 7.2`_.

:param obj: text of JWS JSON Serialization
:param key: key used to verify the signature
:param decode: a function to decode payload data
:return: JWSObject
:raise: BadSignatureError

.. _`Section 7.2`: https://tools.ietf.org/html/rfc7515#section-7.2
r!   r2   zMissing "payload" valuerT   flatTFjson)	r   getr   r   rB   _validate_json_jwsr   r   append)r   objr3   rF   r6   r2   r4   validrI   headersis_validrX   s   &&&&        r   deserialize_json!JsonWebSignature.deserialize_json   s     #u%''),"788"?3"?3WoGs" $ 7 7#!J :7B	#B''l++J $ 7 7*!J NN:&5  , w0I##r   c                    \        V\        \        34      '       d   V P                  WV4      # RV9   d   V P                  WV4      # V P	                  WV4      # )a  Generate a JWS Serialization. It will automatically generate a
Compact or JSON Serialization depending on the given header. If a
header is in a JSON header format, it will call
:meth:`serialize_json`, otherwise it will call
:meth:`serialize_compact`.

:param header: A dict/list of header
:param payload: A string/dict of payload
:param key: Private key used to generate signature
:return: byte/dict
r/   )rU   listtupler[   r9   )r   rN   r2   r3   s   &&&&r   	serializeJsonWebSignature.serialize   sV     ftUm,,&&v<<& &&v<<%%fs;;r   c                   \        V\        4      '       d   V P                  WV4      # \        V4      pVP	                  R4      '       d*   VP                  R4      '       d   V P                  WV4      # V P                  WV4      # )a  Deserialize JWS Serialization, both compact and JSON format.
It will automatically deserialize depending on the given JWS.

:param s: text of JWS Compact/JSON Serialization
:param key: key used to verify the signature
:param decode: a function to decode payload data
:return: dict
:raise: BadSignatureError

If key is not provided, it will still deserialize the serialization
without verification.
   {   })rU   rV   rg   r   
startswithendswithrJ   )r   rE   r3   rF   s   &&&&r   deserializeJsonWebSignature.deserialize   sp     a((88QK<<!**T"2"2((88''77r   c                t   R V9  d   \        4       hVR ,          pW@P                  9  d   \        4       hV P                  V,          pV P                  f   VP                  '       d   \        4       hMW@P                  9  d   \        4       h\        V4      '       d	   V! W4      pVP                  V4      pWS3# )alg)r   r$   r   r   
deprecatedcallableprepare_key)r   rN   r2   r3   rv   r'   s   &&&&  r   r.   'JsonWebSignature._prepare_algorithm_key  s    '))Um...+--,,S1	####/11 $(((+--C==f&C##C(~r   c                    V P                   eR   V P                  P                  4       pVP                  V P                   4      pV F  pW29  g   K  \	        V4      h	  R # R # r   )r   !REGISTERED_HEADER_PARAMETER_NAMEScopyunionr   )r   rN   namesks   &&  r   r,   *JsonWebSignature._validate_private_headers  sW       ,::??AEKK 5 56E>9!<< 	 -r   c                >    V'       d   RV9   d   \        R4      hR# R# )uG   Reject 'crit' when found in the unprotected header (RFC 7515 §4.1.11).critNr
   )r   unprotected_headers   &&r   rO   )JsonWebSignature._reject_unprotected_crit"  s     &,>">1&99 #?r   c                   R V9   d   VR ,          p\        V\        4      '       d;   \        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       g   \        R 4      hV P                  P                  4       pV P                  '       d   VP                  V P                  4      pV F%  pWC9  d   \        V4      hWA9  g   K  \        V4      h	  R# R# )r   c              3   B   "   T F  p\        V\        4      x  K  	  R # 5ir   )rU   str).0xs   & r   	<genexpr>:JsonWebSignature._validate_crit_headers.<locals>.<genexpr>+  s      =,8q
1c""Ls   FTN)	rU   rj   allr   r|   r}   r   r~   r	   )r   rN   crit_headersr   r   s   &&   r   r-   'JsonWebSignature._validate_crit_headers'  s    V!&>LlD11 =,8= =,8= : : 6f==::??AE$$$D$9$9:!>=a@@_=a@@	 " r   c                @   VP                  R 4      pV'       g   \        R4      hVP                  R4      pV'       g   \        R4      h\        V4      p\        V4      pVP                  R4      pV'       d"   \	        V\
        4      '       g   \        R4      hV P                  V4       V P                  V4       \        Wx4      p	V P                  WV4      w  rRP                  WQ.4      p\        \        V4      4      pV
P                  WV4      '       d   V	R3# V	R3# )	r/   zMissing "protected" valuer8   zMissing "signature" valuerN   zInvalid "header" valuer+   TF)r`   r   r   rA   rU   rV   rO   r-   r   r.   r0   rC   rD   )r   r6   r2   rX   r3   r5   rG   r/   rN   r4   r'   r7   r8   s   &&&&&        r   ra   #JsonWebSignature._validate_json_jws8  s   &NN;7 9::&NN;7 9::$%67#$56	)*VT22677 	%%f-
 	##I.y1
44Z#N			#4"FG&x0A'BC	Mc::t##5  r   c                &   < V ^8  d   Qh/ S[ ;R&   # )   r>   )int)format__classdict__s   "r   __annotate__JsonWebSignature.__annotate__   s     $ $% r   )r   r   )rv   jkujwkkidx5ux5cx5tzx5t#S256typctyr   )NNr   )__name__
__module____qualname____firstlineno__	frozensetr|   r>   r$   r   classmethodr(   r9   rJ   r[   rg   rl   rs   r.   r,   rO   r-   ra   __annotate_func____static_attributes____classdictcell__)r   s   @r   r   r      s     (1	
)%  % & < <
J:$$L1Rf0$d<$8*(	=:
A"!K	  r   r   c                 "    \        V \        4      # r   )r   r   )header_segments   &r   rA   rA   W  s    .+66r   c                 $    \        V \        R 4      # )r8   r   r   )rG   s   &r   rC   rC   [  s    ,k;GGr   c                 $    \        V \        R 4      # )r2   r   )r6   s   &r   rB   rB   _  s    ?KCCr   N)authlib.common.encodingr   r   r   r   authlib.jose.errorsr   r   r	   r   r   r   authlib.jose.utilr   r   r   modelsr   r   r   rA   rC   rB    r   r   <module>r      sP    2 , . 5 1 + C ? 5 9 ) , -  A! A!H
7HDr   