HEX
Server: LiteSpeed
System: Linux srv146.niagahoster.com 4.18.0-553.30.1.lve.el8.x86_64 #1 SMP Tue Dec 3 01:21:19 UTC 2024 x86_64
User: kodi1989 (1633)
PHP: 8.1.34
Disabled: symlink,shell_exec,exec,popen,system,dl,passthru,escapeshellarg,escapeshellcmd,show_source,pcntl_exec
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/pyasn1/codec/ber/__pycache__/decoder.cpython-37.pyc
B

��f�-�2@s0ddlZddlZddlZddlmZddlmZddlmZddlm	Z	ddlm
Z
ddlmZddlmZdd	l
mZdd
lmZddlmZmZmZmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZdddgZej e!ej"d�Z#ej$Z$ej%Z%Gdd�de&�Z'Gdd�de'�Z(Gdd�de(�Z)e)�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(�Z0Gd)d*�d*e(�Z1Gd+d,�d,e'�Z2Gd-d.�d.e2�Z3Gd/d0�d0e3�Z4Gd1d2�d2e4�Z5Gd3d4�d4e4�Z6Gd5d6�d6e3�Z7Gd7d8�d8e7�Z8Gd9d:�d:e7�Z9Gd;d<�d<e3�Z:Gd=d>�d>e(�Z;Gd?d@�d@e.�Z<GdAdB�dBe.�Z=GdCdD�dDe.�Z>GdEdF�dFe.�Z?GdGdH�dHe.�Z@GdIdJ�dJe.�ZAGdKdL�dLe.�ZBGdMdN�dNe.�ZCGdOdP�dPe.�ZDGdQdR�dRe.�ZEGdSdT�dTe.�ZFGdUdV�dVe.�ZGGdWdX�dXe.�ZHGdYdZ�dZe.�ZIejJjKe+�ejLjKe,�ejMjKe-�ejNjKe.�ejOjKe/�ejPjKe0�ejQjKe+�ejRjKe1�ejSjKe4�ejTjKe7�ejUjKe:�ejVjKe<�ejWjKe=�ejXjKe>�ejYjKe?�ejZjKe@�ej[jKeA�ej\jKeB�ej]jKeC�ej^jKeD�ej_jKeE�ej`jKeF�ejajKeG�ejbjKeH�ejcjKeI�iZdejTjee8�ejfjee9�ejSjee5�ejgjee6�ejUjee:�ejhjee;�iZiedZjeiZkxDed�l�D]8Zmemjndk	�r�emjnjojeZeeedk	�r�eeeik�r�emeiee<�q�Wd[d\�epd]�D�\
ZqZrZsZtZuZvZwZxZyZzed^�Z{Gd_d`�d`e&�Z|Gdad�de&�Z}Gdbd�de&�Z~e~�ZdS)c�N)�debug)�error)�eoo)�asSeekableStream)�
isEndOfStream)�peekIntoStream)�readFromStream)�_MISSING)�
from_bytes)�oct2int�	octs2ints�	ints2octs�null)�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$�I/opt/alt/python37/lib/python3.7/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 %sN)rr)	rrrrrr r!r"r#r$r$r%�indefLenValueDecoder4sz+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)�AbstractSimplePayloadDecoderccs xt|||�D]
}|VqWdS)N)r)r(rrr#�chunkr$r$r%�substrateCollectorGsz/AbstractSimplePayloadDecoder.substrateCollectorcKs@|�d�r|S|dkr&|jj||d�S|tkr2|S|�|�SdS)NZnative)r)�getr-�clone�noValue)rrr�valuer#r$r$r%�_createComponentLs
z-AbstractSimplePayloadDecoder._createComponentN)r*r+r,r.r1r6r$r$r$r%r/Fsr/c@s*eZdZe�d�Zddd�Zddd�ZdS)	�RawPayloadDecoder�Ncks^|r8|j||df|�}	x||	|||�D]
}
|
Vq&WdSx |||||f|�D]
}|VqLWdS)Nr8)r6)rrrrrr r!r"r#r(r0r5r$r$r%r&Zs
zRawPayloadDecoder.valueDecodercksz|r8|j||df|�}	x||	|||�D]
}
|
Vq&WdSx<x6|||||fddi|��D]}|tjkrhdS|VqVWq:WdS)Nr8�allowEooT)r6r�endOfOctets)rrrrrr r!r"r#r(r0r5r$r$r%r'is

