Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/site-packages/pyasn1/codec/ber/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/site-packages/pyasn1/codec/ber/__pycache__/decoder.cpython-38.pyc
U

N��gX5�4@s0ddlZddlZddlZddlZddlmZddlmZddlmZddl	m
Z
ddl	mZddl	mZddl	m
Z
dd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZdddgZejeejd�ZejZejZGdd�de �Z!Gdd�de!�Z"Gdd�de"�Z#e#�Z$Gdd�de"�Z%Gdd�de%�Z&Gdd �d e"�Z'Gd!d"�d"e"�Z(Gd#d$�d$e"�Z)Gd%d&�d&e"�Z*Gd'd(�d(e"�Z+Gd)d*�d*e"�Z,Gd+d,�d,e!�Z-Gd-d.�d.e-�Z.Gd/d0�d0e.�Z/Gd1d2�d2e/�Z0Gd3d4�d4e/�Z1Gd5d6�d6e.�Z2Gd7d8�d8e2�Z3Gd9d:�d:e2�Z4Gd;d<�d<e.�Z5Gd=d>�d>e"�Z6Gd?d@�d@e(�Z7GdAdB�dBe(�Z8GdCdD�dDe(�Z9GdEdF�dFe(�Z:GdGdH�dHe(�Z;GdIdJ�dJe(�Z<GdKdL�dLe(�Z=GdMdN�dNe(�Z>GdOdP�dPe(�Z?GdQdR�dRe(�Z@GdSdT�dTe(�ZAGdUdV�dVe(�ZBGdWdX�dXe(�ZCGdYdZ�dZe(�ZDejEjFe%�ejGjFe&�ejHjFe'�ejIjFe(�ejJjFe)�ejKjFe*�ejLjFe+�ejMjFe%�ejNjFe,�ejOjFe/�ejPjFe2�ejQjFe5�ejRjFe7�ejSjFe8�ejTjFe9�ejUjFe:�ejVjFe;�ejWjFe<�ejXjFe=�ejYjFe>�ejZjFe?�ej[jFe@�ej\jFeA�ej]jFeB�ej^jFeC�ej_jFeD�iZ`ejPjae3�ejbjae4�ejOjae0�ejcjae1�ejQjae5�ejdjae6�iZee`�f�D]8Zgegjhdk	�r�egjhjijaZaeadk	�r�eaeek�r�egeeea<�q�d[d\�ejd]�D�\
ZkZlZmZnZoZpZqZrZsZteud^�ZvGd_d`�d`e �ZwGdad�de �ZxGdbd�de �Zyey�Zze{dc�ddde�Z|dS)f�N)�debug)�error)�eoo)�asSeekableStream)�
isEndOfStream)�peekIntoStream��readFromStream)�_MISSING)�PyAsn1Error)�base)�char)�tag)�tagmap)�univ)�useful�StreamingDecoder�Decoder�decode)�flagsc@s0eZdZdZddd�Zd	dd�Zedd��ZdS)
�AbstractPayloadDecoderNc	Kst�d|f��dS)ztDecode value with fixed byte length.

        The decoder is allowed to consume as many bytes as necessary.
        z(SingleItemDecoder not implemented for %sN�rr�	�self�	substrate�asn1Spec�tagSet�length�state�	decodeFun�substrateFun�options�r"�E/opt/cppython/lib/python3.8/site-packages/pyasn1/codec/ber/decoder.py�valueDecoder(sz#AbstractPayloadDecoder.valueDecoderc	Kst�d|f��dS)zsDecode value with undefined length.

        The decoder is allowed to consume as many bytes as necessary.
        z5Indefinite length mode decoder not implemented for %sNrrr"r"r#�indefLenValueDecoder2sz+AbstractPayloadDecoder.indefLenValueDecodercCsd|kr||d<|S)N�
asn1Objectr")r&r!r"r"r#�_passAsn1Object<sz&AbstractPayloadDecoder._passAsn1Object)NNNNN)NNNNN)�__name__�
__module__�__qualname__�protoComponentr$r%�staticmethodr'r"r"r"r#r%s�
�

rc@s eZdZedd��Zdd�ZdS)�AbstractSimplePayloadDecoderccst|||�D]
}|VqdS�Nr)r&rrr!�chunkr"r"r#�substrateCollectorEsz/AbstractSimplePayloadDecoder.substrateCollectorcKs@|�d�r|S|dkr&|jj||d�S|tkr2|S|�|�SdS)N�native�r)�getr+�clone�noValue�rrr�valuer!r"r"r#�_createComponentJs
z-AbstractSimplePayloadDecoder._createComponentN)r(r)r*r,r0r8r"r"r"r#r-Ds
r-c@s*eZdZe�d�Zddd�Zddd�ZdS)	�RawPayloadDecoder�NcksV|r4|j||df|�}	||	|||�D]
}
|
Vq$dS|||||f|�D]
}|VqFdS)Nr:)r8�rrrrrrrr r!r&r/r7r"r"r#r$XszRawPayloadDecoder.valueDecodercksp|r4|j||df|�}	||	|||�D]
}
|
Vq$dS|||||fddi|��D]}|tjkrbdS|VqNq4dS)Nr:�allowEooT)r8r�endOfOctetsr;r"r"r#r%gs$���

z&RawPayloadDecoder.indefLenValueDecoder)NNNNN)NNNNN�r(r)r*r�Anyr+r$r%r"r"r"r#r9Us
�
�r9c@s eZdZe�d�Zddd�ZdS)�IntegerPayloadDecoderrNcksr|djtjkrt�d��t|||�D]}	t|	t�r&|	Vq&|	rVtj	t
|	�ddd�}
nd}
|j|||
f|�VdS)Nr�Simple tag format expected�bigT)�signed)�	tagFormatr�tagFormatSimplerrr	�
isinstance�SubstrateUnderrunError�int�
from_bytes�bytesr8)rrrrrrrr r!r/r7r"r"r#r$�s

z"IntegerPayloadDecoder.valueDecoder)NNNNN)r(r)r*r�Integerr+r$r"r"r"r#r@�s
�r@c@seZdZe�d�Zdd�ZdS)�BooleanPayloadDecoderrcKstj||||rdpdf|�S)N�r)r@r8r6r"r"r#r8�s
��z&BooleanPayloadDecoder._createComponentN)r(r)r*r�Booleanr+r8r"r"r"r#rL�s
rLc@s.eZdZe�d�ZdZddd�Zd	dd�ZdS)
�BitStringPayloadDecoderr"TNcks�|r4|j||tf|�}	||	|||�D]
}
|
Vq$dS|sBt�d��t|�D]}
t|
t�rJ|
VqJ|
rnt�d��|djtj	k�rt
|d|�D]}t|t�r�|Vq�t|�}|dkr�t�d|��t
||d|�D]}
t|
t�r�|
Vq�|jj
|
d|d�}|j|||f|�VdS|j�s*t�d|jj��t�r8td	�|j}|jj
d
dd�}
|��}|��||k�r�|||jfd|i|��D]}t|t��r�|V�q�|d}|dk�r�t�d|��|jj
|dd�d|
|d
�}
�qV|j|||
f|�VdS)NzEmpty BIT STRING substraterrM��Trailing bits overflow %sT)�internalFormat�padding�*Constructed encoding form prohibited at %s�$assembling constructed serialization��rRr �rR�prependrS)r8r5rrrrFrGrDrrEr	�ordr+�fromOctetString�supportConstructedForm�	__class__r(�LOGr0�tell)rrrrrrrr r!r&r/�trailingBitsr7�	bitString�current_position�	componentr"r"r#r$�s~



�
�����


�
�
z$BitStringPayloadDecoder.valueDecodercks�|r4|j||tf|�}	||	|||�D]
}
|
Vq$dS|j}|jjddd�}|||jf|dd�|��D]"}|tjkrvq�t|t�rd|Vqd|tjkr�q�|d}
|
dkr�t	�
d|
��|jj|dd�d||
d	�}qJ|j|||f|�VdS)
NrVTrW�r r<rrPrQrMrX)r8r5r0r+r[rr=rFrGrr)rrrrrrrr r!r&r/rarcr`r"r"r#r%�sD���



�
�z,BitStringPayloadDecoder.indefLenValueDecoder)NNNNN)NNNNN)	r(r)r*r�	BitStringr+r\r$r%r"r"r"r#rO�s
�
Q�rOc@s.eZdZe�d�ZdZddd�Zd	dd�ZdS)
�OctetStringPayloadDecoderr:TNcks|r4|j||tf|�}	||	|||�D]
}
|
Vq$dS|djtjkr~t|||�D]}
t|
t�rP|
VqP|j|||
f|�VdS|js�t	�
d|jj��t
r�t
d�|j}d}|��}|��||kr�|||jfd|i|��D]}
t|
t�r�|
Vq�||
7}q�|j|||f|�VdS)NrrTrUrVr )r8r5rDrrEr	rFrGr\rrr]r(r^r0r_r+)rrrrrrrr r!r&r/�header�original_positionrcr"r"r#r$(s>
���


z&OctetStringPayloadDecoder.valueDecoderc
ks�|r>||jk	r>|j||tf|�}	||	|||�D]
}
|
Vq.dS|j}d}|||jf|dd�|��D]"}t|t�rv|V|tjkrbq�qb|tjkr�q�||7}qH|j|||f|�VdS)NrVTrd)r0r8r5r+rFrGrr=)
rrrrrrrr r!r&r/rgrcr"r"r#r%Us0���




z.OctetStringPayloadDecoder.indefLenValueDecoder)NNNNN)NNNNN)	r(r)r*r�OctetStringr+r\r$r%r"r"r"r#rf$s
�
.�rfc@s eZdZe�d�Zddd�ZdS)�NullPayloadDecoderr:Ncksj|djtjkrt�d��t|||�D]}	t|	t�r&|	Vq&|j||df|�}
|	r`t�d|��|
VdS)NrrAr:z&Unexpected %d-octet substrate for Null)	rDrrErrr	rFrGr8)rrrrrrrr r!r/rcr"r"r#r$}s

zNullPayloadDecoder.valueDecoder)NNNNN)r(r)r*r�Nullr+r$r"r"r"r#rjzs
�rjc@s eZdZe�d�Zddd�ZdS)�ObjectIdentifierPayloadDecoderr"Ncks�|djtjkrt�d��t|||�D]}	t|	t�r&|	Vq&|	sJt�d��d}
d}t|	�}||k�r|	|}
|d7}|
dkr�|
|
f7}
qZ|
dkr�|
}d}
|dkr�|
d>|d@}
||kr�t�d	|
f��|	|}|d7}q�|
|
d>|f7}
qZ|
dkrZt�d
��qZd|
dk�rdk�r,nn
d|
}
n|d
|
dk�rHdk�rjnnd|
dd
f|
dd�}
n>|
ddk�r�d|
ddf|
dd�}
nt�d|	d��|j	|||
f|�VdS)NrrA�Empty substrater"rM�rP��#Short substrate for sub-OID past %sz"Invalid octet 0x80 in OID encoding�')r�(�O�P�zMalformed first OID octet: %s�
rDrrErrr	rFrG�lenr8)rrrrrrrr r!r/�oid�index�substrateLen�subId�	nextSubIdr"r"r#r$�sJ



