ok

Mini Shell

Direktori : /lib/python3.6/site-packages/josepy/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/josepy/__pycache__/jws.cpython-36.pyc

3

�}:aY7�@s�dZddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
mZGdd�d�ZGdd�dej
�ZGdd	�d	ej
�ZGd
d�dej
�ZGdd
�d
�Zedkr�eej��dS)zJSON Web Signature.�N)�b64�errors�	json_util�jwa�jwk�utilc@s,eZdZdZdZedd��Zedd��ZdS)�	MediaTypez MediaType field encoder/decoder.zapplication/cCs(d|kr$d|krtjd��|j|S|S)zDecoder.�/�;zUnexpected semi-colon)r�DeserializationError�PREFIX)�cls�value�r�/usr/lib/python3.6/jws.py�decodes


zMediaType.decodecCs.d|kr*|j|j�st�|t|j�d�S|S)zEncoder.r
N)�
startswithr�AssertionError�len)r
rrrr�encodeszMediaType.encodeN)�__name__�
__module__�__qualname__�__doc__r�classmethodrrrrrrrs
rc@seZdZdZejdejjdd�Z	ejddd�Z
ejdejjdd�Zejddd�Z
ejd	dd�Zejd
dfd�Zejdejdd�Zejd
ejdd�Zejdejejdd�Zejdejejdd�Zejddfd�Zdd�Zdd�Zdd�Zejdd��Zejdd��Zejdd��ZdS)�Headera6JOSE Header.

    .. warning:: This class supports **only** Registered Header
        Parameter Names (as defined in section 4.1 of the
        protocol). If you need Public Header Parameter Names (4.2)
        or Private Header Parameter Names (4.3), you must subclass
        and override :meth:`from_json` and :meth:`to_partial_json`
        appropriately.

    .. warning:: This class does not support any extensions through
        the "crit" (Critical) Header Parameter (4.1.11) and as a
        conforming implementation, :meth:`from_json` treats its
        occurrence as an error. Please subclass if you seek for
        a different behaviour.

    :ivar x5tS256: "x5t#S256"
    :ivar str typ: MIME Media Type, inc. :const:`MediaType.PREFIX`.
    :ivar str cty: Content-Type, inc. :const:`MediaType.PREFIX`.

    �algT)�decoder�	omitempty�jku)rr�kid�x5u�x5c)r�default�x5tzx5t#S256�typ)�encoderrr�cty�critcs�fdd��jj�D�S)z4Fields that would not be omitted in the JSON object.cs,i|]$\}}|jt�|��st�|�|�qSr)Zomit�getattr)�.0�nameZfield)�selfrr�
<dictcomp>Msz&Header.not_omitted.<locals>.<dictcomp>)�_fields�items)r,r)r,r�not_omittedKs
zHeader.not_omittedcCs^t|t|��s tdjt|����|j�}|j�}t|�j|�rFtd��|j|�t|�f|�S)NzHeader cannot be added to: {0}z+Addition of overlapping headers not defined)�
isinstance�type�	TypeError�formatr0�set�intersection�update)r,�otherZnot_omitted_selfZnot_omitted_otherrrr�__add__Qs
zHeader.__add__cCs|jdkrtjd��|jS)z�Find key based on header.

        .. todo:: Supports only "jwk" header parameter lookup.

        :returns: (Public) key found in the header.
        :rtype: .JWK

        :raises josepy.errors.Error: if key could not be found

        NzNo key found)rr�Error)r,rrr�find_key_s

zHeader.find_keycCstjd��dS)Nz("crit" is not supported, please subclass)rr)Zunused_valuerrrr(nszHeader.critcCsdd�|D�S)NcSs&g|]}tjtjjtjj|j���qSr)�base64�	b64encode�OpenSSL�cryptoZdump_certificate�
FILETYPE_ASN1�wrapped)r*�certrrr�
<listcomp>xszHeader.x5c.<locals>.<listcomp>r)rrrrr"vsz
Header.x5ccCsHytdd�|D��Stjjk
rB}ztj|��WYdd}~XnXdS)Ncss,|]$}tjtjjtjjtj|���VqdS)N)rZComparableX509r>r?Zload_certificater@r<�	b64decode)r*rBrrr�	<genexpr>~szHeader.x5c.<locals>.<genexpr>)�tupler>r?r:rr)r�errorrrrr"{s