z&RawPayloadDecoder.indefLenValueDecoder)NNNNN)NNNNN)r*r+r,r�Anyr-r&r'r$r$r$r%r7Ws


r7c@s eZdZe�d�Zddd�ZdS)�IntegerPayloadDecoderrNcksn|djtjkrt�d��x$t|||�D]}	t|	t�r(|	Vq(W|	rRt|	dd�}
nd}
|j	|||
f|�VdS)NrzSimple tag format expectedT)�signed)
�	tagFormatr�tagFormatSimplerrr�
isinstance�SubstrateUnderrunErrorr
r6)rrrrrr r!r"r#r0r5r$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<r6)rrrr5r#r$r$r%r6�sz&BooleanPayloadDecoder._createComponentN)r*r+r,r�Booleanr-r6r$r$r$r%rC�s
rCc@s.eZdZe�d�ZdZddd�Zd	dd�ZdS)
�BitStringPayloadDecoderr$TNcks|r8|j||tf|�}	x||	|||�D]
}
|
Vq&WdS|sFt�d��x t|�D]}
t|
t�rP|
VqPW|
rvt�d��|djtj	k�r x$t
|d|�D]}t|t�r�|Vq�Wt|�}|dkr�t�d|��x(t
||d|�D]}
t|
t�r�|
Vq�W|jj
|
d|d�}|j|||f|�VdS|j�s:t�d|jj��t�rHtd	�|j}|jj
tdd
�}
|��}x�|��||k�r�x4|||jfd|i|��D]}t|t��r�|V�q�Wt|d�}|dk�r�t�d|��|jj
|dd�d|
|d�}
�qhW|j|||
f|�VdS)
NzEmpty BIT STRING substraterrD�zTrailing bits overflow %sT)�internalFormat�paddingz*Constructed encoding form prohibited at %sz$assembling constructed serialization)rHr")rH�prependrI)r6r4rrrr@rAr>rr?r�ordr-�fromOctetString�supportConstructedForm�	__class__r*�LOGr1r�tellr)rrrrrr r!r"r#r(r0�trailingBitsr5�	bitString�current_position�	componentr$r$r%r&�sb











z$BitStringPayloadDecoder.valueDecodercks�|r8|j||tf|�}	x||	|||�D]
}
|
Vq&WdS|j}|jjtdd�}x�x>|||jf|dd�|��D] }|tjkr|Pt|t	�rl|VqlW|tjkr�Pt
|d�}
|
dkr�t�d|
��|jj|dd�d||
d�}qPW|j|||f|�VdS)	NT)rH)r"r9rrGzTrailing bits overflow %srD)rHrJrI)
r6r4r1r-rLrrr:r@rArrr)rrrrrr r!r"r#r(r0rRrTrQr$r$r%r'�s2






z,BitStringPayloadDecoder.indefLenValueDecoder)NNNNN)NNNNN)	r*r+r,r�	BitStringr-rMr&r'r$r$r$r%rF�s

OrFc@s.eZdZe�d�ZdZddd�Zd	dd�ZdS)
�OctetStringPayloadDecoderr8TNcks&|r8|j||tf|�}	x||	|||�D]
}
|
Vq&WdS|djtjkr�x$t|||�D]}
t|
t�rV|
VqVW|j|||
f|�VdS|js�t	�
d|jj��t
r�t
d�|j}t}|��}xP|��||k�rx0|||jfd|i|��D]}
t|
t�r�|
Vq�W||
7}q�W|j|||f|�VdS)Nrz*Constructed encoding form prohibited at %sz$assembling constructed serializationr")r6r4r>rr?rr@rArMrrrNr*rOr1rrPr-)rrrrrr r!r"r#r(r0�header�original_positionrTr$r$r%r&*s4




z&OctetStringPayloadDecoder.valueDecoderc
ks�|rB||jk	rB|j||tf|�}	x||	|||�D]
}
|
Vq0WdS|j}t}xXx>|||jf|dd�|��D] }t|t�r~|V|tjkrjPqjW|tjkr�P||7}qNW|j|||f|�VdS)NT)r"r9)	r1r6r4rr-r@rArr:)
rrrrrr r!r"r#r(r0rWrTr$r$r%r'Ws&




z.OctetStringPayloadDecoder.indefLenValueDecoder)NNNNN)NNNNN)	r*r+r,r�OctetStringr-rMr&r'r$r$r$r%rV&s