�
 
 z+ObjectIdentifierPayloadDecoder.valueDecoder)NNNNN)r(r)r*r�ObjectIdentifierr+r$r"r"r"r#rl�s
�rlc@s eZdZe�d�Zddd�ZdS)�RelativeOIDPayloadDecoderr"Ncks|djtjkrt�d��t|||�D]}	t|	t�r&|	Vq&|	sJt�d��d}
d}t|	�}||k�r|	|}
|d7}|
dkr�|
|
f7}
qZ|
dkr�|
}d}
|dkr�|
d>|d@}
||kr�t�d	|
f��|	|}|d7}q�|
|
d>|f7}
qZ|
dkrZt�d
��qZ|j	|||
f|�VdS)NrrArmr"rMrnrProrpz+Invalid octet 0x80 in RELATIVE-OID encodingrv)rrrrrrrr r!r/Zreloidryrzr{r|r"r"r#r$�s<



�
z&RelativeOIDPayloadDecoder.valueDecoder)NNNNN)r(r)r*r�RelativeOIDr+r$r"r"r"r#r~�s
�r~c@seZdZe��Zddd�ZdS)�RealPayloadDecoderNcks�|djtjkrt�d��t|||�D]}	t|	t�r&|	Vq&|	sX|j||df|�VdS|	d}
|	dd�}	|
d@�r�|	s�t�d��t	r�t	d�|
d@d}|d	kr�|	d}|	dd�}	|	d|�|	|d�}}	|r�|	s�t�d
��|dd@r�dp�d}
|�r |
dK}
|
|dO}
|dd�}q�|
d	?d@}|d
k�r@t�d��|dk�rT|
d9}
n|d
k�rf|
d	9}
d}|	�r�|dK}||	dO}|	dd�}	�qj|
d@�r�|}|
d
?d@}|d
|9}|d
|
f}n�|
d@�r�t	�r�t	d�|
d@�r�d�p�d}n�|
d@dk�r�|	�st�d��t	�r"t	d�z`|
d@dk�rBt
|	�ddf}n>|
d@d
k�rZt|	�}n&|
d@dk�rrt|	�}nt�d|
��Wn tk
�r�t�d��YnXnt�d|
��|j|||f|�VdS)NrrAgrMrnzIncomplete floating-point valuezdecoding binary encoded REAL��zReal exponent screwed����ruzIllegal Real base�@zdecoding infinite REALz-inf�inf�zdecoding character encoded REAL�
zUnknown NR (tag %s)zBad character Real syntaxzUnknown encoding (tag %s))
rDrrErrr	rFrGr8r^rH�float�
ValueError)rrrrrrrr r!r/�fo�n�eo�e�b�pZsfr7r"r"r#r$�s�














���zRealPayloadDecoder.valueDecoder)NNNNN)r(r)r*r�Realr+r$r"r"r"r#r��s�r�c@seZdZdZdS)�!AbstractConstructedPayloadDecoderN)r(r)r*r+r"r"r"r#r�isr�c@sBeZdZdZdZdd�Zdd�Zddd�Zd
dd	�Zdd
d�Z	dS)�ConstructedPayloadDecoderBaseNcCst�dSr.��NotImplementedError)rr&�idxr"r"r#�_getComponentTagMapqsz1ConstructedPayloadDecoderBase._getComponentTagMapcCst�dSr.r�)rr&rr�r"r"r#�_getComponentPositionByTypetsz9ConstructedPayloadDecoderBase._getComponentPositionByTypec
ks�d}g}t�}|��}	|dks.|��|	|kr�||f|�D]}
t|
t�r:|
Vq:|dkrd|
tjkrdq�|�|
�|�|
j�t	|�dkr�|j
}n|j}|jt
j|jjf|j��d�}qtr�td|�t|�D]\}}
|j||
dddd�q�|VdS)Nr�rMr2z@guessed %r container type (pass `asn1Spec` to guide the decoder)F��verifyConstraints�	matchTags�matchConstraints)�setr_rFrGrr=�append�addrrw�protoRecordComponent�protoSequenceComponentr4r�TagSet�baseTagZ	superTagsr^�	enumerate�setComponentByPosition)
rrrrrr!r&�
componentsZcomponentTypesrhrcr+r�r"r"r#�_decodeComponentsSchemalessws>

