o
    £i=hB  ã                   @   sl   d dl mZmZ d dlZd dlZd dlZd dlZddlmZm	Z	m
Z
mZ dd„ Zdd„ Zd	d
„ Zdd„ ZdS )é    )Úabsolute_importÚprint_functionNé   )ÚDecodeErrorÚ__version__ÚdecodeÚencodec              	   C   sä   | j d u r	tdƒ‚i }| jD ]U}| dd¡\}}|dkr8|d dkr8t|ƒdkr8ttt ¡ t|dd … ƒ ƒƒ}| ¡ rAt|ƒ}nzt	|ƒ}W n	 tyP   Y nw ddd d	œ}||v r_|| }|||< qt
|| j | jd
�}| d¡S )Nz4Key is required when encoding. See --help for usage.ú=r   Úexpr   ú+TF)ÚtrueÚfalseÚnull)ÚkeyÚ	algorithmúutf-8)r   Ú
ValueErrorÚpayloadÚsplitÚlenÚstrÚintÚtimeÚisdigitÚfloatr   r   r   )Úargsr   ÚargÚkÚvÚ	constantsÚtoken© r!   úD/var/www/html/loop/venv/lib/python3.10/site-packages/jwt/__main__.pyÚencode_payload   s0   

  
ÿ
ý
r#   c              
   C   s~   z,| j r| j }ntj ¡ rtj ¡  ¡ }ntdƒ‚| d¡}t|| j	| j
d�}t |¡W S  ty> } ztd| ƒ‚d }~ww )Nz*Cannot read from stdin: terminal not a TTYr   )r   Úverifyz)There was an error decoding the token: %s)r    ÚsysÚstdinÚisattyÚreadlineÚstripÚIOErrorr   r   r   r$   ÚjsonÚdumpsr   )r   r    ÚdataÚer!   r!   r"   Údecode_payload7   s   

€ÿr/   c                  C   sÒ   d} t jd| d�}|jddddt d� |jd	d
dd dd� |jdddddd� |jdddd�}|jddd�}d}|jdd|d� |jtd� |jdd d�}|jd!d"d#d$� |jd%d&d'd(d)d*d+� |jtd� |S ),Na  
    Encodes or decodes JSON Web Tokens based on input.

    %(prog)s [options] <command> [options] input

    Decoding examples:

    %(prog)s --key=secret decode json.web.token
    %(prog)s decode --no-verify json.web.token

    Encoding requires the key option and takes space separated key/value pairs
    separated by equals (=) as input. Examples:

    %(prog)s --key=secret encode iss=me exp=1302049071
    %(prog)s --key=secret encode foo=bar exp=+10

    The exp key is special and can take an offset to current Unix time.
    Úpyjwt)ÚprogÚusagez-vz	--versionÚversionz	%(prog)s )Úactionr3   z--keyr   ÚKEYzset the secret key to sign with)ÚdestÚmetavarÚdefaultÚhelpz--algr   ÚALGÚHS256z0set crypto algorithm to sign with. default=HS256zPyJWT subcommandszvalid subcommandszadditional help)ÚtitleÚdescriptionr9   r   z use to encode a supplied payload)r9   zfPayload to encode. Must be a space separated list of key/value
    pairs separated by equals (=) sign.r   r   )Únargsr9   )Úfuncr   z'use to decode a supplied JSON web tokenr    zJSON web token to decode.ú?)r9   r>   z-nz--no-verifyÚstore_falser$   Tz2ignore signature and claims verification on decode)r4   r6   r8   r9   )	ÚargparseÚArgumentParserÚadd_argumentr   Úadd_subparsersÚ
add_parserÚset_defaultsr#   r/   )r2   Ú
arg_parserÚ
subparsersÚencode_parserÚpayload_helpÚdecode_parserr!   r!   r"   Úbuild_argparserJ   s`   þýûûýýûrM   c               
   C   sl   t ƒ } z|  tjdd … ¡}| |¡}t|ƒ W d S  ty5 } ztd|ƒ |  ¡  W Y d }~d S d }~ww )Nr   zThere was an unforseen error: )rM   Ú
parse_argsr%   Úargvr?   ÚprintÚ	ExceptionÚ
print_help)rH   Ú	argumentsÚoutputr.   r!   r!   r"   Úmain�   s   

€þrU   )Ú
__future__r   r   rB   r+   r%   r   Ú r   r   r   r   r#   r/   rM   rU   r!   r!   r!   r"   Ú<module>   s   *S