,rVc@s eZdZe�d�Zddd�ZdS)�NullPayloadDecoderr8Ncksn|djtjkrt�d��x$t|||�D]}	t|	t�r(|	Vq(W|j||df|�}
|	rdt�d|��|
VdS)NrzSimple tag format expectedr8z&Unexpected %d-octet substrate for Null)	r>rr?rrrr@rAr6)rrrrrr r!r"r#r0rTr$r$r%r&s


zNullPayloadDecoder.valueDecoder)NNNNN)r*r+r,r�Nullr-r&r$r$r$r%rZ|s
rZc@s eZdZe�d�Zddd�ZdS)�ObjectIdentifierPayloadDecoderr$Ncks�|djtjkrt�d��x$t|||�D]}	t|	t�r(|	Vq(W|	sNt�d��t|	�}	d}
d}t	|	�}x�||k�r|	|}
|d7}|
dkr�|
|
f7}
qh|
dk�r|
}d}
xD|dkr�|
d>|d@}
||kr�t�d	|
f��|	|}|d7}q�W|
|
d>|f7}
qh|
dkrht�d
��qhWd|
dk�r4dk�rBnn
d|
}
n|d
|
dk�r^dk�r�nnd|
dd
f|
dd�}
n>|
ddk�r�d|
ddf|
dd�}
nt�d|	d��|j
|||
f|�VdS)NrzSimple tag format expectedzEmpty substrater$rD�rG�z#Short substrate for sub-OID past %sz"Invalid octet 0x80 in OID encoding�')r�(�O�P�zMalformed first OID octet: %s)r>rr?rrrr@rAr�lenr6)rrrrrr r!r"r#r0�oid�indexZsubstrateLenZsubIdZ	nextSubIdr$r$r%r&�sJ





 
 z+ObjectIdentifierPayloadDecoder.valueDecoder)NNNNN)r*r+r,r�ObjectIdentifierr-r&r$r$r$r%r\�s