N)rrrrr�Fieldr�JWASignature�	from_jsonrrr�JWKr r!r"�decode_b64joser$Zx5tS256rrrr%r'r(r0r9r;rr&rrrrr%s.

rcs�eZdZdZeZdZejdddd�Z	ejdde�ej
d�Zejd	ejej
d
�Ze	jdd��Z	e	jd
d��Z	�fdd�Zedd��Zedd��Zddd�Zede�fdd��Z�fdd�Ze�fdd��Z�ZS)�	SignatureaJWS Signature.

    :ivar combined: Combined Header (protected and unprotected,
        :class:`Header`).
    :ivar unicode protected: JWS protected header (Jose Base-64 decoded).
    :ivar header: JWS Unprotected Header (:class:`Header`).
    :ivar str signature: The signature.

    �combined�	protectedT�)rr#�header)rr#r�	signature)rr&cCstj|jd��S)Nzutf-8)r�encode_b64joser)rrrrrO�szSignature.protectedcCstj|�jd�S)Nzutf-8)rrLr)rrrrrO�scs4d|kr|j|�}t�jf|�|jjdk	s0t�dS)NrN)�_with_combined�super�__init__rNrr)r,�kwargs)�	__class__rrrV�s
zSignature.__init__cCsZd|kst�|jd|jdj�}|jd|jdj�}|rJ||jj|�}n|}||d<|S)NrNrQrO)r�getr.r#�
header_cls�
json_loads)r
rWrQrOrNrrrrT�szSignature._with_combinedcCstj|jd��dtj|�S)Nzutf-8�.)rr=r)r
rO�payloadrrr�_msg�szSignature._msgNcCs8|dkr|jj�n|}|jjj|j|j|j|j|�d�S)zEVerify.

        :param JWK key: Key used for verification.

        N)�key�sig�msg)rNr;r�verifyr_rRr^rO)r,r]r_rrrrb�szSignature.verifycKs�t||j�st�|}||d<|r,|j�|d<t|�j|jj�sBt�|j|jj�sTt�i}x"|D]}	|	|kr^|j|	�||	<q^W|r�|jf|�j	�}
nd}
|jf|�}	|j
|j|j|
|��}||
|	|d�S)z;Sign.

        :param JWK key: Key for signature.

        rrrP)rOrQrR)
r1�ktyr�
public_keyr5�issubsetrZr.�popZ
json_dumps�signr_r^)r
r]r_rZinclude_jwk�protectrWZ
header_paramsZprotected_paramsrQrOrRrrrrg�s"
zSignature.signcs t�j�}|dj�s|d=|S)NrQ)rU�fields_to_partial_jsonr0)r,�fields)rXrrri�s
z Signature.fields_to_partial_jsoncs4t�j|�}|j|�}d|dj�kr0tjd��|S)NrrNzalg not present)rU�fields_from_jsonrTr0rr)r
�jobjrjZfields_with_combined)rXrrrk�s


zSignature.fields_from_json)rN)N)rrrrrrZ�	__slots__rrHrOrJrQrLrSrRr&rrVrrTr^rb�	frozensetrgrirk�
__classcell__rr)rXrrM�s*	


rMc@sdeZdZdZdZeZddd�Zedd��Z	e
d	d
��Zdd�Zed
d��Z
ddd�Zedd��ZdS)�JWSzgJSON Web Signature.

    :ivar str payload: JWS Payload.
    :ivar str signature: JWS Signatures.

    r]�
signaturesNcst��fdd��jD��S)zVerify.c3s|]}|j�j��VqdS)N)rbr])r*r`)r_r,rrrEszJWS.verify.<locals>.<genexpr>)�allrq)r,r_r)r_r,rrbsz
JWS.verifycKs |||jjfd|i|��fd�S)zSign.r])r]rq)�
signature_clsrg)r
r]rWrrrrgszJWS.signcCst|j�dkst�|jdS)zPGet a singleton signature.

        :rtype: :class:`JWS.signature_cls`

        �r)rrqr)r,rrrrRsz
JWS.signaturecCs\t|j�dkst�d|jjj�ks&t�tj|jjj	d��dtj|j
�dtj|jj�S)z7Compact serialization.

        :rtype: bytes

        rtrzutf-8r\)rrqrrRrQr0rr=rOrr])r,rrr�
to_compacts&zJWS.to_compactcCshy|jd�\}}}Wntk
r2tjd��YnX|jtj|�jd�tj|�d�}|tj|�|fd�S)zACompact deserialization.

        :param bytes compact:

        r\zOCompact JWS serialization should comprise of exactly 3 dot-separated componentszutf-8)rOrR)r]rq)�split�
ValueErrorrrrsrrDr)r
�compactrOr]rRr`rrr�from_compact(szJWS.from_compactTcCsR|js
t�tj|j�}|rBt|j�dkrB|jdj�}||d<|S||jd�SdS)Nrtrr])r]rq)rqrrrSr]r�to_partial_json)r,Zflatr]�retrrrrz;s
zJWS.to_partial_jsoncsvd|krd|krtjd��nVd|krF�tj|jd���jj|�fd�S�tj|d�t�fdd�|dD��d�SdS)NrRrqzFlat mixed with non-flatr])r]rqc3s|]}�jj|�VqdS)N)rsrJ)r*r`)r
rrrERsz JWS.from_json.<locals>.<genexpr>)rrrrLrfrsrJrF)r
rlr)r
rrJIsz
JWS.from_json)r]rq)N)T)rrrrrmrMrsrbrrg�propertyrRruryrzrJrrrrrp�s


rpc@sZeZdZdZedd��Zedd��Zedd��Zedd	��Zed
d��Z	edd
d��Z
dS)�CLIzJWS CLI.cCs�|jjj|jj��}|jj�|jdkr.g|_|jr@|jjd�t	j
tjj�j
�||jt|j�d�}|jr~t|j�jd��nt|j��dS)zSign.Nr)r]r_rrhzutf-8)rrc�loadr_�read�closerhrx�appendrprg�sys�stdinrr5�printrurZjson_dumps_pretty)r
�argsr_r`rrrrgYs

zCLI.signcCs�|jrtjtjj�j��}n@ytjtjj��}Wn*tj	k
rZ}zt
|�dSd}~XnX|jdk	r�|jdk	stt
�|jj|jj��j�}|jj�nd}tjj|j�|j|d�S)zVerify.rtN)r_���)rxrpryr�r�rrr[rr:r�r_rcrr~rdr��stdout�writer]rb)r
r�r`rGr_rrrrbks
z
CLI.verifycCstjj|�S)N)rrIrJ)r
�argrrr�	_alg_type�sz
CLI._alg_typecCs|tjjkst�|S)N)rMrZr.r)r
r�rrr�_header_type�szCLI._header_typecCs|tjjkst�tjj|S)N)rrKZTYPESr)r
r�rrr�	_kty_type�sz
CLI._kty_typeNcCs�|dkrtjdd�}tj�}|jddd�|j�}|jd�}|j|jd�|jdd	tj	d
�dd�|jd
d|j
tjd�|jddd|j
d�|jd�}|j|jd�|jdd	tj	d
�dd�|jd|jdd�|j|�}|j|�S)z Parse arguments and sign/verify.Nrtz	--compact�
store_true)�actionrg)�funcz-kz--key�rbT)r2Zrequiredz-az--alg)r2r#z-pz	--protectr�)r�r2rbFz--kty)r��argv�argparse�ArgumentParser�add_argumentZadd_subparsersZ
add_parserZset_defaultsrgZFileTyper�rZRS256r�rbr��
parse_argsr�)r
r��parserZ
subparsersZparser_signZ
parser_verifyZparsedrrr�run�s*


zCLI.run)N)rrrrrrgrbr�r�r�r�rrrrr}Vsr}�__main__)rr�r<r�r>ZjosepyrrrrrrrZJSONObjectWithFieldsrrMrpr}r�exitr�rrrr�<module>s `r_V

Zerion Mini Shell 1.0