o
    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!   T/var/www/html/magazine_api/magazine_env/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.
    Zpyjwt)progusagez-vz	--versionversionz	%(prog)s )actionr2   z--keyr   ZKEYzset the secret key to sign with)destmetavardefaulthelpz--algr   ZALGZHS256z0set crypto algorithm to sign with. default=HS256zPyJWT subcommandszvalid subcommandszadditional help)titledescriptionr7   r   z use to encode a supplied payload)r7   zfPayload to encode. Must be a space separated list of key/value
    pairs separated by equals (=) sign.r   r   )nargsr7   )funcr   z'use to decode a supplied JSON web tokenr    zJSON web token to decode.?)r7   r:   z-nz--no-verifystore_falser$   Tz2ignore signature and claims verification on decode)r3   r4   r6   r7   )	argparseArgumentParseradd_argumentr   add_subparsers
add_parserset_defaultsr#   r/   )r1   
arg_parserZ
subparsersZencode_parserZpayload_helpZdecode_parserr!   r!   r"   build_argparserJ   s`   rE   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: )rE   
parse_argsr%   argvr;   print	Exception
print_help)rD   	argumentsoutputr.   r!   r!   r"   main   s   

rM   )
__future__r   r   r>   r+   r%   r    r   r   r   r   r#   r/   rE   rM   r!   r!   r!   r"   <module>   s   *S