r\c@seZdZe��Zddd�ZdS)�RealPayloadDecoderNcks�|djtjkrt�d��x$t|||�D]}	t|	t�r(|	Vq(W|	s\|j||df|�VdSt	|	d�}
|	dd�}	|
d@�r�|	s�t�d��t
r�t
d�|
d@d}|d	kr�t	|	d�}|	dd�}	|	d|�|	|d�}}	|r�|	s�t�d
��t	|d�d@�rd�p
d}
x0|�r<|
dK}
|
t	|d�O}
|dd�}�qW|
d	?d@}|d
k�r^t�d��|dk�rr|
d9}
n|d
k�r�|
d	9}
d}x0|	�r�|dK}|t	|	d�O}|	dd�}	�q�W|
d@�r�|}|
d
?d@}|d
|9}|d
|
f}n�|
d@�rt
�rt
d�|
d@�rd�pd}n�|
d@dk�r�|	�s:t�d��t
�rHt
d�y`|
d@dk�rht|	�ddf}n>|
d@d
k�r�t|	�}n&|
d@dk�r�t|	�}nt�d|
��Wn t
k
�r�t�d��YnXnt�d|
��|j|||f|�VdS)NrzSimple tag format expectedgrDr]zIncomplete floating-point valuezdecoding binary encoded REAL��zReal exponent screwed����rczIllegal Real base�@zdecoding infinite REALz-inf�inf�zdecoding character encoded REAL�
zUnknown NR (tag %s)zBad character Real syntaxzUnknown encoding (tag %s))r>rr?rrrr@rAr6rrO�int�float�
ValueError)rrrrrr r!r"r#r0�fo�n�eo�e�b�pZsfr5r$r$r%r&�s�
















zRealPayloadDecoder.valueDecoder)NNNNN)r*r+r,r�Realr-r&r$r$r$r%rh�srhc@seZdZdZdS)�!AbstractConstructedPayloadDecoderN)r*r+r,r-r$r$r$r%r{=sr{c@sBeZdZdZdZdd�Zdd�Zddd�Zd
dd	�Zdd
d�Z	dS)�ConstructedPayloadDecoderBaseNcCs
t��dS)N)�NotImplementedError)rr(�idxr$r$r%�_getComponentTagMapEsz1ConstructedPayloadDecoderBase._getComponentTagMapcCs
t��dS)N)r})rr(rr~r$r$r%�_getComponentPositionByTypeHsz9ConstructedPayloadDecoderBase._getComponentPositionByTypec
ksd}g}t�}|��}	x�|dks0|��|	|kr�x$||f|�D]}
t|
t�r>|
Vq>W|dkrj|
tjkrjP|�|
�|�|
j�t	|�dkr�|j
}n|j}|jt
j|jjf|j��d�}qWtr�td|�x(t|�D]\}}
|j||
dddd�q�W|VdS)NrkrD)rz@guessed %r container type (pass `asn1Spec` to guide the decoder)F)�verifyConstraints�	matchTags�matchConstraints)�setrPr@rArr:�append�addrrd�protoRecordComponent�protoSequenceComponentr3r�TagSet�baseTagZ	superTagsrO�	enumerate�setComponentByPosition)
rrrr!rr#r(�
componentsZcomponentTypesrXrTr-r~r$r$r%�_decodeComponentsSchemalessKs4


z9ConstructedPayloadDecoderBase._decodeComponentsSchemalesscks|djtjkrt�d��|��}	|r�|dk	r8|��}
n&|jdk	rR|jj|d�}
n|j|j	f}
x||
|||�D]
}|VqnWdS|dk�r x2|j
|f|||d�|��D]}
t|
t�r�|
Vq�W|��|	|k�rt
�rx$t||d�D]}t|t�r�|Vq�Wt
dt|�t�|�f�|
VdS|��}
|
��|�|
|�}|jtjjtjjfk�r�|j}
|jtjjk}|�ov|
j}t
�r�t
d|�r�d�p�d	|�r�d
�p�d	|f�t�}d}�x6|��|	|k�r�|
�s�d}nz|�r�|
j}nlyD|�r�|
|j}n.|
|j�s|
|j�r|
�|�}n
|
|j}Wn&t k
�rNt�d|f��YnXx*|||f|�D]}t|t��r`|V�q`W|�s�|
�r�|�r�|
�!|j"�}n&|
|j�s�|
|j�r�|
�#|j"|�}|
j$||dddd
�|�%|�|d7}�q�Wt
�rt
d|�|
�rx|
j&�'|��s&t�d|
j(j)��|
j*�r�|�+di�}t
�rpt
d�x&|�,�D]\}}t
d||f��qRW|�s�|�+dd��r��xt-|
j.�D�]�\}}|j/�s��q�|j�r�|
�0|�j1�sq�|
�2|j/j3�}y||}Wn�t4k
�r�t
�r@t
d|
j(j)|j3|
j(j)|j/j3f�x(|j/�,�D]\}}t
d||f��q"Wy|j/|}Wn.t4k
�r|t
�rtt
d|f��w�YnXYnXt
�r�t
d||f�|
�0|�}|jtj5jtj6jfk�r x�t-|�D]T\}}t7||�8��}x0||fd|i|��D]}t|t��r�|V�q�W|||<�q�WnPt7|
�0|��8��}x0||fd|i|��D]}t|t��rH|V�qHW|
�$||��q�Wn|
j9}|�r|�n~|j}t
�r�t
d|�d}x`|��|	|k�rx*|||f|�D]}t|t��r�|V�q�W|
j$||dddd
�|d7}�q�W|
VdS)NrzConstructed tag format expected)r)rr!r)�contextz)Unused trailing %d octets encountered: %sz5decoding %sdeterministic %s type %r chosen by type IDznon-r8�SETz"Excessive components decoded at %rF)r�r�r�rDzseen component indices %sz,ASN.1 object %s has uninitialized components�	openTypeszuser-specified open types map:z%s -> %r�decodeOpenTypeszJdefault open types map of component "%s.%s" governed by component "%s.%s":z1failed to resolve open type by governing value %rz+resolved open type %r by governing value %rrz+decoding type %r chosen by given `asn1Spec`):r>r�tagFormatConstructedrrrPr3r-r�r�r�r@rArOrrdr�hexdump�clearr)�typeIdr�Sequence�Set�
componentType�hasOptionalOrDefaultr��tagMapUniquer(�
isOptional�isDefaulted�getTagMapNearPosition�
IndexError�getPositionByType�effectiveTagSet�getPositionNearTyper�r��requiredComponents�issubsetrNr*�hasOpenTypesr2�itemsr��
namedTypes�openType�getComponentByPosition�isValue�getComponentByName�name�KeyError�SetOf�
SequenceOfr�asOctets�isInconsistent)rrrrrr r!r"r#rXr(r0Ztrailingr��	isSetType�isDeterministic�seenIndicesr~r�rTr��k�v�	namedType�governingValuer��containerValue�pos�containerElement�stream�
inconsistencyr$r$r%r&~s















