%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/josepy/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/josepy/__pycache__/jws.cpython-312.pyc

�

���e�<��n�dZddlZddlZddlZddlmZmZmZmZm	Z	m
Z
mZmZm
Z
ddlmZddlZddlmZmZmZmZddlmZddlmZGd�d	�ZGd
�dej2�ZGd�d
ej2�ZGd�dej2�ZGd�d�Zedk(reejA��yy)zJSON Web Signature.�N)	�Any�Dict�	FrozenSet�List�Mapping�Optional�Tuple�Type�cast)�crypto)�b64�errors�	json_util�jwa)�jwk)�utilc�J�eZdZdZdZ	ededefd��Zededefd��Zy)�	MediaTypez MediaType field encoder/decoder.zapplication/�value�returnc�^�d|vr(d|vrtjd��|j|zS|S)zDecoder.�/�;zUnexpected semi-colon)r�DeserializationError�PREFIX��clsrs  �,/usr/lib/python3/dist-packages/josepy/jws.py�decodezMediaType.decodes9���e���e�|��1�1�2I�J�J��:�:��%�%���c�x�d|vr5|j|j�sJ�|t|j�dS|S)zEncoder.rN)�
startswithr�lenrs  r�encodezMediaType.encode)s?���e���#�#�C�J�J�/�/�/���S�Z�Z��*�+�+��r N)	�__name__�
__module__�__qualname__�__doc__r�classmethod�strrr$�r rrrsO��*�
�F�2���3��3������3��3���r rc��eZdZUdZej
dejjd��Z	e
ejed<ej
dd��Ze
e
ed<ej
dejjd��Ze
ejed<ej
dd��Ze
eed<ej
d	d��Ze
e
ed	<ej
d
dd��Zeej.d
fed
<ej
dej0d��Ze
e
ed<ej
dej0d��Ze
e
ed<ej
dej8ej:d��Ze
eed<ej
dej8ej:d��Ze
eed<ej
ddd��Z ee!d
fed<e"eejFfed<de"eejFffd�Z$de!ddfd�Z%de&jfd�Z'e jPde!de!fd��Z ejRd��ZejPd��Zy) �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)r0r�kid�x5u�x5cr+�r0�default.�x5tzx5t#S256�x5tS256�typ)�encoderr/r0�cty�crit�_fieldsrc
��|jj�D��cic]-\}}|jt||��s
|t||���/c}}Scc}}w)z4Fields that would not be omitted in the JSON object.)r=�items�omit�getattr)�self�name�fields   r�not_omittedzHeader.not_omitted`sT�� $�|�|�1�1�3�
���e��:�:�g�d�D�1�2�
�'�$��%�%�
�	
��
s�2A�otherc�@�t|t|��s#tdjt|����|j	�}|j	�}t|�j
|�rtd��|j|�t|�di|��S)NzHeader cannot be added to: {0}z+Addition of overlapping headers not definedr+)�
isinstance�type�	TypeError�formatrE�set�intersection�update)rBrF�not_omitted_self�not_omitted_others    r�__add__zHeader.__add__hs����%��d��,��<�C�C�D��K�P�Q�Q��+�+�-��!�-�-�/���� �-�-�.?�@��I�J�J���� 1�2��t�D�z�-�,�-�-r c�\�|j�tjd��|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

        zNo key found)rr�Error�rBs r�find_keyzHeader.find_keyus&���8�8���,�,�~�.�.��x�x�r �unused_valuec�,�tjd��)Nz("crit" is not supported, please subclass)rr)rVs rr<zHeader.crit�s���)�)�*T�U�Ur c	��|D�cgc]C}tjtjtj|j
����Ec}Scc}w�N)�base64�	b64encoder�dump_certificate�
FILETYPE_ASN1�wrapped)r�certs  rr4z
Header.x5c�sF���
��
���V�4�4�V�5I�5I�4�<�<�X�Y�
�	
��
s�AAc��	td�|D��S#tj$r}tj|��d}~wwxYw)Nc	3�K�|]N}tjtjtjtj|������Py�wrY)r�ComparableX509r�load_certificater]rZ�	b64decode)�.0r_s  r�	<genexpr>zHeader.x5c.<locals>.<genexpr>�sG�������#�#��+�+�F�,@�,@�&�BR�BR�SW�BX�Y���s�AA)�tuplerrSrr)r�errors  rr4z
Header.x5c�sJ��	5���"�	��
���|�|�	5��-�-�e�4�4��	5�s��A�<�AN)*r%r&r'r(rrDr�JWASignature�	from_jsonr.r�__annotations__r1�bytes�jwk_mod�JWKrr2r*r3r4r	rrb�decode_b64joser7r8rr$rr9r;r<rr�FieldrErQ�josepyrUr/r:r+r rr-r-3sn���*'6�i�o�o�
�s�'�'�1�1�T�'�C��#�"�"�	#��+�9�?�?�5�D�A�C��%��A�!0����
�w�{�{�,�,��"�C��'�+�+�	��)�����$�?�C��#��?�*�9�?�?�5�D�A�C��%��A�+:�9�?�?�5�D�Z\�+]�C��t�"�"�C�'�	(�]�*�9�?�?�5�)�:R�:R�^b�c�C��%��c�.�y����I�4�4�� �G�X�e�_�� /�y���
�y�'�'��1A�1A�T� �C��)�	�� /�y���
�y�'�'��1A�1A�T� �C��)�	��,�I�O�O�F�d�B�O�D�%��S��/�O�
�#�y���&�
'�'�
�T�#�y���"6�7�
�.�S�.�X�.�
�&�*�*�
�
�\�\�V�3�V�3�V��V�
	�[�[�
��
�	�[�[�	5��	5r r-c���eZdZUdZeZeed<dZejddd��Z
eed<ejdde�ej�	�Z
eed<ejd
ejej��Zeed
<e
j$ded
efd��Z
e
j&ded
efd��Z
ded
df�fd�Zeded
eeeffd��Zededed
efd��Zddedeej8d
efd�Zede�fdedej8dej@dede!ded
dfd��Z"d
eeeff�fd�Z#ede$eefd
eeeff�fd��Z%�xZ&S) �	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)rt�	protectedT�r5�header)r0r6r/�	signature)r/r:rrc�J�tj|jd��S�N�utf-8)r�encode_b64joser$�rs rruzSignature.protected�s���'�'����W�(=�>�>r c�J�tj|�jd�Srz)rrorr}s rruzSignature.protected�s���'�'��.�5�5�g�>�>r �kwargsNc�~��d|vr|j|�}t�|�di|��|jj�J�y)Nrtr+)�_with_combined�super�__init__rtr.)rBr�	__class__s  �rr�zSignature.__init__�sA����V�#��(�(��0�F�
���"�6�"��}�}� � �,�,�,r c��d|vsJ�|jd|jdj�}|jd|jdj�}|r||jj	|�z}n|}||d<|S)Nrtrwru)�getr=r6�
header_cls�
json_loads)rrrwrurts     rr�zSignature._with_combined�s~����'�'�'����H�c�k�k�(�&;�&C�&C�D���J�J�{�C�K�K��,D�,L�,L�M�	������ 9� 9�)� D�D�H��H�%��z���
r �payloadc�|�tj|jd��dztj|�zS)Nr{�.)r
r[r$)rrur�s   r�_msgzSignature._msg�s/���}�}�Y�-�-�g�6�7�$�>����w�AW�W�Wr �keyc�@�|�|jj�n|}|jjstjd��|jjj|j|j|j|j|���S)zvVerify.

        :param bytes payload: Payload to verify.
        :param JWK key: Key used for verification.

        z Not signature algorithm defined.)r��sig�msg)
rtrUr.rqrS�verifyr�rxr�ru)rBr�r��
actual_keys    rr�zSignature.verify�s{��>A�[����!7�!7�!9�c�
��}�}� � ��,�,�A�B�B��}�}� � �'�'����D�N�N��	�	�$�.�.�RY�8Z�(�
�	
r r.�include_jwk�protectc�8�t||j�sJ�|}||d<|r|j�|d<t|�j	|j
j�sJ�|j	|j
j�sJ�i}|D]}	|	|vs�|j|	�||	<�|r!|j
di|��j�}
nd}
|j
di|��}	|j|j|j|
|��}||
|	|��S)aDSign.

        :param bytes payload: Payload to sign.
        :param JWK key: Key for signature.
        :param JWASignature alg: Signature algorithm to use to sign.
        :param bool include_jwk: If True, insert the JWK inside the signature headers.
        :param FrozenSet protect: List of headers to protect.

        r.rrv)rurwrxr+)rH�kty�
public_keyrL�issubsetr�r=�pop�
json_dumps�signr�r�)rr�r�r.r�r�r�
header_params�protected_paramsrwrurxs            rr�zSignature.sign�s��&�#�s�w�w�'�'�'��
�"�
�e���#&�>�>�#3�M�%� ��=�!�*�*�3�>�>�+A�+A�B�B�B������� 6� 6�7�7�7����	E�F���&�+8�+<�+<�V�+D� ��(�	E��&����:�)9�:�E�E�G�I��I�����0�-�0���H�H�S�W�W�c�h�h�y�'�&B�C�	��Y�v��K�Kr c�P��t�|��}|dj�s|d=|S)Nrw)r��fields_to_partial_jsonrE)rB�fieldsr�s  �rr�z Signature.fields_to_partial_jsons.�����/�1���h��+�+�-��x� ��
r �jobjc���t�|�|�}|j|�}d|dj�vrt	j
d��|S)Nr.rtzalg not present)r��fields_from_jsonr�rErr)rr�r��fields_with_combinedr�s    �rr�zSignature.fields_from_jsonsR�����)�$�/��"�1�1�&�9���,�Z�8�D�D�F�F��-�-�.?�@�@�#�#r rY)'r%r&r'r(r-r�rk�	__slots__rrDrur*rjrwror|rxrlr:r/rr�r)rr�r�rrqrn�boolr��	frozensetrirr�r�rr��
__classcell__)r�s@rrsrs�s"�����J����I�$�Y�_�_�[�D�"�M�I�s�M�$�Y�_�_��D�*�,�
�@T�@T��F�F��'�y����Y�5�5�y�?W�?W��I�u�����?��?��?��?����?��?��?��?�-��-��-���C��D��c��N�����X�S�X�5�X�U�X��X�
�e�
�(�6�:�:�*>�
�$�
��!�&�[�
(L��(L��Z�Z�(L��
 �
 �	(L�
�(L��
(L��(L�
�(L��(L�T��S�#�X����$�G�C��H�$5�$�$�s�C�x�.�$��$r rsc��eZdZUdZdZeed<eeed<eZ	dde
ejde
fd�Zeded	eddfd
��Zedefd��Zdefd�Zed
eddfd��Zdde
deeeffd�Zedeeefddfd��Zy)�JWSzgJSON Web Signature.

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

    �r��
signaturesr�r�Nr�rc�D���t��fd��jD��S)�Verify.c3�V�K�|] }|j�j�����"y�wrY)r�r�)rer�r�rBs  ��rrfzJWS.verify.<locals>.<genexpr>.s �����L�S�3�:�:�d�l�l�C�0�L�s�&))�allr�)rBr�s``rr�z
JWS.verify,s����L�D�O�O�L�L�Lr rc�P�|||jjdd|i|��f��S)�Sign.r�r�r+)�
signature_clsr�)rr�rs   rr�zJWS.sign0s1���7�0F��0A�0A�0F�0F�0a�w�0a�Z`�0a�/c�d�dr c�T�t|j�dk(sJ�|jdS)zPGet a singleton signature.

        :rtype: :class:`JWS.signature_cls`

        �r)r#r�rTs rrxz
