
    kKj2                         d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZmZ ddl	m
Z
 ddlmZmZmZ eeef   Zddedee   dz  d	efd
Z G d ded      Z G d d      Z G d de      Zded	efdZd	efdZy)    N)JSONEncoder)	TypedDictAnyCallable   )to_bytes)MissingClaimErrorInvalidClaimErrorExpiredTokenErrorclaimsencoder_clsreturnc                     dD ]T  }| j                  |      }t        |t        j                        s/t        j                  |j                               | |<   V t        j                  | dd|      }t        |      S )zTurn claims into bytes payload.)expiatnbfF),:)ensure_ascii
separatorscls)	get
isinstancedatetimecalendartimegmutctimetuplejsondumpsr   )r   r   kclaimcontents        h/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/joserfc/_rfc7519/claims.pyconvert_claimsr$      sf    "

1eX../ (:(:(<=F1I #
 jje
P[\GG    c                   ~    e Zd ZU eed<   edz  ed<   eez  ez  ed<   eeez  ez     ee   z  ee   z  ee   z  ed<   y)ClaimsOption	essentialNallow_blankvaluevalues)__name__
__module____qualname__bool__annotations__strintlist r%   r#   r'   r'      sO    O9tsT!"T#Y.c:T$ZGGr%   r'   F)totalc                   f    e Zd ZdZdefdZedee   fd       Z	dede
ddfd	Zd
eee
f   ddfdZy)BaseClaimsRegistryz6Requesting "claims" for JWT with the given conditions.kwargsc                     || _         y N)options)selfr8   s     r#   __init__zBaseClaimsRegistry.__init__'   s	    r%   r   c                 ~    | j                   D ch c]#  }| j                   |   j                  d      s"|% c}S c c}w )z"Returns the essential claim names.r(   )r;   r   )r<   keys     r#   essential_keysz!BaseClaimsRegistry.essential_keys*   s6      $||R|t||C/@/D/D[/Q|RRRs   #::
claim_namer*   Nc                 d   | j                   j                  |      }|sy|j                  d      }|sddg i fv rt        |      |j                  d      }||j                  d      }||g}|syt        t              r t        fd|D              st        |      y|vrt        |      y)a,  
        Validates a given claim value based on predefined options.

        :param claim_name: The name of the claim to validate.
        :param value: The value of the claim to be validated.
        :raises InvalidClaimError: If the value does not meet the claim's validation requirements.
        Nr)    r+   r*   c              3   &   K   | ]  }|v  
 y wr:   r4   ).0vr*   s     r#   	<genexpr>z1BaseClaimsRegistry.check_value.<locals>.<genexpr>J   s     9=aqEz=s   )r;   r   r
   r   r3   any)r<   rA   r*   optionr)   option_valuesoption_values     `    r#   check_valuezBaseClaimsRegistry.check_value/   s     !!*-jj/ur2r(::#J//

8, !::g.L'!-eT"9=99'
33 : M)'
33 *r%   r   c                 >   | j                   D ch c]  }|j                  |      | }}|r#t        dj                  t	        |                  |D ]C  }||   }t        | d|z   d      }|r	 ||       #|| j                  v s2| j                  ||       E yc c}w )a<  
        Validates the provided claims against specified requirements and checks.

        :param claims: A dictionary containing claims to validate.
        :raises InvalidClaimError: Raised if any claim fails validation.
        :raises MissingClaimError: Raised if one or more essential keys are missing.
        Nr   	validate_)r@   r   r	   joinsortedgetattrr;   rL   )r<   r   r?   missed_keysr*   funcs         r#   validatezBaseClaimsRegistry.validateP   s     '+&9&9U&9sVZZ_=Ts&9U#CHHVK-@$ABBC3KE4s!2D9DU$  e, 	 Vs
   BB)r,   r-   r.   __doc__r'   r=   propertysetr1   r@   r   rL   dictrT   r4   r%   r#   r7   r7   $   si    @  SC S S4c 4# 4$ 4B-tCH~ -$ -r%   r7   c            	            e Zd ZdZddeeg ef   z  dz  dededdf fdZedefd       Z	d	eddfd
Z
d	eddfdZd	eddfdZ xZS )JWTClaimsRegistryzA claims registry for validating JWT claims.

    :param now: timestamp of "now" time
    :param leeway: leeway time in seconds
    :param kwargs: claims options
    Nnowleewayr8   r   c                 P    |t         }|| _        || _        t        |   di | y )Nr4   )_generate_now_nowr\   superr=   )r<   r[   r\   r8   	__class__s       r#   r=   zJWTClaimsRegistry.__init__m   s+    ;C	"6"r%   c                 d    t        | j                        r| j                         S | j                  S )zReturns the current timestamp.)callabler_   )r<   s    r#   r[   zJWTClaimsRegistry.nowt   s&     DII99;yyr%   r*   c                     t        |      st        dd      || j                  | j                  z
  k  rt	        d      | j                  d|       y)a  The "exp" (expiration time) claim identifies the expiration time on
        or after which the JWT MUST NOT be accepted for processing.  The
        processing of the "exp" claim requires that the current date/time
        MUST be before the expiration date/time listed in the "exp" claim.
        Implementers MAY provide for some small leeway, usually no more than
        a few minutes, to account for clock skew.  Its value MUST be a number
        containing a NumericDate value.  Use of this claim is OPTIONAL.
        r   z'Claim 'exp' must be a NumericDate valueN)_validate_numeric_timer
   r[   r\   r   rL   r<   r*   s     r#   validate_expzJWTClaimsRegistry.validate_exp{   sJ     &e,#E+TUUDHHt{{*+#E**&r%   c                     t        |      st        dd      || j                  | j                  z   kD  rt        dd      | j	                  d|       y)a  The "nbf" (not before) claim identifies the time before which the JWT
        MUST NOT be accepted for processing.  The processing of the "nbf"
        claim requires that the current date/time MUST be after or equal to
        the not-before date/time listed in the "nbf" claim.  Implementers MAY
        provide for some small leeway, usually no more than a few minutes, to
        account for clock skew.  Its value MUST be a number containing a
        NumericDate value.  Use of this claim is OPTIONAL.
        r   z'Claim 'nbf' must be a NumericDate valuezThe token is not yet validNre   r
   r[   r\   rL   rf   s     r#   validate_nbfzJWTClaimsRegistry.validate_nbf   sM     &e,#E+TUUDHHt{{*+#E+GHH&r%   c                     t        |      st        dd      || j                  | j                  z   kD  rt        dd      | j	                  d|       y)a  The "iat" (issued at) claim identifies the time at which the JWT was
        issued.  This claim can be used to determine the age of the JWT.  Its
        value MUST be a number containing a NumericDate value.  Use of this
        claim is OPTIONAL.
        r   z'Claim 'iat' must be a NumericDate valuez"The token was issued in the futureNri   rf   s     r#   validate_iatzJWTClaimsRegistry.validate_iat   sM     &e,#E+TUUDHHt{{*+#E+OPP&r%   )Nr   )r,   r-   r.   rU   r2   r   r'   r=   rV   r[   rg   rj   rl   __classcell__)ra   s   @r#   rZ   rZ   e   s    #C(2s7"33d: #3 #^j #os # S  '# '$ ''# '$ '
'# 
'$ 
'r%   rZ   sc                 .    t        | t        t        f      S r:   )r   r2   float)rn   s    r#   re   re      s    a#u&&r%   c                  <    t        t        j                               S r:   )r2   timer4   r%   r#   r^   r^      s    tyy{r%   r:   )rr   r   r   r   r   typingr   r   r   utilr   errorsr	   r
   r   rX   r1   Claimstypebytesr$   r'   r7   rZ   r2   r/   re   r^   r4   r%   r#   <module>ry      s         + +   
c3h6 [0AD0H TY H9E H>- >-B>'* >'B'c 'd 's r%   