z*ConstructedPayloadDecoderBase.valueDecodercks|djtjkrt�d��|dk	r||dk	r4|��}	n&|jdk	rN|jj|d�}	n|j|jf}	x||	|||�D]
}
|
VqjWdS|dkr�x:|j	|f|||d�t
|dd���D]}	t|	t�r�|	Vq�W|	VdS|��}	|	�
�|�|	|�}|jtjjtjjfk�rz|	j}|	jtjjk}|�o |j}
t�rTtd|
�r:d�p<d	|�rHd
�pJd	|f�t�}d}�xPt|�|k�rvd}nz|�r�|j}nlyD|
�r�||j}n.||j�s�||j�r�|�|�}n
||j}Wn&tk
�r�t�d|	f��YnXx@|||fddi|��D]&}t|t��r|V|tjk�rP�qW|tjk�r@P|
�s�|�r�|�r`|� |j!�}n&||j�sx||j�r�|�"|j!|�}|	j#||d
d
d
d�|�$|�|d7}�qbWt�r�td|�|�r
|j%�&|��s�t�d|	j'j(��|j)�rh|�*di�}t�r4td�x&|�+�D]\}}td||f��qW|�sH|�*dd
��rx�x,t,|j-�D�]
\}}|j.�sl�qV|j�r�|	�/|�j0�s��qV|	�1|j.j2�}y||}Wn�t3k
�rFt�rtd|	j'j(|j2|	j'j(|j.j2f�x(|j.�+�D]\}}td||f��q�Wy|j.|}Wn.t3k
�r@t�r8td|f��wVYnXYnXt�r^td||f�|	�/|�}|jtj4jtj5jfk�r�x�t,|�D]j\}}t6||�7��}xF||fd|it
|dd���D]&}t|t��r�|V|tjk�r�P�q�W|||<�q�Wnft6|	�/|��7��}xR||fd|it
|dd���D]2}t|t��r@|V|tjk�rNP|	�#||��q*W�qVWn|	j8}|�r
|�n�|j}t�r�td|�d}xrx@|||fddi|��D]&}t|t��r�|V|tjk�r�P�q�W|tjk�r�P|	j#||d
d
d
d�|d7}�q�W|	VdS)NrzConstructed tag format expected)r)rr!rT)r9z5decoding %sdeterministic %s type %r chosen by type IDznon-r8r�z"Excessive components decoded at %rr9F)r�r�r�rDzseen component indices %sz,ASN.1 object %s has uninitialized componentsr�zuser-specified open types map:z%s -> %rr�zJdefault open types map of component "%s.%s" governed by component "%s.%s":z1failed to resolve open type by governing value %rz+resolved open type %r by governing value %rrz+decoding type %r chosen by given `asn1Spec`)9r>rr�rrr3r-r�r�r��dictr@rAr�r)r�rr�r�r�r�rOr�rdr�r(r�r�r�r�rr:r�r�r�r�r�r�r�rNr*r�r2r�r�r�r�r�r�r�r�r�r�r�rr�r�)rrrrrr r!r"r#r(r0r�r�r�r�r~rTr�r�r�r�r�r�r�r�r�r�r�r�r$r$r%r'Zs*












z2ConstructedPayloadDecoderBase.indefLenValueDecoder)NNN)NNNNN)NNNNN)
r*r+r,r�r�rr�r�r&r'r$r$r$r%r|As
2
\r|c@seZdZe��Ze��ZdS)�"SequenceOrSequenceOfPayloadDecoderN)r*r+r,rr�r�r�r�r$r$r$r%r�Esr�c@seZdZe��ZdS)�SequencePayloadDecoderN)r*r+r,rr�r-r$r$r$r%r�Jsr�c@seZdZe��ZdS)�SequenceOfPayloadDecoderN)r*r+r,rr�r-r$r$r$r%r�Nsr�c@seZdZe��Ze��ZdS)�SetOrSetOfPayloadDecoderN)r*r+r,rr�r�r�r�r$r$r$r%r�Rsr�c@seZdZe��ZdS)�SetPayloadDecoderN)r*r+r,rr�r-r$r$r$r%r�Wsr�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|��}	|rFx||	|||�D]
}
|
Vq4WdS|�|	|�}|	j|kr�trntd|f�xl|||	jf|�D]}t|t�r�|Vq�WnBtr�td|f�x.|||	j|||f|�D]}t|t�r�|Vq�W|j}tr�td||f�|	j	||ddddd�|	VdS)N)rz'decoding %s as explicitly tagged CHOICEzdecoding %s as untagged CHOICEz*decoded component %s, effective tag set %sF)r�r�r��	innerFlag)
r-r3r)rrOZcomponentTagMapr@rAr��setComponentByType)
rrrrrr r!r"r#r(r0rTr�r$r$r%r&bs>





z!ChoicePayloadDecoder.valueDecoderc	ks:|dkr|jj|d�}	n|��}	|rFx||	|||�D]
}
|
Vq4WdS|�|	|�}|	j|k}trxtd||rndppdf�x�|r�|||	jjft|dd��}n |||	jj|||ft|dd��}x^|D]V}
t|
t	�r�|
V|
t
jkr�P|
j}tr�td|
|f�|	j
||
ddddd	�|s�Pq�W|�r*|
t
jkrzPqzW|	VdS)
N)rzdecoding %s as %stagged CHOICEzexplicitly ZunT)r9z*decoded component %s, effective tag set %sF)r�r�r�r�)r-r3r)rrOr�r�r�r@rArr:r�r�)rrrrrr r!r"r#r(r0�isTagged�iteratorrTr�r$r$r%r'�sN





z)ChoicePayloadDecoder.indefLenValueDecoder)NNNNN)NNNNN)r*r+r,r�Choicer-r&r'r$r$r$r%r�_s

2r�c@s(eZdZe��Zddd�Zddd�ZdS)�AnyPayloadDecoderNc
ks|dkrd}	n"|jtjkr&||jk}	n
||jk}	|	r�|j}
|��}|�|
tj	�|||
7}t
r�x"t||�D]}t|t
�rl|VqlWt
dt�|��|r�x*||j||tf|�|||�D]
}|Vq�WdSx$t|||�D]}t|t
�r�|Vq�W|j|||f|�VdS)NTz&decoding as untagged ANY, substrate %s)rNr�TagMap�tagMapr�markedPositionrP�seek�os�SEEK_SETrOrr@rArr�r6r4r)
rrrrrr r!r"r#Z
isUntagged�fullPosition�currentPositionr0r$r$r%r&�s4





zAnyPayloadDecoder.valueDecodercks�|dkrd}	n"|jtjkr&||jk}	n
||jk}	|	rFt}
tr�td�n\|j}|��}|�	|t
j�x(t||||�D]}
t
|
t�rt|
VqtWtr�tdt�|
��|j}|r�||jk	r�|j||tf|�}
x(||
|
||t|
�|�D]
}
|
Vq�WdSt�rtd�|j}x`xB|||f|dd�|��D]&}t
|t��r<|V|tjk�r&P�q&W|tjk�r^P|
|7}
�qW|�rz|
Vn|j|||
f|�VdS)NFzdecoding as tagged ANYz-decoding as untagged ANY, header substrate %sz$assembling constructed serializationT)r"r9)rNrr�r�rrrOr�rPr�r�r�rr@rArr�r-r1r6r4rdrr:)rrrrrr r!r"r#r�r0r�r�r(rTr$r$r%r'sT