JWS.signature5s*���4�?�?�#�q�(�(�(����q�!�!r c��t|j�dk(sJ�d|jjj	�vsJ�tj|jjjd��dztj|j�zdztj|jj�zS)z7Compact serialization.

        :rtype: bytes

        r�r.r{r�)
r#r�rxrwrEr
r[rur$r�rTs r�
to_compactzJWS.to_compact?s����4�?�?�#�q�(�(�(��D�N�N�1�1�=�=�?�?�?�?�
�M�M�$�.�.�2�2�9�9�'�B�C��
��m�m�D�L�L�)�
*��
��m�m�D�N�N�4�4�5�	
6�	
r �compactc�>�	|jd�\}}}|j	tj|�jd�tj|���}|tj|�|f��S#t$rtjd��wxYw)zACompact deserialization.

        :param bytes compact:

        r�zOCompact JWS serialization should comprise of exactly 3 dot-separated componentsr{)rurxr�)�split�
ValueErrorrrr�r
rdr)rr�rur�rxr�s      r�from_compactzJWS.from_compactRs���	�,3�M�M�$�,?�)�I�w�	�����m�m�I�.�5�5�g�>�#�-�-�Xa�Jb� �
���3�=�=��1�s�f�E�E���	��-�-�d��
�	�s�A=�=B�flatc��|jsJ�tj|j�}|r<t	|j�dk(r$|jdj�}||d<|S||jd�S)Nr�rr�r�)r�rr|r�r#�to_partial_json)rBr�r��rets    rr�zJWS.to_partial_jsonesp��������*�*�4�<�<�8���C����(�A�-��/�/�!�$�4�4�6�C�$�C�	�N��J�#�"�o�o��
r r�c���d|vrd|vrtjd��d|vrc|j�D��cic]\}}|dk7s�||��}}}�tj|d��j
j
|�f��S�tj|d�t�fd�|dD����Scc}}w)Nrxr�zFlat mixed with non-flatr�r�c3�T�K�|]}�jj|����!y�wrY)r�rj)rer�rs  �rrfz JWS.from_json.<locals>.<genexpr>�s"����� `�c��!2�!2�!<�!<�S�!A� `�s�%()rrr?rror�rjrg)rr�r�r�filtereds`    rrjz
JWS.from_jsonss�����$��<�4�#7��-�-�.H�I�I�
�D�
 �59�Z�Z�\�V�z�s�E�S�I�EU��U�
�V�H�V��!�0�0��i��A��-�-�7�7��A�C��
�
�!�0�0��i��A� � `�T�R^�M_� `�`��
��
Ws�
B;�B;rY)T)r%r&r'r(r�rlrkrrsr�rrqrnr�r�r)rr��propertyrxr�r�rr*r�rrjr+r rr�r�s���*�I�
�N��Y����M�M�(�6�:�:�.�M�$�M��e�5�e�C�e�E�e��e��"�9�"��"�
�E�
�&�F�5�F�U�F��F�$�D��D��c��N���
�W�S�#�X�.�
�5�
��
r r�c��eZdZdZedejddfd��Zedejdefd��Z	ede
dejfd��Z
ede
de
fd	��Zede
deej"fd
��Zeddeeedeefd��Zy)
�CLIzJWS CLI.�argsrNc��|jjj|jj	��}|jj�|j�g|_|jr|jjd�tjtjj	�j�||jt|j���}|jr)t|j!�j#d��yt|j%��y)r�Nr.)r�r�r.r�r{)r.r��loadr��read�closer�r��appendr�r��sys�stdinr$rL�printr�r�json_dumps_pretty)rr�r�r�s    rr�zCLI.sign�s����h�h�l�l������
�
��0���������<�<���D�L��<�<��L�L����&��h�h��I�I�N�N�$�+�+�-�3�D�H�H�c�RV�R^�R^�N_��
���<�<��#�.�.�"�)�)�'�2�3��#�'�'�)�*r c���|jr@tjtjj�j
��}n@	tttjtjj���}|j�j|j�J�|jj|jj��j�}|jj!�nd}tj"j%|j&j)��|j+|��S#tj$r}t|�Yd}~yd}~wwxYw)r�NF)r�)r�r�r�r�r�r�r$rr�rrSr�r�r�r�r�r��stdout�writer�rr�)rr�r�rhr�s     rr�z
CLI.verify�s����<�<��"�"�3�9�9�>�>�#3�#:�#:�#<�=�C�
��3����s�y�y�~�~�/?� @�A��
�8�8���8�8�'�'�'��(�(�-�-����
�
��0�;�;�=�C��H�H�N�N���C��
�
������+�+�-�.��:�:�#�:�&�&�&���<�<�
��e����
�s�?E�E7�"E2�2E7�argc�@�tjj|�SrY)rrirj�rr�s  r�	_alg_typez
CLI._alg_type�s�����)�)�#�.�.r c�B�|tjjvsJ�|SrY)rsr�r=r�s  r�_header_typezCLI._header_type�s!���i�*�*�2�2�2�2�2��
r c�x�|tjjvsJ�tjj|SrY)rmrn�TYPESr�s  r�	_kty_typez
CLI._kty_type�s/���g�k�k�'�'�'�'�'��{�{� � ��%�%r c��|�tjdd}tj�}|j	dd��|j�}|j
d�}|j|j��|j	dd	tjd
�d��|j	d
d|jtj��|j	ddd|j��|j
d�}|j|j��|j	dd	tjd
�d��|j	d|jd��|j!|�}|j#|�S)z Parse arguments and sign/verify.Nr�z	--compact�
store_true)�actionr�)�funcz-kz--key�rbT)rI�requiredz-az--alg)rIr6z-pz	--protectr�)r�rIr�Fz--kty)r��argv�argparse�ArgumentParser�add_argument�add_subparsers�
add_parser�set_defaultsr��FileTyper�r�RS256r�r�r��
parse_argsr�)rr��parser�
subparsers�parser_sign�
parser_verify�parseds       r�runzCLI.run�sK���<��8�8�A�B�<�D��(�(�*�����K���=��*�*�,�
� �+�+�F�3��� � �c�h�h� �/�� � ��w�X�5F�5F�t�5L�W[� �\�� � ��w�S�]�]�C�I�I� �V�� � ��{�8�#�JZ�JZ� �[�"�-�-�h�7�
��"�"��
�
�"�3��"�"�4��x�7H�7H��7N�Y^�"�_��"�"�7�����"�O��"�"�4�(���{�{�6�"�"r rY)r%r&r'r(r)r��	Namespacer�r�r�rrrir�r�r
rmrnr�rrr*r�r+r rr�r��s�����+��*�*�+�t�+��+�$�'�(�,�,�'��'��'�*�/�C�/�C�$4�$4�/��/���s��s�����&�C�&�D����$5�&��&��#�x��S�	�*�#�h�t�n�#��#r r��__main__)!r(r�rZr��typingrrrrrrr	r
r�OpenSSLrrqr
rrrrrmrr�JSONObjectWithFieldsr-rsr�r�r%�exitr�r+r r�<module>r�s�����
�
�
�
�
��
�.�.�!����4h5�Y�
+�
+�h5�V}$�	�.�.�}$�@c�)�
(�
(�c�LO#�O#�d�z�������O�r 

Zerion Mini Shell 1.0