���z9ConstructedPayloadDecoderBase._decodeComponentsSchemalesscks�|djtjkrt�d��|��}	|r||dk	r8|��}
n&|jdk	rR|jj|d�}
n|j|j	f}
||
|||�D]
}|VqldS|dk�r|j
|f|||d�|��D]}
t|
t�r�|
Vq�|��|	|k�r
t
�r
t||d�D]}t|t�r�|Vq�t
dt|�t�|�f�|
VdS|��}
|
��|�|
|�}|jtjjtjjfk�rp|j}
|jtjjk}|�oj|
j}t
�r�t
d|�r�d�p�d	|�r�d
�p�d	|f�t�}d}|��|	|k�r�|
�s�d}nz|�r�|
j}nlzD|�r�|
|j}n.|
|j�s|
|j�r|
�|�}n
|
|j}Wn&t k
�r>t�d|f��YnX|||f|�D]}t|t��rN|V�qN|�s�|
�r�|�r�|
�!|j"�}n&|
|j�s�|
|j�r�|
�#|j"|�}|
j$||dddd
�|�%|�|d7}�q�t
�r�t
d|�|
�rL|
j&�'|��st�d|
j(j)��|
j*�rn|�+di�}t
�rVt
d�|�,�D]\}}t
d||f��q:|�sj|�+dd��rnt-|
j.�D�]�\}}|j/�s��qt|j�r�|
�0|�j1�s��qt|
�2|j/j3�}z||}Wn�t4k
�rdt
�rt
d|
j(j)|j3|
j(j)|j/j3f�|j/�,�D]\}}t
d||f��qz|j/|}Wn2t4k
�r^t
�rRt
d|f�YY�qtYnXYnXt
�r|t
d||f�|
�0|�}|jtj5jtj6jfk�r�t-|�D]P\}}t7||�8��}||fd|i|��D]}t|t��r�|V�q�|||<�q�nLt7|
�0|��8��}||fd|i|��D]}t|t��r |V�q |
�$||��qtn"|
j9}|�r�t�d|
j(j)�d���nv|j}t
�r�t
d|�d}|��|	|k�r�|||f|�D]}t|t��r�|V�q�|
j$||dddd
�|d7}�q�|
VdS)Nr�Constructed tag format expectedr2�rrr)�contextz)Unused trailing %d octets encountered: %s�5decoding %sdeterministic %s type %r chosen by type ID�non-r:�SET�"Excessive components decoded at %rFr�rM�seen component indices %s�,ASN.1 object %s has uninitialized components�	openTypes�user-specified open types map:�%s -> %r�decodeOpenTypes�Jdefault open types map of component "%s.%s" governed by component "%s.%s":�1failed to resolve open type by governing value %r�+resolved open type %r by governing value %rr�
ASN.1 object � is inconsistent�+decoding type %r chosen by given `asn1Spec`):rDr�tagFormatConstructedrrr_r4r+r�r�r�rFrGr^r	rwr�hexdump�clearr'�typeIdr�Sequence�Set�
componentType�hasOptionalOrDefaultr��tagMapUniquer&�
isOptional�isDefaulted�getTagMapNearPosition�
IndexError�getPositionByType�effectiveTagSet�getPositionNearTyper�r��requiredComponents�issubsetr]r(�hasOpenTypesr3�itemsr��
namedTypes�openType�getComponentByPosition�isValue�getComponentByName�name�KeyError�SetOf�
SequenceOfr�asOctets�isInconsistent)rrrrrrrr r!rhr&r/Ztrailingr��	isSetType�isDeterministic�seenIndicesr�r�rcr��k�v�	namedType�governingValuer��containerValue�pos�containerElement�stream�
inconsistencyr"r"r#r$�sV



���


���

�
�������
��

�
�z*ConstructedPayloadDecoderBase.valueDecodercks
|djtjkrt�d��|dk	rx|dk	r4|��}	n&|jdk	rN|jj|d�}	n|j|jf}	||	|||�D]
}
|
VqhdS|dkr�|j	|f|||d�t
|dd���D]}	t|	t�r�|	Vq�|	VdS|��}	|	�
�|�|	|�}|jtjjtjjfk�rr|	j}|	jtjjk}|�o|j}
t�rLtd|
�r2d�p4d	|�r@d
�pBd	|f�t�}d}t|�|k�rjd}nz|�rx|j}nlzD|
�r�||j}n.||j�s�||j�r�|�|�}n
||j}Wn&tk
�r�t�d|	f��YnX|||fddi|��D]*}t|t��r|V|tjk�r��q&�q�|tjk�r6�q�|
�s||�r||�rV|� |j!�}n&||j�sn||j�r||�"|j!|�}|	j#||d
d
d
d�|�$|�|d7}�qVt�r�td|�|�r|j%�&|��s�t�d|	j'j(��|j)�rN|�*di�}t�r$td�|�+�D]\}}td||f��q|�s8|�*dd
��rpt,|j-�D�]\}}|j.�sX�qB|j�rr|	�/|�j0�sr�qB|	�1|j.j2�}z||}Wn�t3k
�r2t�r�td|	j'j(|j2|	j'j(|j.j2f�|j.�+�D]\}}td||f��q�z|j.|}Wn2t3k
�r,t�r td|f�YY�qBYnXYnXt�rJtd||f�|	�/|�}|jtj4jtj5jfk�r�t,|�D]j\}}t6||�7��}||fd|it
|dd���D]*}t|t��r�|V|tjk�r��qԐq�|||<�qtnft6|	�/|��7��}||fd|it
|dd���D]6}t|t��r&|V|tjk�r8�qB|	�#||��q�qBn"|	j8}|�rt�d|	j'j(�d���n�|j}t�r�td|�d}|||fddi|��D]*}t|t��r�|V|tjk�r��qАq�|tjk�r�q|	j#||d
d
d
d�|d7}�q�|	VdS)Nrr�r2r�T�r<r�r�r:r�r�r<Fr�rMr�r�r�r�r�r�r�r�r�rr�r�r�)9rDrr�rrr4r+r�r�r��dictrFrGr�r'r�rr�r�r�r�r^r�rwr�r&r�r�r�r�rr=r�r�r�r�r�r�r�r]r(r�r3r�r�r�r�r�r�r�r�r�r�r�rr�r�)rrrrrrrr r!r&r/r�r�r�r�r�rcr�r�r�r�r�r�r�r�r�r�r�r�r"r"r#r%�sl


��
�

��

�
�������
��
�


�
����

�z2ConstructedPayloadDecoderBase.indefLenValueDecoder)NNN)NNNNN)NNNNN)
r(r)r*r�r�r�r�r�r$r%r"r"r"r#r�ms*�
4�
_�r�c@seZdZe��Ze��ZdS)�"SequenceOrSequenceOfPayloadDecoderN)r(r)r*rr�r�r�r�r"r"r"r#r�ssr�c@seZdZe��ZdS)�SequencePayloadDecoderN)r(r)r*rr�r+r"r"r"r#r�xsr�c@seZdZe��ZdS)�SequenceOfPayloadDecoderN)r(r)r*rr�r+r"r"r"r#r�|sr�c@seZdZe��Ze��ZdS)�SetOrSetOfPayloadDecoderN)r(r)r*rr�r�r�r�r"r"r"r#r��sr�c@seZdZe��ZdS)�SetPayloadDecoderN)r(r)r*rr�r+r"r"r"r#r��sr�c@seZdZe��ZdS)�SetOfPayloadDecoderN)r(r)r*rr�r+r"r"r"r#r��sr�c@s(eZdZe��Zddd�Zddd�ZdS)�ChoicePayloadDecoderNc
ks
|dkr|jj|d�}	n|��}	|rB||	|||�D]
}
|
Vq2dS|�|	|�}|	j|kr�trjtd|f�|||	jf|�D]}t|t�rz|Vqzn>tr�td|f�|||	j|||f|�D]}t|t�r�|Vq�|j}tr�td||f�|	j	||ddddd�|	VdS)Nr2z'decoding %s as explicitly tagged CHOICEzdecoding %s as untagged CHOICE�*decoded component %s, effective tag set %sF�r�r�r�Z	innerFlag)
r+r4r'rr^ZcomponentTagMaprFrGr��setComponentByType)
rrrrrrrr r!r&r/rcr�r"r"r#r$�sX
��

��
�z!ChoicePayloadDecoder.valueDecoderc	ks8|dkr|jj|d�}	n|��}	|rB||	|||�D]
}
|
Vq2dS|�|	|�}|	j|k}trttd||rjdpldf�|r�|||	jjft|dd��}n |||	jj|||ft|dd��}|D]^}
t|
t	�r�|
V|
t
jkr��q|
j}tr�td|
|f�|	j
||
ddddd	�|s��qq�|�r.|
t
jkrt�q.qt|	VdS)
Nr2zdecoding %s as %stagged CHOICEzexplicitly �unTr�r�Fr�)r+r4r'rr^r�r�r�rFrGrr=r�r�)rrrrrrrr r!r&r/�isTagged�iteratorrcr�r"r"r#r%�sj

��
��
�

��z)ChoicePayloadDecoder.indefLenValueDecoder)NNNNN)NNNNN)r(r)r*r�Choicer+r$r%r"r"r"r#r��s�
4�r�c@s(eZdZe��Zddd�Zddd�ZdS)�AnyPayloadDecoderNc
ks�|dkrd}	n"|jtjkr&||jk}	n
||jk}	|	r�|j}
|��}|�|
tj	�|||
7}t
r�t||�D]}t|t
�rj|Vqjt
dt�|��|r�||j||tf|�|||�D]
}|Vq�dSt|||�D]}t|t
�r�|Vq�|j|||f|�VdS)NTz&decoding as untagged ANY, substrate %s)r]r�TagMap�tagMapr�markedPositionr_�seek�os�SEEK_SETr^rrFrGrr�r8r5r	)
rrrrrrrr r!Z
isUntagged�fullPosition�currentPositionr/r"r"r#r$s<

