AlkantarClanX12

Your IP : 18.219.207.115


Current Path : /opt/imunify360/venv/lib/python3.11/site-packages/Crypto/Util/__pycache__/
Upload File :
Current File : //opt/imunify360/venv/lib/python3.11/site-packages/Crypto/Util/__pycache__/asn1.cpython-311.pyc

�

f��fI���Z�ddlZddlmZmZmZddlmZmZgd�Zdd�Z	Gd�de
��ZGd	�d
e
��ZGd�de��Z
Gd
�de��ZGd�de��ZGd�de��ZGd�de��ZGd�de��ZGd�de��ZGd�de��ZdS)�N)�byte_string�bchr�bord)�
long_to_bytes�
bytes_to_long)	�	DerObject�
DerInteger�
DerBoolean�DerOctetString�DerNull�DerSequence�DerObjectId�DerBitString�DerSetOfFc�H�d}	||z}n#t$rYdSwxYw|p|dkS)NrF)�	TypeError)�x�only_non_negative�tests   �r/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Util/asn1.py�
_is_numberr(sK���D���4�x���������u�u����� � �*�A��F�*s�
�
�c�6�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	dS)	�BytesIO_EOFzeThis class differs from BytesIO in that a ValueError exception is
    raised whenever EOF is reached.c�0�||_d|_d|_dS�Nr)�_buffer�_index�	_bookmark)�self�
initial_bytess  r�__init__zBytesIO_EOF.__init__5s��$�����������c��|j|_dS�N)rr�rs r�set_bookmarkzBytesIO_EOF.set_bookmark:s�������r"c�F�|j�J�|j|j|j�Sr$)rrrr%s r�data_since_bookmarkzBytesIO_EOF.data_since_bookmark=s&���~�)�)�)��|�D�N�4�;�6�7�7r"c�:�t|j��|jz
Sr$)�lenrrr%s r�remaining_datazBytesIO_EOF.remaining_dataAs���4�<� � �4�;�.�.r"c���|j|z}|t|j��kr&td|t|j��fz���|j|j|�}||_|S)Nz@Not enough data for DER decoding: expected %d bytes and found %d)rr*r�
ValueError)r�length�	new_index�results    r�readzBytesIO_EOF.readDsy���K�&�(�	��s�4�<�(�(�(�(��_�cl�nq�rv�r~�n�n�cA�A�B�B�
B���d�k�)�3�4������
r"c�R�t|�d��d��S)N�r)rr1r%s r�	read_bytezBytesIO_EOF.read_byteMs���D�I�I�a�L�L��O�$�$�$r"N)
�__name__�
__module__�__qualname__�__doc__r!r&r(r+r1r4�r"rrr1sx������'�'����
%�%�%�8�8�8�/�/�/����%�%�%�%�%r"rc�T�eZdZdZ		dd�Zd�Zed���Zd�Zd	�Z	d
d
�Z
d�ZdS)rzpBase class for defining a single DER object.

        This class should never be directly instantiated.
        Nr"Fc�<�|�	d|_dS|�|��}||_|rdnd}d||fvrtd���|�"d|z|�|��z|_dS|�)d|�|��z|_||z|_dS||z|_dS)a�Initialize the DER object according to a specific ASN.1 type.

                :Parameters:
                  asn1Id : integer or byte
                    The universal DER tag number for this object
                    (e.g. 0x10 for a SEQUENCE).
                    If None, the tag is not known yet.

                  payload : byte string
                    The initial payload of the object (that it,
                    the content octets).
                    If not specified, the payload is empty.

                  implicit : integer or byte
                    The IMPLICIT tag number (< 0x1F) to use for the encoded object.
                    It overrides the universal tag *asn1Id*.
                    It cannot be combined with the ``explicit`` parameter.
                    By default, there is no IMPLICIT tag.

                  constructed : bool
                    True when the ASN.1 type is *constructed*.
                    False when it is *primitive* (default).

                  explicit : integer or byte
                    The EXPLICIT tag number (< 0x1F) to use for the encoded object.
                    It cannot be combined with the ``implicit`` parameter.
                    By default, there is no EXPLICIT tag.
                N� rz1Explicit and implicit tags are mutually exclusive��)�
_tag_octet�_convertTag�payloadr-�_inner_tag_octet)r�asn1IdrA�implicit�constructed�explicit�constructed_bits       rr!zDerObject.__init__Ws���>�>�&*�D�O��F��)�)�&�1�1��&��� +6�"?�$�$�4����(�3�3�3�$�&;�<�<�<��'�&*�_�&<�t�?O�?O�PX�?Y�?Y�&Y�D�O�O�O��)�&1�D�4D�4D�X�4N�4N�&N�D�O�,;�f�,D�D�)�)�)�'6��&>�D�O�O�Or"c���t|��s(t|��dkrt|d��}t|��rd|cxkrdksntd���|S)zCheck if *tag* is a real DER tag (5 bits).
                Convert it from a character to number if necessary.
                r3r�z
