HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //snap/certbot/current/lib/python3.12/site-packages/josepy/__pycache__/json_util.cpython-312.pyc
�

�F�hM����dZddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
mZmZm
Z
mZddlmZddlmZddlmZmZmZmZej0dk\rddlZej4e�Z				d,ded	ed
edeeegefdeeegefd
efd�ZGd�d�Z Gd�de �Z!Gd�dejD�Z#edd��Z$Gd�dejJejLe#��Z'de(d
efd�Z)d-dedee*ded
e(fd�Z+de(d
efd �Z,d-dedee*ded
e(fd!�Z-d"ej\d
efd#�Z/d$ed
ej\fd%�Z0d&ejbd
efd'�Z2d$ed
ejbfd(�Z3ed)d*��Z4Gd+�d*e'�Z5y).z�JSON (de)serialization framework.

The framework presented here is somewhat based on `Go's "json" package`_
(especially the ``omitempty`` functionality).

.. _`Go's "json" package`: http://golang.org/pkg/encoding/json/

�N)	�Any�Callable�Dict�Iterable�List�Mapping�Optional�Type�TypeVar)�x509)�Encoding)�b64�errors�
interfaces�util����	json_name�default�	omitempty�decoder�encoder�returnc�"�t|||||��S)a4Convenient function to declare a :class:`Field` with proper type annotations.

    This function allows to write the following code:

    import josepy
    class JSON(josepy.JSONObjectWithFields):
        typ: str = josepy.field('type')

        def other_type(self) -> str:
            return self.typ

    �rrrrr)�_TypedFieldrs     ��/build/snapcraft-certbot-c9aaebe726f8beb59a0eb2d8e1671bc4/parts/certbot/install/lib/python3.12/site-packages/josepy/json_util.py�fieldr%s��&��W�	�7�\c���c�(�eZdZdZdZ				ddedededee	egefdee	egefd	dfd
�Z
eded	efd��Zded	efd
�Z
ded	dfd�Zde	egefd	dfd�Zde	egefd	dfd�Zded	efd�Zded	efd�Zeded	efd��Zeded	efd��Zy)�Fielda�JSON object field.

    :class:`Field` is meant to be used together with
    :class:`JSONObjectWithFields`.

    ``encoder`` (``decoder``) is a callable that accepts a single
    parameter, i.e. a value to be encoded (decoded), and returns the
    serialized (deserialized) value. In case of errors it should raise
    :class:`~josepy.errors.SerializationError`
    (:class:`~josepy.errors.DeserializationError`).

    Note, that ``decoder`` should perform partial serialization only.

    :ivar str json_name: Name of the field when encoded to JSON.
    :ivar default: Default value (used when not present in JSON object).
    :ivar bool omitempty: If ``True`` and the field value is empty, then
        it will not be included in the serialized JSON object, and
        ``default`` will be used for deserialization. Otherwise, if ``False``,
        field is considered as required, value will always be included in the
        serialized JSON objected, and it must also be present when
        deserializing.

    )rrr�fdec�fencNrrrrrrc��||_||_||_|�|jn||_|�|j
|_y||_y�N)rrr�default_decoderr#�default_encoderr$)�selfrrrrrs      r�__init__zField.__init__XsC��#������"���,3�O�D�(�(���	�,3�O�D�(�(��	���	r �valuec�.�t|t�xr|S)z�Is the provided value considered "empty" for this field?

        This is useful for subclasses that might want to override the
        definition of being empty, e.g. for some more exotic data types.

        )�
isinstance�bool��clsr+s  r�_emptyzField._emptygs���e�T�*�*�8�5�y�8r c�@�|j|�xr|jS)zOmit the value in output?)r1r�r)r+s  r�omitz
Field.omitqs���{�{�5�!�4�d�n�n�4r �kwargsc��|j|j|j|j|jd�|�}t|�di|��S)Nr�)rrrr#r$�type)r)r5�currents   r�_update_paramszField._update_paramsusL������|�|�����y�y��y�y�
��

���t�D�z�$�G�$�$r r#c�&�|j|��S)z6Descriptor to change the decoder on JSON object field.)r�r:)r)r#s  rrz
Field.decoder�����"�"�4�"�0�0r r$c�&�|j|��S)z6Descriptor to change the encoder on JSON object field.)rr<)r)r$s  rrz
Field.encoder�r=r c�$�|j|�S)z4Decode a value, optionally with context JSON object.)r#r3s  r�decodezField.decode�����y�y���r c�$�|j|�S)z4Encode a value, optionally with context JSON object.)r$r3s  r�encodezField.encode�rAr c
�&��t|t�rt�fd�|D��St|t�rUt	j
|j
�D��cic]&\}}�j|��j|���(c}}�S|Scc}}w)z�Default decoder.

        Recursively deserialize into immutable types (
        :class:`josepy.util.frozendict` instead of
        :func:`dict`, :func:`tuple` instead of :func:`list`).

        c3�@�K�|]}�j|����y�wr&)r')�.0�subvaluer0s  �r�	<genexpr>z(Field.default_decoder.<locals>.<genexpr>�s�����M�8��,�,�X�6�M�s�)r-�list�tuple�dictr�
frozendict�itemsr')r0r+�keys`  rr'zField.default_decoder�s�����e�T�"��M�u�M�M�M�
��t�
$��?�?�',�k�k�m��"��U��'�'��,�c�.A�.A�%�.H�H���
��L��
s�+B
c��|S)zDefault (passthrough) encoder.r7r/s  rr(zField.default_encoder�s	��
�r �NFNN)�__name__�
__module__�__qualname__�__doc__�	__slots__�strrr.r	rr*�classmethodr1r4r:rrr@rCr'r(r7r rr"r"=sq���0F�I�
��26�26�

I��
I��
I��	
I�
�(�C�5�#�:�.�/�
I��(�C�5�#�:�.�/�

I�
�
I��9�3�9�4�9��9�5�#�5�$�5�	%�s�	%�w�	%�1�H�c�U�C�Z�0�1�W�1�1�H�c�U�C�Z�0�1�W�1� �C� �C� � �C� �C� ���C��C����*��C��C���r r"c��eZdZdZy)raSpecialized class to mark a JSON object field with typed annotations.

    This class is kept private because fields are supposed to be declared
    using the :function:`field` in this situation.

    In the future the :class:`Field` may be removed in favor of this one.N)rQrRrSrTr7r rrr�s��Mr rc�b�eZdZUdZiZeeefed<e	eed<dede
edeeefddfd�Zy	)
�JSONObjectWithFieldsMetaa�Metaclass for :class:`JSONObjectWithFields` and its subclasses.

    It makes sure that, for any class ``cls`` with ``__metaclass__``
    set to ``JSONObjectWithFieldsMeta``:

    1. All fields (attributes of type :class:`Field`) in the class
       definition are moved to the ``cls._fields`` dictionary, where
       keys are field attribute names and values are fields themselves.

    2. ``cls.__slots__`` is extended by all field attribute names
       (i.e. not :attr:`Field.json_name`). Original ``cls.__slots__``
       are stored in ``cls._orig_slots``.

    In a consequence, for a field attribute name ``some_field``,
    ``cls.some_field`` will be a slot descriptor and not an instance
    of :class:`Field`. For example::

      some_field = Field('someField', default=())

      class Foo:
          __metaclass__ = JSONObjectWithFieldsMeta
          __slots__ = ('baz',)
          some_field = some_field

      assert Foo.__slots__ == ('some_field', 'baz')
      assert Foo._orig_slots == ()
      assert Foo.some_field is not Field

      assert Foo._fields.keys() == ['some_field']
      assert Foo._fields['some_field'] is some_field

    As an implementation note, this metaclass inherits from
    :class:`abc.ABCMeta` (and not the usual :class:`type`) to mitigate
    the metaclass conflict (:class:`ImmutableMap` and
    :class:`JSONDeSerializable`, parents of :class:`JSONObjectWithFields`,
    use :class:`abc.ABCMeta` as its metaclass).

    �_fields�_orig_slots�name�bases�	namespacerc���i}|D]}|jt|di��� |j�j�D]�\}}t	|t
�s�t	|t�rd|vr|d}n_tjdk\rJtj|�}	|	r0tj|	tjj��}ni}ni}||vrtd|�d|�d���|j|�||<��|j!dd	�|d
<t#t%|d
�t%|j'��z�|d<||d<t(j*j-||||�S)Nr[�__annotations__r)�formatzField `z` in JSONObject `z` has no type annotation.rUr7r\)�update�getattr�copyrMr-r"r�sys�version_info�
annotationlib�!get_annotate_from_class_namespace�call_annotate_function�Format�
FORWARDREF�
ValueError�pop�getrJrI�keys�abc�ABCMeta�__new__)
�mcsr]r^r_�fields�baserNr+�annotations�annotates
          rrsz JSONObjectWithFieldsMeta.__new__�sl��$&���	8�D��M�M�'�$�	�2�6�7�	8�$�.�.�*�0�0�2�	1�J�C���%��'��e�[�1�)�I�5�&/�0A�&B���)�)�W�4�#0�#R�#R�S\�#]��#�*7�*N�*N� (��1E�1E�1P�1P�+�K�+-�K�&(���+�-�(�%�c�U�*;�D�6�AZ�[���(�m�m�C�0��s��+	1�.$-�=�=��b�#A�	�-� �!&�t�I�m�,D�'E��V�[�[�]�H[�'[�!\�	�+��%�	�)���{�{�"�"�3��e�Y�?�?r N)
