dbfdg 3 kZ@slddlmZmZddlZddlZddlZddlZddlmZm Z m Z m Z ddZ ddZ d d Zd d ZdS) )absolute_importprint_functionN) DecodeError __version__decodeencodec Cs|jdkrtdi}x|jD]}|jdd\}}|dkrr|ddkrrt|dkrrtttjt|dd}|jrt|}n"y t |}Wntk rYnXdddd }||kr||}|||<qWt ||j|j d }|j d S) Nz4Key is required when encoding. See --help for usage.=rZexpr+TF)trueZfalseZnull)key algorithmzutf-8) r ValueErrorpayloadsplitlenstrinttimeisdigitfloatrr r)argsrargkvZ constantstokenr/usr/lib/python3.6/__main__.pyencode_payload s,         rcCsyV|jr|j}n"tjjr*tjjj}ntd|jd}t||j |j d}t j |St k r}zt d|WYdd}~XnXdS)Nz*Cannot read from stdin: terminal not a TTYzutf-8)r verifyz)There was an error decoding the token: %s)rsysstdinisattyreadlinestripIOErrorrrr rjsondumpsr)rrdataerrrdecode_payload7s   r*cCsd}tjd|d}|jddddtd|jd d d dd d |jdddddd |jdddd}|jddd}d}|jdd|d|jtd|jdd d}|jd!d"d#d$|jd%d&d'd(d)d*d+|jtd|S),Na Encodes or decodes JSON Web Tokens based on input. %(prog)s [options] [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. Zpyjwt)progusagez-vz --versionversionz %(prog)s )actionr-z--keyr ZKEYzset the secret key to sign with)destmetavardefaulthelpz--algr ZALGZHS256z0set crypto algorithm to sign with. default=HS256zPyJWT subcommandszvalid subcommandszadditional help)title descriptionr2rz use to encode a supplied payload)r2zfPayload to encode. Must be a space separated list of key/value pairs separated by equals (=) sign.rr )nargsr2)funcrz'use to decode a supplied JSON web tokenrzJSON web token to decode.?)r2r5z-nz --no-verifyZ store_falserTz2ignore signature and claims verification on decode)r.r/r1r2) argparseArgumentParser add_argumentrZadd_subparsersZ add_parserZ set_defaultsrr*)r, arg_parserZ subparsersZ encode_parserZ payload_helpZ decode_parserrrrbuild_argparserJsR   r<cCsjt}y*|jtjdd}|j|}t|Wn4tk rd}ztd||jWYdd}~XnXdS)NrzThere was an unforseen error: )r< parse_argsr argvr6print ExceptionZ print_help)r;Z argumentsoutputr)rrrmains   rB)Z __future__rrr8r&r rrrrrrr*r<rBrrrrs*S