Wrong DER tag)rr*rr-)r�tags  rr@zDerObject._convertTag�sg��"�#���+��3�x�x�1�}�}�"�3�q�6�l�l��"�3���6�A��O�O�O�O�t�O�O�O�O�$�_�5�5�5��
r"c��|dkr1t|��}tt|��dz��|zSt|��S)zXBuild length octets according to BER/DER
                definite form.
                �r=)rrr*)r.�encodings  r�_definite_formzDerObject._definite_form�sD��
�C�<�<�#0��#8�#8��#�C��M�M�C�$7�8�8�8�C�C��F�|�|�#r"c�,�|j}t|d��rDt|j��|�t|j����z|jz}t|j��|�t|����z|zS)z?Return this DER element, fully encoded as a binary byte string.rB)rA�hasattrrrBrNr*r?)r�output_payloads  r�encodezDerObject.encode�s���"&����4�!3�4�4�4�&*�4�+@�&A�&A�&*�&9�&9�#�d�l�:K�:K�&L�&L�'M�&*�l�'3�N��T�_�-�-��+�+�C��,?�,?�@�@�A�&�'�(r"c��|���}|dkrd|�|dz��}t|d��dkrtd���t	|��}|dkrtd���|S)z%Decode DER length octets from a file.rLrz$Invalid DER: length has leading zeroz5Invalid DER: length in long form but smaller than 128)r4r1rr-r)r�sr.�encoded_lengths    r�
_decodeLenzDerObject._decodeLen�s����������C�<�<�%&�V�V�F�T�M�%:�%:�N��N�1�-�.�.�!�3�3�(�)O�P�P�P�*�>�:�:�F���}�}�(�)`�a�a�a��
r"c���t|��std���t|��}|�||��|���dkrtd���|S)aDecode a complete DER element, and re-initializes this
                object with it.

                Args:
                  der_encoded (byte string): A complete DER element.

                Raises:
                  ValueError: in case of parsing errors.
                zInput is not a byte stringr�-Unexpected extra data after the DER structure)rr-r�_decodeFromStreamr+)r�der_encoded�strictrTs    r�decodezDerObject.decode�st��#�;�/�/�C�$�%A�B�B�B���,�,���&�&�q�&�1�1�1��#�#�%�%��)�)�$�%T�U�U�U��r"c�2�|���}|j�||jkrtd���n||_|�|��}|�|��|_t
|d��r�t|j��}|���}||jkrtd���|�|��}|�|��|_|�	��dkrtd���dSdS)z*Decode a complete DER element from a file.NzUnexpected DER tagrBzUnexpected internal DER tagrrX)
r4r?r-rVr1rArPrrBr+)rrTr[�idOctetr.�p�inner_octets       rrYzDerObject._decodeFromStream�s���+�+�-�-���?�.��$�/�1�1�(�)=�>�>�>�2�'.�D�O�����+�+�� �v�v�f�~�~����4�!3�4�4�
Z�#�D�L�1�1�A�"#�+�+�-�-�K�"�d�&;�;�;�(�)F�G�G�G�!�_�_�Q�/�/�F�#$�6�6�&�>�>�D�L��'�'�)�)�A�-�-�(�)X�Y�Y�Y�
Z�
Z�.�-r")Nr"NFN�F)r5r6r7r8r!r@�staticmethodrNrRrVr\rYr9r"rrrQs�������	�	�
?C�15�D	?�D	?�D	?�D	?�L
	�
	�
	�
�	$�	$�
��	$�	(�	(�	(�&
	�
	�
	�	�	�	�	�.	Z�	Z�	Z�	Z�	Zr"rc�.�eZdZdZd	d�Zd�Zd
d�Zd�ZdS)r	a�Class to model a DER INTEGER.

        An example of encoding is::

          >>> from Crypto.Util.asn1 import DerInteger
          >>> from binascii import hexlify, unhexlify
          >>> int_der = DerInteger(9)
          >>> print hexlify(int_der.encode())

        which will show ``020109``, the DER encoding of 9.

        And for decoding::

          >>> s = unhexlify(b'020109')
          >>> try:
          >>>   int_der = DerInteger()
          >>>   int_der.decode(s)
          >>>   print int_der.value
          >>> except ValueError:
          >>>   print "Not a valid DER INTEGER"

        the output will be ``9``.

        :ivar value: The integer value
        :vartype value: integer
        rNc�R�t�|dd|d|��||_dS)aUInitialize the DER object as an INTEGER.

                :Parameters:
                  value : integer
                    The value of the integer.

                  implicit : integer
                    The IMPLICIT tag to use for the encoded object.
                    It overrides the universal tag for INTEGER (2).
                �r"FN�rr!�value�rrgrDrFs    rr!zDerInteger.__init__#s4���"�"�4��s�H�#(�(�4�4�4�"��
�
�
r"c�2�|j}d|_	tt|dz����|jz|_d|cxkrdkrnntd��|jz|_d|cxkrdkrnnn|dz}�ot�|��S)zIReturn the DER INTEGER, fully encoded as a
                binary string.r"T�r=ri�����)rgrAr�intrrR)r�numbers  rrRzDerInteger.encode3s������"���!�#'��F�S�L�(9�(9�#:�#:�T�\�#I�D�L��f�+�+�+�+��+�+�+�+�+�'+�D�z�z�D�L�'@����v�,�,�,�,��,�,�,�,�,���q�L�F�
!�!�'�'��-�-�-r"Fc�<�t�|||���S)aDecode a DER-encoded INTEGER, and re-initializes this
                object with it.

                Args:
                  der_encoded (byte string): A complete INTEGER DER element.

                Raises:
                  ValueError: in case of parsing errors.
                �r[�rr\�rrZr[s   rr\zDerInteger.decodeBs��!�'�'��k�&�'�I�I�Ir"c�0�t�|||��|rzt|j��dkrt	d���t|j��dkr;tjd|jdd���ddkrt	d���d|_d}|jD]4}|xjd	zc_|xjt|��z
c_|d
z}�5|jr/t|jd��dzr|xj|zc_dSdSdS)z*Decode a complete DER INTEGER from a file.rz/Invalid encoding for DER INTEGER: empty payloadrez>HNr=z.Invalid encoding for DER INTEGER: leading zeror3�rk)	rrYr*rAr-�struct�unpackrgr)rrTr[�bits�is     rrYzDerInteger._decodeFromStreamOs4���+�+�D�!�V�<�<�<��[��4�<�(�(�A�-�-�(�)Z�[�[�[��4�<�(�(�A�-�-�&�-��d�l�SU�TU�SU�FV�2W�2W�XY�2Z�]a�2a�2a�(�)Y�Z�Z�Z���
�������A��J�J�#�%�J�J��J�J�$�q�'�'�)�J�J��Q�J�D�D��<�'�D���a��$9�$9�D�$@�'��J�J�$�&�J�J�J�J�'�'�'�'r")rNNra�r5r6r7r8r!rRr\rYr9r"rr	r	sh������	�	�6	#�	#�	#�	#� 
	.�
	.�
	.�	J�	J�	J�	J�	'�	'�	'�	'�	'r"r	c�.�eZdZdZdd�Zd�Zd	d�Zd�ZdS)
r
aRClass to model a DER-encoded BOOLEAN.

    An example of encoding is::

    >>> from Crypto.Util.asn1 import DerBoolean
    >>> bool_der = DerBoolean(True)
    >>> print(bool_der.encode().hex())

    which will show ``0101ff``, the DER encoding of True.

    And for decoding::

    >>> s = bytes.fromhex('0101ff')
    >>> try:
    >>>   bool_der = DerBoolean()
    >>>   bool_der.decode(s)
    >>>   print(bool_der.value)
    >>> except ValueError:
    >>>   print "Not a valid DER BOOLEAN"

    the output will be ``True``.

    :ivar value: The boolean value
    :vartype value: boolean
    FNc�R�t�|dd|d|��||_dS)a�Initialize the DER object as a BOOLEAN.

        Args:
          value (boolean):
            The value of the boolean. Default is False.

          implicit (integer or byte):
            The IMPLICIT tag number (< 0x1F) to use for the encoded object.
            It overrides the universal tag for BOOLEAN (1).
            It cannot be combined with the ``explicit`` parameter.
            By default, there is no IMPLICIT tag.

          explicit (integer or byte):
            The EXPLICIT tag number (< 0x1F) to use for the encoded object.
            It cannot be combined with the ``implicit`` parameter.
            By default, there is no EXPLICIT tag.
        r3r"FNrfrhs    rr!zDerBoolean.__init__�s-��&	���4��s�H�e�X�F�F�F���
�
�
r"c�V�|jrdnd|_t�|��S)z9Return the DER BOOLEAN, fully encoded as a binary string.����rgrArrRr%s rrRzDerBoolean.encode�s*��#'�*�9�w�w�'�������%�%�%r"c�:�t�|||��S)z�Decode a DER-encoded BOOLEAN, and re-initializes this object with it.

        Args:
            der_encoded (byte string): A DER-encoded BOOLEAN.

        Raises:
            ValueError: in case of parsing errors.
        rprqs   rr\zDerBoolean.decode�s������k�6�:�:�:r"c�B�t�|||��t|j��dkrt	d���t|jd��dkr	d|_dSt|jd��dkr	d|_dSt	d���)	z)Decode a DER-encoded BOOLEAN from a file.r3z7Invalid encoding for DER BOOLEAN: payload is not 1 byterFrjTzInvalid payload for DER BOOLEANN)rrYr*rAr-rrg�rrTr[s   rrYzDerBoolean._decodeFromStream�s���	�#�#�D�!�V�4�4�4��t�|����!�!��V�W�W�W����Q�� � �A�%�%��D�J�J�J�
�$�,�q�/�
"�
"�d�
*�
*��D�J�J�J��>�?�?�?r")FNNrarxr9r"rr
r
fsi��������2����,&�&�&�
;�
;�
;�
;�@�@�@�@�@r"r
c�z�eZdZdZdd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zdd�Zdd�Zd�Zdd�Zd�ZdS)r
a�Class to model a DER SEQUENCE.

        This object behaves like a dynamic Python sequence.

        Sub-elements that are INTEGERs behave like Python integers.

        Any other sub-element is a binary string encoded as a complete DER
        sub-element (TLV).

        An example of encoding is:

          >>> from Crypto.Util.asn1 import DerSequence, DerInteger
          >>> from binascii import hexlify, unhexlify
          >>> obj_der = unhexlify('070102')
          >>> seq_der = DerSequence([4])
          >>> seq_der.append(9)
          >>> seq_der.append(obj_der.encode())
          >>> print hexlify(seq_der.encode())

        which will show ``3009020104020109070102``, the DER encoding of the
        sequence containing ``4``, ``9``, and the object with payload ``02``.

        For decoding:

          >>> s = unhexlify(b'3009020104020109070102')
          >>> try:
          >>>   seq_der = DerSequence()
          >>>   seq_der.decode(s)
          >>>   print len(seq_der)
          >>>   print seq_der[0]
          >>>   print seq_der[:]
          >>> except ValueError:
          >>>   print "Not a valid DER SEQUENCE"

        the output will be::

          3
          4
          [4, 9, b'']

        Nc�h�t�|dd|d|��|�	g|_dS||_dS)aCInitialize the DER object as a SEQUENCE.

                :Parameters:
                  startSeq : Python sequence
                    A sequence whose element are either integers or
                    other DER objects.

                  implicit : integer or byte
                    The IMPLICIT tag number (< 0x1F) to use for the encoded object.
                    It overrides the universal tag for SEQUENCE (16).
                    It cannot be combined with the ``explicit`` parameter.
                    By default, there is no IMPLICIT tag.

                  explicit : integer or byte
                    The EXPLICIT tag number (< 0x1F) to use for the encoded object.
                    It cannot be combined with the ``implicit`` parameter.
                    By default, there is no EXPLICIT tag.
                �r"TN)rr!�_seq)r�startSeqrDrFs    rr!zDerSequence.__init__�s>��(�"�"�4��s�H�d�H�M�M�M��#� "�D�I�I�I� (�D�I�I�Ir"c��|j|=dSr$�r��r�ns  r�__delitem__zDerSequence.__delitem__s���I�a�L�L�Lr"c��|j|Sr$r�r�s  r�__getitem__zDerSequence.__getitem__s���y��|�#r"c��||j|<dSr$r�)r�keyrgs   r�__setitem__zDerSequence.__setitem__s��!&��	�#���r"c��||j||�<dSr$r�)rrw�j�sequences    r�__setslice__zDerSequence.__setslice__	s��!)��	�!�A�#���r"c��|j||�=dSr$r��rrwr�s   r�__delslice__zDerSequence.__delslice__s���I�a��c�N�N�Nr"c�X�|jtd|��td|���Sr)r��maxr�s   r�__getslice__zDerSequence.__getslice__s$���y��Q����3�q�!�9�9�!4�5�5r"c�*�t|j��Sr$�r*r�r%s r�__len__zDerSequence.__len__s���4�9�~�~�%r"c�:�|j�|��|Sr$�r��append�r�items  r�__iadd__zDerSequence.__iadd__����	� � ��&�&�&��r"c�:�|j�|��|Sr$r�r�s  rr�zDerSequence.appendr�r"c�<�|j�||��|Sr$)r��insert)r�indexr�s   rr�zDerSequence.inserts���	� � ���-�-�-��r"Tc�H���fd�|jD��}t|��S)z�Return the number of items in this sequence that are
                integers.

                Args:
                  only_non_negative (boolean):
                    If ``True``, negative integers are not counted in.
                c�4��g|]}t|����|��Sr9)r)�.0rrs  �r�
<listcomp>z'DerSequence.hasInts.<locals>.<listcomp>*s)���R�R�R�q��A�?P�1Q�1Q�R��R�R�Rr")r�r*)rr�itemss ` r�hasIntszDerSequence.hasInts!s-���S�R�R�R�D�I�R�R�R���5�z�z�!r"c�f�|jo*|�|��t|j��kS)a�Return ``True`` if all items in this sequence are integers
                or non-negative integers.

                This function returns False is the sequence is empty,
                or at least one member is not an integer.

                Args:
                  only_non_negative (boolean):
                    If ``True``, the presence of negative integers
                    causes the method to return ``False``.)r�r�r*)rrs  r�hasOnlyIntszDerSequence.hasOnlyInts-s+���y�V�T�\�\�2C�%D�%D��D�I���%V�Vr"c�Z�d|_|jD]�}t|��r|xj|z