rQrRrSrTr[rrVr"rarrrrsr7r rrZrZ�s]��%�N!#�G�T�#�u�*�
�"��#���$@��$@�#�C�y�$@�59�#�s�(�^�$@�	#�$@r rZ�GenericJSONObjectWithFields�JSONObjectWithFields)�boundc���eZdZdZedeeeffd��Zdeddf�fd�Z	dedefd�Z
deeeffd	�Zdeeeffd
�Zede
eefddfd��Zede
eefdefd
��Zedeede
eefdefd��Z�xZS)rza�JSON object with fields.

    Example::

      class Foo(JSONObjectWithFields):
          bar = Field('Bar')
          empty = Field('Empty', omitempty=True)

          @bar.encoder
          def bar(value):
              return value + 'bar'

          @bar.decoder
          def bar(value):
              if not value.endswith('bar'):
                  raise errors.DeserializationError('No bar suffix!')
              return value[:-3]

      assert Foo(bar='baz').to_partial_json() == {'Bar': 'bazbar'}
      assert Foo.from_json({'Bar': 'bazbar'}) == Foo(bar='baz')
      assert (Foo.from_json({'Bar': 'bazbar', 'Empty': '!'})
              == Foo(bar='baz', empty='!'))
      assert Foo(bar='baz').bar == 'baz'

    rc�~�|jj�D��cic]\}}||j��c}}Scc}}w)zGet default fields values.)r[rMr)r0�slotrs   r�	_defaultszJSONObjectWithFields._defaults)s2��8;�{�{�7H�7H�7J�K���e��e�m�m�#�K�K��Ks�9r5Nc�H��t�|�dii|j��|���y�Nr7)�superr*r)r)r5�	__class__s  �rr*zJSONObjectWithFields.__init__.s%���
���:�9�d�n�n�.�9�&�9�:r r]c��	|j|}|jt
||��S#t$r%tjdj	|���wxYw)z�Encode a single field.

        :param str name: Name of the field to be encoded.

        :raises errors.SerializationError: if field cannot be serialized
        :raises errors.Error: if field could not be found

        zField not found: {0})r[�KeyErrorr�ErrorrbrCrd)r)r]rs   rrCzJSONObjectWithFields.encode1s\��	D��L�L��&�E��|�|�G�D�$�/�0�0���	D��,�,�5�<�<�T�B�C�C�	D�s	�,�.Ac	��i}t�}|jj�D]U\}}t||�}|j	|�r|j||f��7	|j
|�||j<�W|S#tj$r+}tjdj|||���d}~wwxYw)zSerialize fields to JSON.zCould not encode {0} ({1}): {2}N)�setr[rMrdr4�addrCrr�SerializationErrorrb)r)�jobj�omittedr~rr+�errors       r�fields_to_partial_jsonz+JSONObjectWithFields.fields_to_partial_jsonAs������%���<�<�-�-�/�	�K�D�%��D�$�'�E��z�z�%� ����T�5�M�*��,1�L�L��,?�D����)�	����	�0�0�� �3�3�9�@�@��u�e�T�����s�B�B?�&B:�:B?c�"�|j�Sr&)r�)r)s r�to_partial_jsonz$JSONObjectWithFields.to_partial_jsonSs���*�*�,�,r r�c�4�t�}|jj�D]<\}}|jr�|j|vs�"|j|j��>|r3t
jdjdj|����y)Nz&The following fields are required: {0}�,)
r�r[rMrrr�r�DeserializationErrorrb�join)r0r��missing�_rs     r�_check_requiredz$JSONObjectWithFields._check_requiredVs���%�����)�)�+�	-�H�A�u��?�?�u���d�'B����E�O�O�,�	-���-�-�8�?�?�����@Q�R��
�r c	��|j|�i}|jj�D]S\}}|j|vr|jr|j
||<�0||j}	|j
|�||<�U|S#tj$r+}tjdj|||���d}~wwxYw)zDeserialize fields from JSON.z#Could not decode {0!r} ({1!r}): {2}N)
r�r[rMrrrr@rr�rb)r0r�rur~rr+r�s       r�fields_from_jsonz%JSONObjectWithFields.fields_from_jsonbs���	���D�!����;�;�,�,�.�
	�K�D�%����d�*�u���$�}�}��t���U�_�_�-���#(�<�<��#6�F�4�L�
	��
��	�2�2�� �5�5�=�D�D�T�5�RW�X�����s�.B�C�&B?�?Cr0c�0�|di|j|���Sr�)r�)r0r�s  r�	from_jsonzJSONObjectWithFields.from_jsonts���0�S�)�)�$�/�0�0r )rQrRrSrTrWrrVrrr*rCr�r�rr�r�r
ryr��
__classcell__)r�s@rrzrzs
����4�L�$�s�C�x�.�L��L�;��;��;�1�3�1�3�1� ��S�#�X���$-��c�3�h��-��	�7�3��8�#4�	��	��	���G�C��H�$5��#����"�1�
�-�
.�1�6=�c�3�h�6G�1�	$�1��1r )�	metaclass�datac�J�tj|�jd�S)zJEncode JOSE Base-64 field.

    :param bytes data:
    :rtype: `str`

    �ascii)r�	b64encoder@)r�s r�encode_b64joser�{s���=�=���%�%�g�.�.r �size�minimumc�:�	tj|j��}|�D|st|�|k7s|r2t|�|kr$tjdj|���|S#tj$r}tj|��d}~wwxYw)aDecode JOSE Base-64 field.

    :param unicode data:
    :param int size: Required length (after decoding).
    :param bool minimum: If ``True``, then `size` will be treated as
        minimum required length, as opposed to exact equality.

    :rtype: bytes

    Nz&Expected at least or exactly {0} bytes)	r�	b64decoderC�binasciir�rr��lenrb)r�r�r��decodedr�s     r�decode_b64joser��s���1��-�-����
�.����
��W���-�7�s�7�|�d�?R��)�)�*R�*Y�*Y�Z^�*_�`�`��N���>�>�1��)�)�%�0�0��1�s�#A-�-B�B�Br+c�H�tj|�j�S)z;Hexlify.

    :param bytes value:
    :rtype: unicode

    )r��hexlifyr@)r+s r�encode_hex16r��s�����E�"�)�)�+�+r c�&�|j�}|�:|st|�|dzk7s|r%t|�|dzkrtj��	t	j
|�S#tj$r}tj|��d}~wwxYw)aDecode hexlified field.

    :param unicode value:
    :param int size: Required length (after decoding).
    :param bool minimum: If ``True``, then `size` will be treated as
        minimum required length, as opposed to exact equality.

    :rtype: bytes

    N�)rCr�rr�r��	unhexlifyr�)r+r�r��value_br�s     r�decode_hex16r��s����l�l�n�G���
��W�����1�w�3�w�<�RV�YZ�RZ�CZ��)�)�+�+�1��!�!�'�*�*���>�>�1��)�)�%�0�0��1�s�A#�#B�6B�B�certc�R�t|jtj��S)aMEncode certificate as JOSE Base-64 DER.

    :type cert: `cryptography.x509.Certificate`
    :rtype: unicode

    .. versionchanged:: 2.0.0
       The `cert` parameter is now `cryptography.x509.Certificate`.
       Previously this was an `josepy.util.ComparableX509` object, which wrapped
       an `OpenSSL.crypto.X509` object.
    �r��public_bytesr
�DER)r�s r�encode_certr��s���$�+�+�H�L�L�9�:�:r �b64derc��	tjt|��S#t$r}t	j
|��d}~wwxYw)aVDecode JOSE Base-64 DER-encoded certificate.

    :param unicode b64der:
    :rtype: `cryptography.x509.Certificate`

    .. versionchanged:: 2.0.0
       The returned object is now a `cryptography.x509.Certificate`.
       Previously this was an `josepy.util.ComparableX509` object, which wrapped
       an `OpenSSL.crypto.X509` object.
    N)r�load_der_x509_certificater�rmrr��r�r�s  r�decode_certr��s>��1��-�-�n�V�.D�E�E���1��)�)�%�0�0��1��� �	A�>�A�csrc�R�t|jtj��S)acEncode CSR as JOSE Base-64 DER.

    :type csr: `cryptography.x509.CertificateSigningRequest`
    :rtype: unicode

    .. versionchanged:: 2.0.0
       The `cert` parameter is now `cryptography.x509.CertificateSigningRequest`.
       Previously this was an `josepy.util.ComparableX509` object, which wrapped
       an `OpenSSL.crypto.X509Req` object.
    r�)r�s r�
encode_csrr��s���#�*�*�8�<�<�8�9�9r c��	tjt|��S#t$r}t	j
|��d}~wwxYw)amDecode JOSE Base-64 DER-encoded CSR.

    :param unicode b64der:
    :rtype: `cryptography.x509.CertificateSigningRequest`

    .. versionchanged:: 2.0.0
       The returned object is now a `cryptography.x509.CertificateSigningRequest`.
       Previously this was an `josepy.util.ComparableX509` object, which wrapped
       an `OpenSSL.crypto.X509Req` object.
    N)r�load_der_x509_csrr�rmrr�r�s  r�
decode_csrr��s>��1��%�%�n�V�&<�=�=���1��)�)�%�0�0��1�r�� GenericTypedJSONObjectWithFields�TypedJSONObjectWithFieldsc	���eZdZUdZeZeed<	dZeed<	eZ	e
eefed<	e	ddee
deedee
fd	��Zed
eeefdedfd��Zde
eeffd�Zed
eeefddfd
��Zy)r�zJSON object with type.�typr8�type_field_name�TYPESN�type_clsrc�D�|�|jn|}||j|<|S)z(Register class for JSON deserialization.)r�r�)r0r�r�s   r�registerz"TypedJSONObjectWithFields.registers%��
"�k�h�l�l�s��!��	�	�#���r r�c���||jj�vr>|j|vr.tjdj|j���|St
|t�s$tjdj|���	||j}	|j|S#t$rtjd��wxYw#t$rtj||��wxYw)z&Get the registered class for ``jobj``.zMissing type field ({0})z{0} is not a dictionary objectzmissing type field)
r��valuesr�rr�rbr-rKr��UnrecognizedTypeError)r0r�r�s   r�get_type_clsz&TypedJSONObjectWithFields.get_type_clss����#�)�)�"�"�$�$��"�"�$�.��1�1�.�5�5�c�6I�6I�J����J��$��%��-�-�.N�.U�.U�VZ�.[�\�\�	D��s�*�*�+�C�	:��9�9�S�>�!��	�	D��-�-�.B�C�C�	D��
�	:��.�.�s�D�9�9�	:�s�B/� C�/C� C1c�X�|j�}|j||j<|S)aGet JSON serializable object.

        :returns: Serializable JSON object representing ACME typed object.
            :meth:`validate` will almost certainly not work, due to reasons
            explained in :class:`josepy.interfaces.IJSONSerializable`.
        :rtype: dict

        )r�r�r�)r)r�s  rr�z)TypedJSONObjectWithFields.to_partial_json3s+���*�*�,��%)�X�X��T�
!�
!�"��r c�R�|j|�}|di|j|���S)z�Deserialize ACME object from valid JSON object.

        :raises josepy.errors.UnrecognizedTypeError: if type
            of the ACME object has not been registered.

        r7)r�r�)r0r�r�s   rr�z#TypedJSONObjectWithFields.from_json@s-���#�#�D�)���:�(�3�3�D�9�:�:r r&)rQrRrSrT�NotImplementedr�rVrar�r�rr
rWr�r	r�rrr�r�r�r7r rr�r�s��� ��C���7�!�O�S�!��,�E�4��T�	�?�+�3��TX���<�=��DL�S�M��	
�.�	/�����:���S�� 1�:�d�;V�6W�:��:�0��c�3�h����	;�W�S�#�X�.�	;�3N�	;��	;r rP)NF)6rTrqr��loggingrf�typingrrrrrrr	r
r�cryptographyr�,cryptography.hazmat.primitives.serializationr
�josepyrrrrrgrh�	getLoggerrQ�loggerrVr.rr"rrrrZry�ImmutableMap�JSONDeSerializablerz�bytesr��intr�r�r��Certificater�r��CertificateSigningRequestr�r�r�r�r7r r�<module>r�s������
�
�
�
��A�0�0����w���	��	�	�8�	$��
��.2�.2����
�����h��u�c�z�*�
+�	�
�h��u�c�z�*�
+��	�
�0n�n�bM�%�M�O@�s�{�{�O@�d&�&C�Ka�b��l1����z�4�4�@X�l1�^/��/�3�/����H�S�M��4��TY��0,��,�#�,�1��1�8�C�=�1�$�1�SX�1�,;�d�&�&�;�3�;�1��1�� 0� 0�1�":�D�2�2�:�s�:�1�s�1�t�=�=�1�"$+�&�.I�$� �
I;� 4�I;r