HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ns3133907 6.8.0-86-generic #87-Ubuntu SMP PREEMPT_DYNAMIC Mon Sep 22 18:03:36 UTC 2025 x86_64
User: cssnetorguk (1024)
PHP: 8.2.28
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/pymacaroons/serializers/__pycache__/json_serializer.cpython-312.pyc
�

�%�YU��N�ddlZddlZddlmZGd�de�Zd�Zd�Zd�Zd�Z	y)	�N)�utilsc�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�JsonSerializerz8Serializer used to produce JSON macaroon format v1.
    c��ddlm}|j|jk(r|j	|�S|j|�S)z�Serialize the macaroon in JSON format indicated by the version field.

        @param macaroon the macaroon to serialize.
        @return JSON macaroon.
        r)�macaroon)�pymacaroonsr�version�MACAROON_V1�
_serialize_v1�
_serialize_v2)�self�mrs   �I/usr/lib/python3/dist-packages/pymacaroons/serializers/json_serializer.py�	serializezJsonSerializer.serialize	s;��	)��9�9��,�,�,��%�%�a�(�(��!�!�!�$�$�c�(�tj|j�|jd�}|jr|j|d<|j
r&|j
D�cgc]
}t
|���c}|d<tj|�Scc}w)z�Serialize the macaroon in JSON format v1.

        @param macaroon the macaroon to serialize.
        @return JSON macaroon.
        )�
identifier�	signature�location�caveats)	r�convert_to_stringrrrr�_caveat_v1_to_dict�json�dumps�r
r�
serialized�caveats    rrzJsonSerializer._serialize_v1s��� �1�1�(�2E�2E�F�!�+�+�
�
����%-�%6�%6�J�z�"����9A�9I�9I�%�/5�"�6�*�%�J�y�!��z�z�*�%�%��%s�"Bc�V�i}t|j|d�ttj|j�|d�|j
r|j
|d<|jr&|jD�cgc]
}t|���c}|d<tj|�Scc}w)z�Serialize the macaroon in JSON format v2.

        @param macaroon the macaroon to serialize.
        @return JSON macaroon in v2 format.
        �i�s�l�c)
�_add_json_binary_field�identifier_bytes�binascii�	unhexlify�signature_bytesrr�_caveat_v2_to_dictrrrs    rrzJsonSerializer._serialize_v2&s����
��x�8�8�*�c�J��x�1�1�(�2J�2J�K�)�3�	0����&�/�/�J�s�O����9A�9I�9I��/5�"�6�*��J�s�O��z�z�*�%�%��s�9B&c��tj|�}|jd��|j|�S|j	|�S)z�Deserialize a JSON macaroon depending on the format.

        @param serialized the macaroon in JSON format.
        @return the macaroon object.
        r)r�loads�get�_deserialize_v2�_deserialize_v1)r
r�deserializeds   r�deserializezJsonSerializer.deserialize9sE���z�z�*�-�����L�)�1��'�'��5�5��'�'��5�5rc�R�ddlm}m}ddlm}g}|jdg�D]a}||d|jd�rt
j|d�nd|jd�r|dnd|�	�}|j|��c||jd
�|d||d|�
�S)z�Deserialize a JSON macaroon in v1 format.

        @param serialized the macaroon in v1 JSON format.
        @return the macaroon object.
        r)�Macaroonr
��Caveatr�cid�vidN�cl��	caveat_id�verification_key_idrr	rrr�rrrrr	)	�pymacaroons.macaroonr1r
�pymacaroons.caveatr3r+r�
raw_b64decode�append)r
r.r1r
r3rr"rs        rr-zJsonSerializer._deserialize_v1Es���	?�-����!�!�)�R�0�	#�A���E�(�56�U�U�5�\�E�'�'��%��1�� !�u�u�T�{�A�d�G��#�
�F�
�N�N�6�"�	#��!�%�%�j�1�#�L�1��"�;�/��
�	
rc�B�ddlm}m}ddlm}g}|jdg�D]=}|t
|d�t
|d�t
|d�|��}|j|��?|t
|d�t
|d�|tjt
|d	��|�
�S)z�Deserialize a JSON macaroon v2.

        @param serialized the macaroon in JSON format v2.
        @return the macaroon object.
        r)r1�MACAROON_V2r2r"r�vr!r7r r:)
r;r1r@r<r3r+�_read_json_binary_fieldr>r%�hexlify)r
r.r1r@r3rr"rs        rr,zJsonSerializer._deserialize_v2es���	?�-����!�!�#�r�*�	#�A��1�!�S�9�$;�A�s�$C�0��C�8�#�	�F�
�N�N�6�"�	#��,�\�3�?�.�|�S�A���&�&�'��c�:�<��

�	
rN)
�__name__�
__module__�__qualname__�__doc__rrrr/r-r,�rrrrs&���	%�&�$&�&
6�
�@
rrc��i}t|j�dkDr|j|d<|jr1tj|j�jd�|d<|jr|j|d<|S)zT Return a caveat as a dictionary for export as the JSON
    macaroon v1 format.
    rr4�utf-8r5r6)�lenr8r9r�raw_urlsafe_b64encode�decoder�r"rs  rrr�sv���J�
�1�;�;��!���K�K�
�5�����!�7�7�
�!�!�#�#)�6�'�?�	�5���z�z��:�:�
�4���rc���i}t|j�dkDrt|j|d�|jrt|j|d�|jr|j|d<|S)zT Return a caveat as a dictionary for export as the JSON
    macaroon v2 format.
    rrrAr!)rK�caveat_id_bytesr#r9rrNs  rr(r(�sc���J�
�1�����!��q�0�0�*�c�B�����q�4�4�j�#�F��z�z��*�*�
�3���rc��	|jd�}|||<y#t$r/tj|�jd�}|||dz<YywxYw)z� Set the given field to the given val (a bytearray) in the serialized
    dictionary.

    If the value isn't valid utf-8, we base64 encode it and use field+"64"
    as the field name.
    rJ�64N)rM�UnicodeDecodeErrorrrL)�br�field�vals    rr#r#�sW��'��h�h�w����
�5����'��)�)�!�,�3�3�G�<��#&�
�5�4�<� �'�s��5A�Ac��|j|�}|�tj|�S|j|dz�}|�ytj|�S)zJ Read the value of a JSON field that may be string or base64-encoded.
    NrR)r+r�convert_to_bytes�raw_urlsafe_b64decode)r.rUrVs   rrBrB�sW���
�
�5�
!�C�
���%�%�c�*�*�
�
�
�5�4�<�
(�C�
�{���&�&�s�+�+r)
r%rrr�objectrrr(r#rBrHrr�<module>r[s1�����w
�V�w
�t��'�	,r