c_�"t|��r0|xjt	|�����z
c_�a|xj|���z
c_��t�|��S)z�Return this DER SEQUENCE, fully encoded as a
                binary string.

                Raises:
                  ValueError: if some elements in the sequence are neither integers
                              nor byte strings.
                r")rAr�rrr	rRrr�s  rrRzDerSequence.encode:s��� #��� �I�6�6�D�"�4�(�(�6�����,����#�D�)�)�6����
�4�(8�(8�(?�(?�(A�(A�A����������
�
�5���� �'�'��-�-�-r"Fc��||_t�|||���}|r#|���st	d���|S)a9Decode a complete DER SEQUENCE, and re-initializes this
                object with it.

                Args:
                  der_encoded (byte string):
                    A complete SEQUENCE DER element.
                  nr_elements (None or integer or list of integers):
                    The number of members the SEQUENCE can have
                  only_ints_expected (boolean):
                    Whether the SEQUENCE is expected to contain only integers.
                  strict (boolean):
                    Whether decoding must check for strict DER compliancy.

                Raises:
                  ValueError: in case of parsing errors.

                DER INTEGERs are decoded into Python integers. Any other DER
                element is not decoded. Its validity is not checked.
                rozSome members are not INTEGERs)�_nr_elementsrr\r�r-)rrZr[�nr_elements�only_ints_expectedr0s      rr\zDerSequence.decodeLsW��*%0��!�"�)�)�$��F�)�K�K��%�F�d�.>�.>�.@�.@�F�$�%D�E�E�E��
r"c�V�g|_t�|||��t|j��}|���dkr�|���t��}|�||��|jdkr-|j�|�	����nXt��}|�	��}|�||���|j�|j��|���dk��d}|j
�J	t|j��|j
v}n-#t$r t|j��|j
k}YnwxYw|s$t!dt|j��z���dS)z+Decode a complete DER SEQUENCE from a file.rreroTNz1Unexpected number of members (%d) in the sequence)r�rrYrrAr+r&r?r�r(r	r\rgr�r*rr-)rrTr[r_�der�derInt�data�oks        rrYzDerSequence._decodeFromStreamis�����	��+�+�D�!�V�<�<�<� ���-�-���&�&�(�(�1�,�,��N�N�$�$�$�#�+�+�C��)�)�!�V�4�4�4��~��-�-��	�(�(��)>�)>�)@�)@�A�A�A�A�!+���� �4�4�6�6���
�
�d�6�
�:�:�:��	�(�(���6�6�6��&�&�(�(�1�,�,����$�0�A� ���^�^�t�/@�@����$�A�A�A� ���^�^�t�/@�@����A�����J�$�&8�:=�d�i�.�.�&I�J�J�J�J�Js�:E�'F�?F)NNN)T)FNF)r5r6r7r8r!r�r�r�r�r�r�r�r�r�r�r�r�rRr\rYr9r"rr
r
�s,������(	�(	�T	)�	)�	)�	)�8	!�	!�	!�	$�	$�	$�	'�	'�	'�	*�	*�	*�	#�	#�	#�	6�	6�	6�	&�	&�	&�	�	�	�	�	�	�	�	�	�
	"�
	"�
	"�
	"�	W�	W�	W�	W�	.�	.�	.�$	�	�	�	�:"	J�"	J�"	J�"	J�"	Jr"r
c��eZdZdZdd�ZdS)ra�Class to model a DER OCTET STRING.

    An example of encoding is:

    >>> from Crypto.Util.asn1 import DerOctetString
    >>> from binascii import hexlify, unhexlify
    >>> os_der = DerOctetString(b'\xaa')
    >>> os_der.payload += b'\xbb'
    >>> print hexlify(os_der.encode())

    which will show ``0402aabb``, the DER encoding for the byte string
    ``b'\xAA\xBB'``.

    For decoding:

    >>> s = unhexlify(b'0402aabb')
    >>> try:
    >>>   os_der = DerOctetString()
    >>>   os_der.decode(s)
    >>>   print hexlify(os_der.payload)
    >>> except ValueError:
    >>>   print "Not a valid DER OCTET STRING"

    the output will be ``aabb``.

    :ivar payload: The content of the string
    :vartype payload: byte string
    r"Nc�B�t�|d||d��dS)ahInitialize the DER object as an OCTET STRING.

        :Parameters:
          value : byte string
            The initial payload of the object.
            If not specified, the payload is empty.

          implicit : integer
            The IMPLICIT tag to use for the encoded object.
            It overrides the universal tag for OCTET STRING (4).
        �FN�rr!)rrgrDs   rr!zDerOctetString.__init__�s&��	���4��u�h��>�>�>�>�>r")r"N�r5r6r7r8r!r9r"rrr�s2��������:?�?�?�?�?�?r"rc��eZdZdZd�ZdS)rz"Class to model a DER NULL element.c�B�t�|dddd��dS)z$Initialize the DER object as a NULL.�r"NFr�r%s rr!zDerNull.__init__�s&��	���4��s�D�%�8�8�8�8�8r"Nr�r9r"rrr�s)������,�,�9�9�9�9�9r"rc�.�eZdZdZd	d�Zd�Zd
d�Zd�ZdS)ra(Class to model a DER OBJECT ID.

    An example of encoding is:

    >>> from Crypto.Util.asn1 import DerObjectId
    >>> from binascii import hexlify, unhexlify
    >>> oid_der = DerObjectId("1.2")
    >>> oid_der.value += ".840.113549.1.1.1"
    >>> print hexlify(oid_der.encode())

    which will show ``06092a864886f70d010101``, the DER encoding for the
    RSA Object Identifier ``1.2.840.113549.1.1.1``.

    For decoding:

    >>> s = unhexlify(b'06092a864886f70d010101')
    >>> try:
    >>>   oid_der = DerObjectId()
    >>>   oid_der.decode(s)
    >>>   print oid_der.value
    >>> except ValueError:
    >>>   print "Not a valid DER OBJECT ID"

    the output will be ``1.2.840.113549.1.1.1``.

    :ivar value: The Object ID (OID), a dot separated list of integers
    :vartype value: string
    �Nc�R�t�|dd|d|��||_dS)a�Initialize the DER object as an OBJECT ID.

        :Parameters:
          value : string
            The initial Object Identifier (e.g. "1.2.0.0.6.2").
          implicit : integer
            The IMPLICIT tag to use for the encoded object.
            It overrides the universal tag for OBJECT ID (6).
          explicit : integer
            The EXPLICIT tag to use for the encoded object.
        �r"FNrfrhs    rr!zDerObjectId.__init__�s-��	���4��s�H�e�X�F�F�F���
�
�
r"c��d�|j�d��D��}t|��dkrtd���|ddkrtd���|ddkr|ddkrtd	���d
|dz|dzg|dd�z}g}t	|��D]C}|�|dz��|d
z}|r"|�|dzdz��|d
z}|�"�Dd�d�t	|��D����|_t�	|��S)zCReturn the DER OBJECT ID, fully encoded as a
        binary string.c�,�g|]}t|����Sr9)rl�r�rs  rr�z&DerObjectId.encode.<locals>.<listcomp>�s��7�7�7�A��Q���7�7�7r"�.rez$Not a valid Object Identifier stringrz!First component must be 0, 1 or 2r3�'z#Second component must be 39 at most�(NrL�r=r"c�,�g|]}t|����Sr9)rr�s  rr�z&DerObjectId.encode.<locals>.<listcomp>s�� E� E� E�Q��a��� E� E� Er")