z&AnyPayloadDecoder.indefLenValueDecoder)NNNNN)NNNNN)r*r+r,rr;r-r&r'r$r$r$r%r��s

(r�c@seZdZe��ZdS)�UTF8StringPayloadDecoderN)r*r+r,r�
UTF8Stringr-r$r$r$r%r�Psr�c@seZdZe��ZdS)�NumericStringPayloadDecoderN)r*r+r,r�
NumericStringr-r$r$r$r%r�Tsr�c@seZdZe��ZdS)�PrintableStringPayloadDecoderN)r*r+r,r�PrintableStringr-r$r$r$r%r�Xsr�c@seZdZe��ZdS)�TeletexStringPayloadDecoderN)r*r+r,r�
TeletexStringr-r$r$r$r%r�\sr�c@seZdZe��ZdS)�VideotexStringPayloadDecoderN)r*r+r,r�VideotexStringr-r$r$r$r%r�`sr�c@seZdZe��ZdS)�IA5StringPayloadDecoderN)r*r+r,r�	IA5Stringr-r$r$r$r%r�dsr�c@seZdZe��ZdS)�GraphicStringPayloadDecoderN)r*r+r,r�
GraphicStringr-r$r$r$r%r�hsr�c@seZdZe��ZdS)�VisibleStringPayloadDecoderN)r*r+r,r�
VisibleStringr-r$r$r$r%r�lsr�c@seZdZe��ZdS)�GeneralStringPayloadDecoderN)r*r+r,r�
GeneralStringr-r$r$r$r%r�psr�c@seZdZe��ZdS)�UniversalStringPayloadDecoderN)r*r+r,r�UniversalStringr-r$r$r$r%r�tsr�c@seZdZe��ZdS)�BMPStringPayloadDecoderN)r*r+r,r�	BMPStringr-r$r$r$r%r�xsr�c@seZdZe��ZdS)�ObjectDescriptorPayloadDecoderN)r*r+r,r�ObjectDescriptorr-r$r$r$r%r�}sr�c@seZdZe��ZdS)�GeneralizedTimePayloadDecoderN)r*r+r,r�GeneralizedTimer-r$r$r$r%r��sr�c@seZdZe��ZdS)�UTCTimePayloadDecoderN)r*r+r,r�UTCTimer-r$r$r$r%r��sr�cCsg|]}|�qSr$r$)�.0�xr$r$r%�
<listcomp>�sr�rp)rrc@sFeZdZeZe�ZdZeZe	Z	e
e
fdd�Zdddeddfdd�Z
dS)�SingleItemDecoderTcKs8|tk	r|n|j|_|tk	r |n|j|_i|_i|_dS)N)r	�TAG_MAP�_tagMap�TYPE_MAP�_typeMap�	_tagCache�_tagSetCache)rr��typeMapZignoredr$r$r%�__init__�szSingleItemDecoder.__init__Nc#ks�|�dd�}	tr&tdtj|||f�|	r�|jr�x$t|d|�D]}
t|
t�r>|
Vq>W|
tkrvtrjtd�t	j
VdS|�dtj
�|j}|j}|j}
|j}t}|��|_�x�|tk	�r�|tk�rPd}x$t|d|�D]}t|t�r�|Vq�Wt|�}y|
|}Wn�tk
�r�|}|d	@}|d
@}|d@}|dk�r�d}d}d}xpx(t|d|�D]}t|t��rT|V�qTW|�s�t�d
��t|�}|d7}|dK}||d@O}|d@�sFP�qFWtj|||d�}|�r�||
|<YnX|dk�r2|�r$y||}Wn*tk
�r t�d|�}|||<YnXnt�d|�}n||}t}t�rPtd|�|tk�rnx(t|d|�D]}t|t��rh|V�qhWt|�}|dk�r�|}n�|dk�r8|d@}x(t|||�D]}t|t��r�|V�q�Wt|�}t|�|k�rt�d|t|�|f��d}x"|D]}|dK}|t |�O}�qW|d7}nd}|dk�rX|j�sXt�!d��t"}t�rntd|�|t"k�r�|dk�r�t#}nt$}|t#k�rby||}Wntk
�r�d}YnX|�r�t%}n@y||dd�}Wntk
�r�d}YnX|�rt%}nt&}t�rbtd|�r$|j'j(�p&d|t%k�r6d�p8df�tj�)|dk�rVd�p^|j*j'j(�|t$k�r�|j't+j,k�rBy||}Wntk
�r�d}YnXt�rztd�x,|j-�.�D]\}}td||j'j(f��q�W|j/�rtd �x,|j/�.�D]\}}td||j'j(f��q�Wtd!|dk�r0d�p6|�0�|f�n8||j1k�sZ||j2k�rv|}t�rztd"|j'j(�nd}|dk	�r&y$||j3}t�r�td#|j3f�Wnftk
�rt�|j1j4|j1j4�} y || }t�r�td$| f�Wntk
�rd}YnXYnX|�r |}t%}nt&}nd}t&}t�r�td%|t%k�rL|j'j(�pNd|t%k�r^d�p`df�tj�)|dk�r~d�p�|j'j(�|t%k�r�|�5d&d��s�|�s�d'd(�}|��}!|dk�r�x�|j6||||t"||f|�D]}t|t��r�|V�q�Wn�x6|j7||||t"||f|�D]}t|t��r|V�qW|��|!}"|�s`|"|k�r`t!d)|"|f��n |�r�|"|k�r�t!d*|"|f��t�r�td+|j'j(|j'j(t|t8j9��r�|�:��p�|f�t}P|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�r2d�p4d-f�|tAk�rf|jB}t�rbtd.|j'j(�t%}|tCkr�t�!d/||f��q�Wt�r�tj��td0tj�|VdS)1Nr9FzWdecoder called at scope %s with state %d, working with up to %s octets of substrate: %srczend-of-octets sentinel found���TrDro� �rz'Short octet stream on long tag decodingrGr^r])�tagClassr>�tagIdr$z$tag decoded into %s, decoding lengthz%s<%s at %srlrkz6Indefinite length encoding not supported by this codeczvalue length decoded into %dz/codec %s chosen by a built-in type, decoding %sz<none>r5zas 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)D�poprOrZscope�supportIndefLengthrr@rA�EOO_SENTINELrr:r�r��SEEK_CURr�r�r�r�r4rPr��stStop�stDecodeTagrKr�rr�Tagr��stDecodeLength�listrdrr�stGetValueDecoder�stGetValueDecoderByTag�stGetValueDecoderByAsn1Spec�
stDecodeValue�stTryAsExplicitTagrNr*�pushr-rr�ZpresentTypesr�Z	skipTypesZprettyPrintTyperr�r�r�r2r'r&rZAsn1ItemZprettyPrintr>r�r�ZtagClassUniversal�rawPayloadDecoder�defaultErrorState�stDumpRawValue�defaultRawDecoder�stErrorCondition)#rrrrrr r!r"r#r9Z
eoo_candidater�r�ZtagCacheZtagSetCacher5Z
isShortTagZ	firstByteZ
firstOctetZlastTagZ
integerTagr�r>rZlengthOctetIdxZintegerByte�sizeZ
encodedLengthZlengthOctetZconcreteDecoderZ
chosenSpecr�Z
baseTagSetrXZ	bytesReadr$r$r%�__call__�s�




















0"

&

4 
	
"
0

zSingleItemDecoder.__call__)r*r+r,rrr�rrr�r�r	r�r
rr$r$r$r%r��sr�c@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|�|_||_||_dS)N)�SINGLE_ITEM_DECODER�_singleItemDecoderrr�	_asn1Specr)rrrr#r$r$r%r��s
zStreamingDecoder.__init__ccs\xVx$|j|j|jf|j�D]
}|VqWx$t|j�D]}t|t�rHdVPq4W|rPqWdS)N)rrrrrr@rA)rr(r0r$r$r%�__iter__�s

zStreamingDecoder.__iter__)N)r*r+r,�__doc__r�rr�rr$r$r$r%r7sI
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|�}xR|D]J}t|t�r\t�d��ytt|��}Wntjk
r�t}YnX||fSWdS)a�
Turns BER/CER/DER octet stream into an ASN.1 object.

        Takes BER/CER/DER octet-stream in form of :py:class:`bytes` (Python 3)
        or :py:class:`str` (Python 2) 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` (Python 3) or :py:class:`str` (Python 2)
            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		3svy�||||�}WnJtk