��
zAnyPayloadDecoder.valueDecodercks�|dkrd}	n"|jtjkr&||jk}	n
||jk}	|	rFd}
tr�td�nX|j}|��}|�|t	j
�t||||�D]}
t|
t
�rr|
Vqrtr�tdt�|
��|j}|r�||jk	r�|j||tf|�}
||
|
||t|
�|�D]
}
|
Vq�dStr�td�|j}|||f|dd�|��D]*}t|t
��r.|V|tjk�r�qD�q|tjk�rT�q`|
|7}
�q|�rn|
Vn|j|||
f|�VdS)NFrVzdecoding as tagged ANYz-decoding as untagged ANY, header substrate %srUTrd)r]rr�r�rr^r�r_r�r�r�r	rFrGrr�r+r0r8r5rwrr=)rrrrrrrr r!r�r/r�r�r&rcr"r"r#r%1sp


��
����

z&AnyPayloadDecoder.indefLenValueDecoder)NNNNN)NNNNNr>r"r"r"r#r�s�
*�r�c@seZdZe��ZdS)�UTF8StringPayloadDecoderN)r(r)r*r
�
UTF8Stringr+r"r"r"r#r�~sr�c@seZdZe��ZdS)�NumericStringPayloadDecoderN)r(r)r*r
�
NumericStringr+r"r"r"r#r�src@seZdZe��ZdS)�PrintableStringPayloadDecoderN)r(r)r*r
�PrintableStringr+r"r"r"r#r�src@seZdZe��ZdS)�TeletexStringPayloadDecoderN)r(r)r*r
�
TeletexStringr+r"r"r"r#r�src@seZdZe��ZdS)�VideotexStringPayloadDecoderN)r(r)r*r
�VideotexStringr+r"r"r"r#r�src@seZdZe��ZdS)�IA5StringPayloadDecoderN)r(r)r*r
�	IA5Stringr+r"r"r"r#r	�sr	c@seZdZe��ZdS)�GraphicStringPayloadDecoderN)r(r)r*r
�
GraphicStringr+r"r"r"r#r�src@seZdZe��ZdS)�VisibleStringPayloadDecoderN)r(r)r*r
�
VisibleStringr+r"r"r"r#r
�sr
c@seZdZe��ZdS)�GeneralStringPayloadDecoderN)r(r)r*r
�
GeneralStringr+r"r"r"r#r�src@seZdZe��ZdS)�UniversalStringPayloadDecoderN)r(r)r*r
�UniversalStringr+r"r"r"r#r�src@seZdZe��ZdS)�BMPStringPayloadDecoderN)r(r)r*r
�	BMPStringr+r"r"r"r#r�src@seZdZe��ZdS)�ObjectDescriptorPayloadDecoderN)r(r)r*r�ObjectDescriptorr+r"r"r"r#r�src@seZdZe��ZdS)�GeneralizedTimePayloadDecoderN)r(r)r*r�GeneralizedTimer+r"r"r"r#r�src@seZdZe��ZdS)�UTCTimePayloadDecoderN)r(r)r*r�UTCTimer+r"r"r"r#r�srcCsg|]}|�qSr"r")�.0�xr"r"r#�
<listcomp>�srr�)rrc@sFeZdZeZe�ZdZeZe	Z	e
e
fdd�Zdddeddfdd�Z
dS)�SingleItemDecoderTcKs8|tk	r|n|j|_|tk	r |n|j|_i|_i|_dSr.)r
�TAG_MAP�_tagMap�TYPE_MAP�_typeMap�	_tagCache�_tagSetCache)rr��typeMapZignoredr"r"r#�__init__szSingleItemDecoder.__init__Nc#ksz|�dd�}	tr&tdtj|||f�|	r�|jr�t|d|�D]}
t|
t�r<|
Vq<|
tkrrtrftd�t	j
VdS|�dtj
�|j}|j}|j}
|j}t}|��|_|tk	�rR|tk�r>d}t|d|�D]}t|t�r�|Vq�t|�}z|
|}Wn�tk
�r�|}|d	@}|d
@}|d@}|dk�r�d}d}d}t|d|�D]}t|t��rD|V�qD|�snt�d
��t|�}|d7}|dK}||d@O}|d@�s8�q��q8tj|||d�}|�r�||
|<YnX|dk�r |�rz||}Wn*tk
�rt�d|�}|||<YnXnt�d|�}n||}t}t�r>td|�|tk�rLt|d|�D]}t|t��rT|V�qTt|�}|dk�r�|}n�|dk�r|d@}t|||�D]}t|t��r�|V�q�t|�}t|�|k�r�t�d|t|�|f��d}|D]}|dK}||O}�q�|d7}nd}|dk�r6|j�s6t� d��t!}t�rLtd|�|t!k�rj|dk�rft"}nt#}|t"k�r@z||}Wntk
�r�d}YnX|�r�t$}n@z||dd�}Wntk
�r�d}YnX|�r�t$}nt%}t�r@td|�r|j&j'�pd|t$k�rd�pdf�tj�(|dk�r4d�p<|j)j&j'�|t#k�r^|j&t*j+k�rz||}Wntk
�r~d}YnXt�rPtd�|j,�-�D]\}}td||j&j'f��q�|j.�r�td �|j.�-�D]\}}td||j&j'f��q�td!|dk�rd�p|�/�|f�n8||j0k�s0||j1k�rL|}t�rPtd"|j&j'�nd}|dk	�r�z$||j2}t�r|td#|j2f�Wnftk
�r�t�|j0j3|j0j3�} z || }t�r�td$| f�Wntk
�r�d}YnXYnX|�r�|}t$}nt%}nd}t%}t�r^td%|t$k�r"|j&j'�p$d|t$k�r4d�p6df�tj�(|dk�rTd�pZ|j&j'�|t$k�r�|�4d&d��s�|�s�d'd(�}|��}!|dk�r�|j5||||t!||f|�D]}t|t��r�|V�q�n�|j6||||t!||f|�D]}t|t��r�|V�q�|��|!}"|�s.|"|k�r.t d)|"|f��n |�rN|"|k�rNt d*|"|f��t�r�td+|j&j'|j&j't|t7j8��r||�9��p~|f�t}�qR|t%k�r|�r�|dj:tj;k�r�|dj<tj=k�r�t>}t$}n
d}|j?}t�rtd,|�r�|j&j'�p�d|t$k�rd�pd-f�|t@k�r6|jA}t�r2td.|j&j'�t$}|tBkr�t� d/||f��q�t�rptj��td0tj�|VdS)1Nr<FzWdecoder called at scope %s with state %d, working with up to %s octets of substrate: %sruzend-of-octets sentinel found���TrMr�� �rz'Short octet stream on long tag decodingrProrn)�tagClassrD�tagIdr"z$tag decoded into %s, decoding lengthz%s<%s at %sr�r�z6Indefinite length encoding not supported by this codeczvalue length decoded into %dz/codec %s chosen by a built-in type, decoding %sz<none>r7zas explicit tag�?z!candidate ASN.1 spec is a map of:z
  %s -> %szbut neither of: z,new candidate ASN.1 spec is %s, chosen by %szcandidate ASN.1 spec is %sz8value decoder chosen for an ambiguous type by type ID %szvalue decoder chosen by base %sz*codec %s chosen by ASN.1 spec, decoding %sZ
recursiveFlagcss
|VdS)aeLegacy hack to keep the recursiveFlag=False option supported.

                        The decode(..., substrateFun=userCallback) option was introduced in 0.1.4 as a generalization
                        of the old recursiveFlag=False option. Users should pass their callback instead of using
                        recursiveFlag.
                        Nr")r&�
_substrate�_length�_optionsr"r"r#r sz0SingleItemDecoder.__call__.<locals>.substrateFunz%Read %s bytes instead of expected %s.z(Read %s bytes are more than expected %s.z&codec %s yields type %s, value:
%s
...zcodec %s chosen, decoding %sz
as failurezcodec %s chosen, decoding valuez%s not in asn1Spec: %rz%decoder left scope %s, call completed)C�popr^r�scope�supportIndefLengthr	rFrG�EOO_SENTINELrr=r�r��SEEK_CURr r"r#r$r5r_r��stStop�stDecodeTagrZr�rr�Tagr��stDecodeLength�listrwr�stGetValueDecoder�stGetValueDecoderByTag�stGetValueDecoderByAsn1Spec�
stDecodeValue�stTryAsExplicitTagr]r(�pushr+rr�ZpresentTypesr�Z	skipTypesZprettyPrintTyperr�r�r�r3r%r$rZAsn1ItemZprettyPrintrDr�r*ZtagClassUniversal�rawPayloadDecoder�defaultErrorState�stDumpRawValue�defaultRawDecoder�stErrorCondition)#rrrrrrrr r!r<Z
eoo_candidater�r%ZtagCacheZtagSetCacher7Z
isShortTagZ	firstByteZ
firstOctetZlastTagZ
integerTagr*rDr+ZlengthOctetIdxZintegerByte�sizeZ
encodedLengthZlengthOctetZconcreteDecoderZ
chosenSpecr�Z
baseTagSetrhZ	bytesReadr"r"r#�__call__	s��







�
�





�






0"

&

4 
	
����

�
��
��0

�
zSingleItemDecoder.__call__)r(r)r*rDrAr�rCr2rr!r
r&r6rFr"r"r"r#r�s�rc@s&eZdZdZeZddd�Zdd�ZdS)ra�	Create an iterator that turns BER/CER/DER byte stream into ASN.1 objects.

    On each iteration, consume whatever BER/CER/DER serialization is
    available in the `substrate` stream-like object and turns it into
    one or more, possibly nested, ASN.1 objects.

    Parameters
    ----------
    substrate: :py:class:`file`, :py:class:`io.BytesIO`
        BER/CER/DER serialization in form of a byte stream

    Keyword Args
    ------------
    asn1Spec: :py:class:`~pyasn1.type.base.PyAsn1Item`
        A pyasn1 type object to act as a template guiding the decoder.
        Depending on the ASN.1 structure being decoded, `asn1Spec` may
        or may not be required. One of the reasons why `asn1Spec` may
        me required is that ASN.1 structure is encoded in the *IMPLICIT*
        tagging mode.

    Yields
    ------
    : :py:class:`~pyasn1.type.base.PyAsn1Item`, :py:class:`~pyasn1.error.SubstrateUnderrunError`
        Decoded ASN.1 object (possibly, nested) or
        :py:class:`~pyasn1.error.SubstrateUnderrunError` object indicating
        insufficient BER/CER/DER serialization on input to fully recover ASN.1
        objects from it.
        
        In the latter case the caller is advised to ensure some more data in
        the input stream, then call the iterator again. The decoder will resume
        the decoding process using the newly arrived data.

        The `context` property of :py:class:`~pyasn1.error.SubstrateUnderrunError`
        object might hold a reference to the partially populated ASN.1 object
        being reconstructed.

    Raises
    ------
    ~pyasn1.error.PyAsn1Error, ~pyasn1.error.EndOfStreamError
        `PyAsn1Error` on deserialization error, `EndOfStreamError` on
         premature stream closure.

    Examples
    --------
    Decode BER serialisation without ASN.1 schema

    .. code-block:: pycon

        >>> stream = io.BytesIO(
        ...    b'0	')
        >>>
        >>> for asn1Object in StreamingDecoder(stream):
        ...     print(asn1Object)
        >>>
        SequenceOf:
         1 2 3

    Decode BER serialisation with ASN.1 schema

    .. code-block:: pycon

        >>> stream = io.BytesIO(
        ...    b'0	')
        >>>
        >>> schema = SequenceOf(componentType=Integer())
        >>>
        >>> decoder = StreamingDecoder(stream, asn1Spec=schema)
        >>> for asn1Object in decoder:
        ...     print(asn1Object)
        >>>
        SequenceOf:
         1 2 3
    NcKs(|jf|�|_t|�|_||_||_dSr.)�SINGLE_ITEM_DECODER�_singleItemDecoderrr-�	_asn1Specr/)rrrr!r"r"r#r&�s
zStreamingDecoder.__init__ccsR|j|j|jf|j�D]
}|Vqt|j�D]}t|t�r@dVqFq,|rqNqdSr.)rHr-rIr/rrFrG)rr&r/r"r"r#�__iter__�s��
zStreamingDecoder.__iter__)N)r(r)r*�__doc__rrGr&rJr"r"r"r#rbsJ
c@s.eZdZdZeZeddd��Zedd��Z	dS)rznCreate a BER decoder object.

    Parse BER/CER/DER octet-stream into one, possibly nested, ASN.1 object.
    Nc	s�t|�}d|kr.|d�d�fdd�	}||d<|j||f|�}|D]N}t|t�rZt�d��ztt|��}Wntjk
r�d}YnX||fSdS)a.
Turns BER/CER/DER octet stream into an ASN.1 object.

        Takes BER/CER/DER octet-stream in form of :py:class:`bytes`
        and decode it into an ASN.1 object
        (e.g. :py:class:`~pyasn1.type.base.PyAsn1Item` derivative) which
        may be a scalar or an arbitrary nested structure.

        Parameters
        ----------
        substrate: :py:class:`bytes`
            BER/CER/DER octet-stream to parse

        Keyword Args
        ------------
        asn1Spec: :py:class:`~pyasn1.type.base.PyAsn1Item`
            A pyasn1 type object (:py:class:`~pyasn1.type.base.PyAsn1Item`
            derivative) to act as a template guiding the decoder.
            Depending on the ASN.1 structure being decoded, `asn1Spec` may or
            may not be required. Most common reason for it to require is that
            ASN.1 structure is encoded in *IMPLICIT* tagging mode.

        substrateFun: :py:class:`Union[
                Callable[[pyasn1.type.base.PyAsn1Item, bytes, int],
                         Tuple[pyasn1.type.base.PyAsn1Item, bytes]],
                Callable[[pyasn1.type.base.PyAsn1Item, io.BytesIO, int, dict],
                         Generator[Union[pyasn1.type.base.PyAsn1Item,
                                         pyasn1.error.SubstrateUnderrunError],
                                   None, None]]
            ]`
            User callback meant to generalize special use cases like non-recursive or
            partial decoding. A 3-arg non-streaming variant is supported for backwards
            compatiblilty in addition to the newer 4-arg streaming variant.
            The callback will receive the uninitialized object recovered from substrate
            as 1st argument, the uninterpreted payload as 2nd argument, and the length
            of the uninterpreted payload as 3rd argument. The streaming variant will
            additionally receive the decode(..., **options) kwargs as 4th argument.
            The non-streaming variant shall return an object that will be propagated
            as decode() return value as 1st item, and the remainig payload for further
            decode passes as 2nd item.
            The streaming variant shall yield an object that will be propagated as
            decode() return value, and leave the remaining payload in the stream.

        Returns
        -------
        : :py:class:`tuple`
            A tuple of :py:class:`~pyasn1.type.base.PyAsn1Item` object
            recovered from BER/CER/DER substrate and the unprocessed trailing
            portion of the `substrate` (may be empty)

        Raises
        ------
        : :py:class:`~pyasn1.error.PyAsn1Error`
            :py:class:`~pyasn1.error.SubstrateUnderrunError` on insufficient
            input or :py:class:`~pyasn1.error.PyAsn1Error` on decoding error.

        Examples
        --------
        Decode BER/CER/DER serialisation without ASN.1 schema

        .. code-block:: pycon

           >>> s, unprocessed = decode(b'0	')
           >>> str(s)
           SequenceOf:
            1 2 3

        Decode BER/CER/DER serialisation with ASN.1 schema

        .. code-block:: pycon

           >>> seq = SequenceOf(componentType=Integer())
           >>> s, unprocessed = decode(
                b'0	', asn1Spec=seq)
           >>> str(s)
           SequenceOf:
            1 2 3

        r Nc
3stz�||||�}WnLtk
r^}z.|jjr.�t|tj�s>t�t��|||�}W5d}~XYnX|D]
}|VqddS)arSupport both 0.4 and 0.5 style APIs.

                substrateFun API has changed in 0.5 for use with streaming decoders. To stay backwards compatible,
                we first try if we received a streaming user callback. If that fails,we assume we've received a
                non-streaming v0.4 user callback and convert it for streaming on the fly
                N)	�	TypeError�
__traceback__�tb_nextrF�io�BytesIO�AssertionErrorr�_callSubstrateFunV4asV5)r&rrr!Z
substrate_gen�_valuer7�ZorigSubstrateFunr"r#�substrateFunWrapper!s"z-Decoder.__call__.<locals>.substrateFunWrapperzShort substrate on inputrV)N)r�STREAMING_DECODERrFrGr�nextr	ZEndOfStreamError)�clsrrr!rUZstreamingDecoderr&�tailr"rTr#rF�s&P��


zDecoder.__call__ccsT|��}|dkrt|�}||||�\}}|�|�}|��|�|tj�|VdS)Nr�)�readrw�write�truncater�r�r4)ZsubstrateFunV4r&rrZsubstrate_bytesr7Z
nextSubstrate�nbytesr"r"r#rREs
zDecoder._callSubstrateFunV4asV5)N)
r(r)r*rKrrV�classmethodrFr,rRr"r"r"r#r�sx)�attrcCsBddd��|�}r6t�|�d|�d�t�t�|St|��dS)Nrr!)r�r%z is deprecated. Please use z	 instead.)r3�warnings�warn�DeprecationWarning�globals�AttributeError)r_ZnewAttrr"r"r#�__getattr__�s
re)}rOr��sysr`Zpyasn1rrZpyasn1.codec.berrZpyasn1.codec.streamingrrrr	Z
pyasn1.compatr
Zpyasn1.errorrZpyasn1.typerr
rrrr�__all__ZregisterLoggeer(Z
DEBUG_DECODERr^r5rG�objectrr-r9r@r@rLrOrfrjrlr~r�r�r�r�r�r�r�r�r�r�r�r�rrrrr	rr
rrrrrrrKrrNrerirkr}rZ
Enumeratedr�r�r�r�rrrrrr
rrrrrrrrrr�r�r�r?r!�valuesZtypeDecoderr+r]�ranger6r8r:r<r;r>r=rBrDr5rJr3rrrr�strrer"r"r"r#�<module>s4
)V:0n
xy�!�

�mcC

F1le Man4ger