rg�splitr*r-�reversedr��joinrArrR)r�comps�subcompsrM�vs     rrRzDerObjectId.encode�sa��8�7���!1�!1�#�!6�!6�7�7�7���u�:�:��>�>��C�D�D�D���8�a�<�<��@�A�A�A���8�a�<�<�E�!�H�r�M�M��B�C�C�C���q��M�E�!�H�,�-��a�b�b�	�9�����(�#�#�	�	�A��O�O�A��H�%�%�%�
�!�G�A��
�����T��T� 1�2�2�2��a����
���x�x� E� E�(�8�2D�2D� E� E� E�F�F�������%�%�%r"Fc�:�t�|||��S)abDecode a complete DER OBJECT ID, and re-initializes this
        object with it.

        Args:
            der_encoded (byte string):
                A complete DER OBJECT ID.
            strict (boolean):
                Whether decoding must check for strict DER compliancy.

        Raises:
            ValueError: in case of parsing errors.
        rprqs   rr\zDerObjectId.decodes������k�6�:�:�:r"c�Z�t�|||��t|j��}g}d}|���rO|���}|dz|dzz}|dzs|�|��d}|����Ot|��dkrtd���|ddkrd|dg|dd�<n1|dd	krd|ddz
g|dd�<nd
|dd	z
g|dd�<d�	d�|D����|_
dS)
z,Decode a complete DER OBJECT ID from a file.rr�rLr=z
Empty payloadr�Nr3�Prer�c�,�g|]}t|����Sr9)�strr�s  rr�z1DerObjectId._decodeFromStream.<locals>.<listcomp>7s��8�8�8�!�s�1�v�v�8�8�8r")rrYrrAr+r4r�r*r-r�rg)rrTr[r_r�r��cs       rrYzDerObjectId._decodeFromStreamsX��	�#�#�D�!�V�4�4�4�
���%�%����
����� � �	����
�
�A��a��A��H�%�A���H�
�����"�"�"������ � �	��x�=�=�A����_�-�-�-��A�;�����x��{�+�H�R�a�R�L�L�
�a�[�2�
�
��x��{�R�/�0�H�R�a�R�L�L��x��{�R�/�0�H�R�a�R�L��X�X�8�8�x�8�8�8�9�9��
�
�
r")r�NNrarxr9r"rrr�sd��������:
�
�
�
�&�&�&�4;�;�;�;� :�:�:�:�:r"rc�.�eZdZdZd	d�Zd�Zd
d�Zd�ZdS)ra�Class to model a DER BIT STRING.

    An example of encoding is:

    >>> from Crypto.Util.asn1 import DerBitString
    >>> bs_der = DerBitString(b'\xAA')
    >>> bs_der.value += b'\xBB'
    >>> print(bs_der.encode().hex())

    which will show ``030300aabb``, the DER encoding for the bit string
    ``b'\xAA\xBB'``.

    For decoding:

    >>> s = bytes.fromhex('030300aabb')
    >>> try:
    >>>   bs_der = DerBitString()
    >>>   bs_der.decode(s)
    >>>   print(bs_der.value.hex())
    >>> except ValueError:
    >>>   print "Not a valid DER BIT STRING"

    the output will be ``aabb``.

    :ivar value: The content of the string
    :vartype value: byte string
    r"Nc��t�|dd|d|��t|t��r|���|_dS||_dS)a�Initialize the DER object as a BIT STRING.

        :Parameters:
          value : byte string or DER object
            The initial, packed bit string.
            If not specified, the bit string is empty.
          implicit : integer
            The IMPLICIT tag to use for the encoded object.
            It overrides the universal tag for BIT STRING (3).
          explicit : integer
            The EXPLICIT tag to use for the encoded object.
        �r"FN)rr!�
isinstancerRrgrhs    rr!zDerBitString.__init__WsT��	���4��s�H�e�X�F�F�F��e�Y�'�'�	������D�J�J�J��D�J�J�Jr"c�T�d|jz|_t�|��S)zBReturn the DER BIT STRING, fully encoded as a
        byte string.r}r~r%s rrRzDerBitString.encodels&��
���+�������%�%�%r"Fc�:�t�|||��S)aTDecode a complete DER BIT STRING, and re-initializes this
        object with it.

        Args:
            der_encoded (byte string): a complete DER BIT STRING.
            strict (boolean):
                Whether decoding must check for strict DER compliancy.

        Raises:
            ValueError: in case of parsing errors.
        rprqs   rr\zDerBitString.decodets������k�6�:�:�:r"c���t�|||��|jr-t|jd��dkrt	d���d|_|jr|jdd�|_dSdS)z1Decode a complete DER BIT STRING DER from a file.rzNot a valid BIT STRINGr"r3N)rrYrArr-rgr�s   rrYzDerBitString._decodeFromStream�s���	�#�#�D�!�V�4�4�4��<�	7�D���a��1�1�Q�6�6��5�6�6�6���
��<�	*���a�b�b�)�D�J�J�J�	*�	*r")r"NNrarxr9r"rrr:sd��������8����*&�&�&�
;�
;�
;�
;�
*�
*�
*�
*�
*r"rc�F�eZdZdZdd�Zd�Zd�Zd�Zd�Zd
d	�Z	d
�Z
d�ZdS)ra�Class to model a DER SET OF.

    An example of encoding is:

    >>> from Crypto.Util.asn1 import DerBitString
    >>> from binascii import hexlify, unhexlify
    >>> so_der = DerSetOf([4,5])
    >>> so_der.add(6)
    >>> print hexlify(so_der.encode())

    which will show ``3109020104020105020106``, the DER encoding
    of a SET OF with items 4,5, and 6.

    For decoding:

    >>> s = unhexlify(b'3109020104020105020106')
    >>> try:
    >>>   so_der = DerSetOf()
    >>>   so_der.decode(s)
    >>>   print [x for x in so_der]
    >>> except ValueError:
    >>>   print "Not a valid DER SET OF"

    the output will be ``[4, 5, 6]``.
    Nc��t�|dd|d��g|_d|_|r|D]}|�|���dSdS)a9Initialize the DER object as a SET OF.

        :Parameters:
          startSet : container
            The initial set of integers or DER encoded objects.
          implicit : integer
            The IMPLICIT tag to use for the encoded object.
            It overrides the universal tag for SET OF (17).
        �r"TN)rr!r��
_elemOctet�add)r�startSetrD�es    rr!zDerSetOf.__init__�sl��	���4��s�H�d�;�;�;���	�����	��
�
����������	�	�
�
r"c��|j|Sr$r�r�s  rr�zDerSetOf.__getitem__�s���y��|�r"c�*�t|j��Sr$)�iterr�r%s r�__iter__zDerSetOf.__iter__�s���D�I���r"c�*�t|j��Sr$r�r%s rr�zDerSetOf.__len__�s���4�9�~�~�r"c�(�t|��rd}n2t|t��r|j}nt	|d��}|j|kr|j�t
d���||_||jvr|j�|��dSdS)z�Add an element to the set.

        Args:
            elem (byte string or integer):
              An element of the same type of objects already in the set.
              It can be an integer or a DER encoded object.
        rerNz&New element does not belong to the set)	rr�rr?rr�r-r�r�)r�elem�eos   rr�zDerSetOf.add�s����d���	��B�B�
��i�
(�
(�	���B�B��d�1�g���B��?�b� � ���*� �!I�J�J�J� �D�O��t�y� � ��I���T�"�"�"�"�"�!� r"Fc�:�t�|||��S)a�Decode a complete SET OF DER element, and re-initializes this
        object with it.

        DER INTEGERs are decoded into Python integers. Any other DER
        element is left undecoded; its validity is not checked.

        Args:
            der_encoded (byte string): a complete DER BIT SET OF.
            strict (boolean):
                Whether decoding must check for strict DER compliancy.

        Raises:
            ValueError: in case of parsing errors.
        rprqs   rr\zDerSetOf.decode�s�� ����k�6�:�:�:r"c��g|_t�|||��t|j��}d}|���dk�r|���t��}|�||��|dkr|j}n||jkrtd���|dkr-|j�	|�
����nUt��}|�|�
��|��|j�	|j
��|���dk��dSdS)z)Decode a complete DER SET OF from a file.���rz)Not all elements are of the same DER typereN)r�rrYrrAr+r&r?r-r�r(r	r\rg)rrTr[r_�
setIdOctetr�r�s       rrYzDerSetOf._decodeFromStream�sI����	�	�#�#�D�!�V�4�4�4�
���%�%���
���� � �1�$�$�
�N�N�����+�+�C��!�!�!�V�,�,�,��A�~�~� �^�
�
����/�/�$�%P�Q�Q�Q��T�!�!��	� � ��!6�!6�!8�!8�9�9�9�9�#�����
�
�a�3�3�5�5�v�>�>�>��	� � ���.�.�.�'��� � �1�$�$�$�$�$�$r"c��g}|jD]t}t|��r"t|�����}n,t	|t
��r|���}n|}|�|���u|���d�|��|_	t
�|��S)zRReturn this SET OF DER element, fully encoded as a
        binary string.
        r")