r\t��\}}}|jr8�t|tj�sHt�t�	�|||�}YnXx|D]
}|VqdWdS)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�sys�exc_info�tb_nextr@�io�BytesIO�AssertionErrorr�_callSubstrateFunV4asV5)	r(rrr#Z
substrate_gen�_type�_value�	tracebackr5)�origSubstrateFunr$r%�substrateFunWrapper�s
z-Decoder.__call__.<locals>.substrateFunWrapperzShort substrate on input)N)	r�STREAMING_DECODERr@rAr�nextrZEndOfStreamErrorr)�clsrrr#r,ZstreamingDecoderr(�tailr$)r+r%r�sP



zDecoder.__call__ccsT|��}|dkrt|�}||||�\}}|�|�}|��|�|tj�|VdS)Nrk)�readrd�write�truncater�r�r)ZsubstrateFunV4r(rrZsubstrate_bytesr5Z
nextSubstrate�nbytesr$r$r%r's
zDecoder._callSubstrateFunV4asV5)N)
r*r+r,rrr-�classmethodrr.r'r$r$r$r%r�s
y)�r$r�r!Zpyasn1rrZpyasn1.codec.berrZpyasn1.codec.streamingrrrrZ
pyasn1.compatr	Zpyasn1.compat.integerr
Zpyasn1.compat.octetsrrr
rZpyasn1.errorrZpyasn1.typerrrrrr�__all__ZregisterLoggeer*Z
DEBUG_DECODERrOr4rA�objectrr/r7rr<rCrFrVrZr\rhr{r|r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rBrrErUrYr[rgZ
Enumeratedrzr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r;r�r�r��valuesZtypeDecoderr-rN�ranger
rrrrrrrrr	rr�rrrr$r$r$r%�<module>s�
)V<nxy





























&mcD