r�rr	rRr�rr��sortr�rA)r�orderedr��byss    rrRzDerSetOf.encodes������I�	 �	 �D��$���
� ��&�&�-�-�/�/����D�)�,�,�
��k�k�m�m������N�N�3������������x�x��(�(�������%�%�%r")NNra)r5r6r7r8r!r�r�r�r�r\rYrRr9r"rrr�s���������4����*���������#�#�#�0;�;�;�;�$/�/�/�B&�&�&�&�&r"rra)rt�Crypto.Util.py3compatrrr�Crypto.Util.numberrr�__all__r�objectrrr	r
r
rrrrrr9r"r�<module>r�sv��.�
�
�
�9�9�9�9�9�9�9�9�9�9�;�;�;�;�;�;�;�;�P�P�P��+�+�+�+�%�%�%�%�%�&�%�%�%�@sZ�sZ�sZ�sZ�sZ��sZ�sZ�sZ�l\'�\'�\'�\'�\'��\'�\'�\'�~P@�P@�P@�P@�P@��P@�P@�P@�fRJ�RJ�RJ�RJ�RJ�)�RJ�RJ�RJ�j*?�*?�*?�*?�*?�Y�*?�*?�*?�Z9�9�9�9�9�i�9�9�9�s:�s:�s:�s:�s:�)�s:�s:�s:�lV*�V*�V*�V*�V*�9�V*�V*�V*�rU&�U&�U&�U&�U&�y�U&�U&�U&�U&�U&r"