HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/lib/python3.10/site-packages/asyncssh/__pycache__/asn1.cpython-310.pyc
o

�hw_�@s�UdZddlmZmZmZmZmZmZmZm	Z	ddlm
Z
edZeddd�ZdZ
dZd	Zd
ZdZdZd	Zd
ZdZdZd
ZdZdZdZdZdZiZeeefed<iZ ee	e!efefed<dede"dede#fdd�Z$Gdd�de%�Z&Gdd�de&�Z'Gdd �d e&�Z(Gd!d�d�Z)Gd"d#�d#�Z*Gd$d%�d%�Z+Gd&d'�d'�Z,e*ee-d(�f�Gd)d*�d*e)��Z.e*ee"f�Gd+d,�d,e)��Z/e*eef�Gd-d.�d.e)��Z0e*ee#e1f�Gd/d0�d0e)��Z2e*ee3f�Gd1d2�d2e)��Z4e*ee5e6fd3d4�Gd5d6�d6e)��Z7e*ee8e9fd3d4�Gd7d8�d8e)��Z:e*e�Gd9d:�d:e)��Z;e*e�Gd;d<�d<e)��Z<e*e�Gd=d>�d>e)��Z=d?e!de#fd@dA�Z>dBe#dee!effdCdD�Z?dBe#de!fdEdF�Z@d(S)GaJUtilities for encoding and decoding ASN.1 DER data

   The der_encode function takes a Python value and encodes it in DER
   format, returning a byte string. In addition to supporting standard
   Python types, BitString can be used to encode a DER bit string,
   ObjectIdentifier can be used to encode OIDs, values can be wrapped
   in a TaggedDERObject to set an alternate DER tag on them, and
   non-standard types can be encoded by placing them in a RawDERObject.

   The der_decode function takes a byte string in DER format and decodes
   it into the corresponding Python values.

�)�Dict�	FrozenSet�Sequence�Set�Tuple�Type�TypeVar�Union)�cast�DERType�_DERClassVar�	_DERClass)�bound����������)�	Universal�ApplicationzContext-specific�Private�_der_class_by_tag�_der_class_by_type�
asn1_class�constructed�tag�returncCs�|ttttfvrtd��|d>|rdndB}|dkr ||Bg}n!|d@g}|dkr:|dL}|�d|d@B�|dks)|�|dB�t|d	d	d
��S)z Encode a DER object's identifierzInvalid ASN.1 classr� r����N���)�	UNIVERSAL�APPLICATION�CONTEXT_SPECIFIC�PRIVATE�ASN1EncodeError�append�bytes)rrr �flags�
identifier�r1�@/usr/local/CyberCP/lib/python3.10/site-packages/asyncssh/asn1.py�_encode_identifierDs
�r3c@�eZdZdZdS)�	ASN1ErrorzASN.1 coding errorN��__name__�
__module__�__qualname__�__doc__r1r1r1r2r5Z�r5c@r4)r,zASN.1 DER encoding errorNr6r1r1r1r2r,^r;r,c@r4)�ASN1DecodeErrorzASN.1 DER decoding errorNr6r1r1r1r2r<br;r<c@sNeZdZUdZdZeed<ededefdd��Z	e
ded	edefd
d��ZdS)
rz3Parent class for classes which use DERTag decorator�r0�valuer!cC�t�)z!Encode value as a DER byte string��NotImplementedError�r>r1r1r2�encodek�zDERType.encoder�contentcCr?)z'Decode a DER byte string into an objectr@��clsrrEr1r1r2�decodeqrDzDERType.decodeN)
r7r8r9r:r0r.�__annotations__�staticmethod�objectrC�classmethod�boolrHr1r1r1r2rfs
c@sBeZdZdZ		ddedeedefdd�Zd	e	d
e	fdd�Z
d
S)�DERTagaaA decorator used by classes which convert values to/from DER

       Classes which convert Python values to and from DER format
       should use the DERTag decorator to indicate what DER tag value
       they understand. When DER data is decoded, the tag is looked
       up in the list to see which class to call to perform the
       decoding.

       Classes which convert existing Python types to and from DER
       format can specify the list of types they understand in the
       optional "types" argument. Otherwise, conversion is expected
       to be to and from the new class being defined.

    r1Fr �typesrcCs||_||_tt||�|_dS�N)�_tag�_typesr3r(�_identifier)�selfr rOrr1r1r2�__init__�szDERTag.__init__rGr!cCs<|j|_|t|j<|jr|jD]}|t|<q|S|t|<|SrP)rSr0rrQrRr)rTrG�tr1r1r2�__call__�s


�zDERTag.__call__N)r1F)r7r8r9r:�intrrKrMrUrrWr1r1r1r2rNxs�
�rNc@sxeZdZdZdededefdd�Zdefdd	�Zd
e	de
fdd�Zdefd
d�Zdefdd�Z
ede	defdd��ZdS)�RawDERObjecta7A class which can encode a DER object of an arbitrary type

       This object is initialized with an ASN.1 class, tag, and a
       byte string representing the already encoded data. Such
       objects will never have the constructed flag set, since
       that is represented here as a TaggedDERObject.

    r rErcC�||_||_||_dSrP)rr rE)rTr rErr1r1r2rU�s
zRawDERObject.__init__r!cCs"dt|j�d|j�d|j�d�S)Nz
RawDERObject(�, �))�_asn1_classrr rE�rTr1r1r2�__repr__�s
��zRawDERObject.__repr__�othercC�2t|t�stS|j|jko|j|jko|j|jkSrP)�
isinstancerY�NotImplementedrr rE�rTr`r1r1r2�__eq__��

�
�zRawDERObject.__eq__cC�t|j|j|jf�SrP)�hashrr rEr^r1r1r2�__hash__��zRawDERObject.__hash__cC�t|jd|j�S)�:Encode the DER identifier for this object as a byte stringF�r3rr r^r1r1r2�encode_identifier��zRawDERObject.encode_identifierr>cC�td|�jS)�7Encode the content for this object as a DER byte stringrY)r
rErBr1r1r2rC��zRawDERObject.encodeN)r7r8r9r:rXr.rU�strr_rKrMrerirnrJrCr1r1r1r2rY�s	rYc@s|eZdZdZefdededefdd�Zdefdd	�Z	d
ede
fdd�Zdefd
d�Zde
fdd�Zedede
fdd��ZdS)�TaggedDERObjectauAn explicitly tagged DER object

       This object provides a way to wrap an ASN.1 object with an
       explicit tag. The value (including the tag representing its
       actual type) is then encoded as part of its value. By
       default, the ASN.1 class for these objects is CONTEXT_SPECIFIC,
       and the DER encoding always marks these values as constructed.

    r r>rcCrZrP)rr r>)rTr r>rr1r1r2rU�s
zTaggedDERObject.__init__r!cCsB|jtkrd|j�d|j�d�Sdt|j�d|j�d|j�d�S)NzTaggedDERObject(r[r\)rr*r r>r]r^r1r1r2r_�s
��zTaggedDERObject.__repr__r`cCrarP)rbrtrcrr r>rdr1r1r2re�rfzTaggedDERObject.__eq__cCrgrP)rhrr r>r^r1r1r2ri�rjzTaggedDERObject.__hash__cCrk)rlTrmr^r1r1r2rn�roz!TaggedDERObject.encode_identifiercCsttd|�j�S)rqrt)�
der_encoder
r>rBr1r1r2rC��zTaggedDERObject.encodeN)r7r8r9r:r*rXrKrUrsr_rMrerir.rnrJrCr1r1r1r2rt�s�
�rtNc@s@eZdZdZededefdd��Zede	deddfd	d
��Z
dS)�_NullzA null valuer>r!cCsdS)zEncode a DER null valuer=r1rBr1r1r2rC�sz_Null.encoderrENcCs|rtd��|rtd��dS)zDecode a DER null valuezNULL should not be constructedz'NULL should not have associated contentN�r<rFr1r1r2rH�s
z_Null.decode�r7r8r9r:rJrKr.rCrLrMrHr1r1r1r2rw�srwc@s@eZdZdZededefdd��Zede	dede	fdd	��Z
d
S)�_BooleanzA boolean valuer>r!cCs|rdSdS)zEncode a DER boolean value���r1rBr1r1r2rCrrz_Boolean.encoderrEcCs(|rtd��|dvrtd��t|d�S)zDecode a DER boolean valuez!BOOLEAN should not be constructed>r|r{z$BOOLEAN content must be 0x00 or 0xffr)r<rMrFr1r1r2rHs
z_Boolean.decodeNryr1r1r1r2rz�rzc@�@eZdZdZededefdd��Zede	dede
fdd	��Zd
S)�_IntegerzAn integer valuer>r!cCs`tt|�}|��}|ddkr|ddn|dd}|j|ddd�}|�d�r.|dd	�S|S)
zEncode a DER integer value�rrr%�bigT��signeds��N)r
rX�
bit_length�to_bytes�
startswith)r>�i�l�resultr1r1r2rC's

$z_Integer.encoderrEcCs|rtd��tj|ddd�S)zDecode a DER integer valuez!INTEGER should not be constructedr�Tr�)r<rX�
from_bytesrFr1r1r2rH1sz_Integer.decodeN)r7r8r9r:rJrKr.rCrLrMrXrHr1r1r1r2r#s	rc@s@eZdZdZededefdd��Zede	dedefdd	��Z
d
S)�_OctetStringzAn octet string valuer>r!cCs
tt|�S)zEncode a DER octet string)r
r.rBr1r1r2rC?s
z_OctetString.encoderrEcCs|rtd��|S)zDecode a DER octet stringz&OCTET STRING should not be constructedrxrFr1r1r2rHEsz_OctetString.decodeNryr1r1r1r2r�;r}r�c@r~)�_UTF8StringzA UTF-8 string valuer>r!cCstt|��d�S)zEncode a DER UTF-8 string�utf-8)r
rsrCrBr1r1r2rCSrvz_UTF8String.encoderrEcCs|rtd��|�d�S)zDecode a DER UTF-8 stringz%UTF8 STRING should not be constructedr�)r<rHrFr1r1r2rHYs
z_UTF8String.decodeN)r7r8r9r:rJrKr.rCrLrMrsrHr1r1r1r2r�Or}r�T)rc@�DeZdZdZededefdd��Zede	dede
efdd	��Zd
S)�	_SequencezA sequence of valuesr>r!cCs"ttt|�}d�dd�|D��S)zEncode a sequence of DER valuesr=cs��|]}t|�VqdSrP�ru��.0�itemr1r1r2�	<genexpr>l��z#_Sequence.encode.<locals>.<genexpr>)r
rrK�join)r>�	seq_valuer1r1r2rCgsz_Sequence.encoderrEcCsZ|std��d}t|�}g}||kr)t||d��\}}|�|�||7}||kst|�S)zDecode a sequence of DER valuesz%SEQUENCE should always be constructedrN)r<�len�der_decode_partialr-�tuple�rGrrE�offset�lengthr>r��consumedr1r1r2rHns
�z_Sequence.decodeN)r7r8r9r:rJrKr.rCrLrMrrHr1r1r1r2r�c� r�c@r�)�_SetzA set of DER valuesr>r!cCs2ttttttf|�}d�tdd�|D���S)zEncode a set of DER valuesr=csr�rPr�r�r1r1r2r��r�z_Set.encode.<locals>.<genexpr>)r
r	rrKrr��sorted)r>�	set_valuer1r1r2rC�sz_Set.encoderrEcCs\|std��d}t|�}t�}||kr*t||d��\}}|�|�||7}||kst|�S)zDecode a set of DER valuesz SET should always be constructedrN)r<r��setr��add�	frozensetr�r1r1r2rH�s
�z_Set.decodeN)r7r8r9r:rJrKr.rCrLrMrrHr1r1r1r2r��r�r�c@s�eZdZdZddededefdd�Zd	efd
d�Z	d	efdd
�Z
ded	efdd�Zd	efdd�Ze
ded	efdd��Zededed	dfdd��ZdS)�	BitStringa�A string of bits

       This object can be initialized either with a byte string and an
       optional count of the number of least-significant bits in the last
       byte which should not be included in the value, or with a string
       consisting only of the digits '0' and '1'.

       An optional 'named' flag can also be set, indicating that the
       BitString was specified with named bits, indicating that the proper
       DER encoding of it should strip any trailing zeroes.

    rFr>�unused�namedcs|dks|dkrtd��t�t�r(|r'�std���dd|>d@r'td��n5t�t�rY|r3td��t��d	}|r?d	|nd}�|d
7�t�fdd�tdt��d	�D���ntd
��|r��r��dd|>@s�|d7}|d	kry�dd��d}�r��dd|>@ri�|_||_dS)Nrr%z(Unused bit count must be between 0 and 7z'Can't have unused bits with empty valuer'rz#Unused bits in value should be zeroz:Unused bit count should not be set when providing a stringr��0c3s&�|]}t�||d�d�VqdS)r�rN�rX)r�r�rBr1r2r��s��z%BitString.__init__.<locals>.<genexpr>z#Unexpected type of bit string value)r,rbr.rsr��ranger>r�)rTr>r�r��usedr1rBr2rU�s8
�

��
zBitString.__init__r!cCs0d�dd�|jD��}|jr|d|j�}|S)N�css&�|]}t|�dd��d�VqdS)rNr�)�bin�zfill)r��br1r1r2r��s�$z$BitString.__str__.<locals>.<genexpr>)r�r>r�)rTr�r1r1r2�__str__�szBitString.__str__cCsd|�d�S)NzBitString('�')r1r^r1r1r2r_��zBitString.__repr__r`cCs&t|t�stS|j|jko|j|jkSrP)rbr�rcr>r�rdr1r1r2re�s
zBitString.__eq__cCst|j|jf�SrP)rhr>r�r^r1r1r2ri�szBitString.__hash__cCstd|�}t|jf�|jS)zEncode a DER bit stringr�)r
r.r�r>)r>�bitstr_valuer1r1r2rC�s
zBitString.encoderrEcCs<|rtd��|r|ddkrtd��||dd�|dd�S)zDecode a DER bit stringz$BIT STRING should not be constructedrr%zInvalid unused bit countrN)r�rxrFr1r1r2rH�s
zBitString.decodeN)rF)r7r8r9r:rKrXrMrUrsr�r_rerirJr.rCrLrHr1r1r1r2r��s
#r�c@s�eZdZdZdeeeffdd�Zdefdd�Z	defdd	�Z
d
edefdd�Z
defd
d�Zededefdd��Zedededdfdd��ZdS)�	IA5StringzAn ASCII string valuer>cC�
||_dSrPrB�rTr>r1r1r2rU��
zIA5String.__init__r!cCs|j�d�S)N�ascii)r>rHr^r1r1r2r��r�zIA5String.__str__cCsd|j�d�S)Nz
IA5String(r\rBr^r1r1r2r_�zIA5String.__repr__r`cC�t|t�stS|j|jkSrP)rbr�rcr>rdr1r1r2re�
zIA5String.__eq__cC�
t|j�SrP�rhr>r^r1r1r2ri
r�zIA5String.__hash__cCrp)zEncode a DER IA5 stringr�)r
r>rBr1r1r2rC
s
zIA5String.encoderrEcCs|rtd��||�S)zDecode a DER IA5 stringz$IA5 STRING should not be constructedrxrFr1r1r2rHszIA5String.decodeN)r7r8r9r:r	r.�	bytearrayrUrsr�r_rKrMrerXrirJrCrLrHr1r1r1r2r��sr�c@s�eZdZdZdefdd�Zdefdd�Zdefdd	�Zd
ede	fdd�Z
defd
d�Ze
dedefdd��Zede	deddfdd��ZdS)�ObjectIdentifiera�An object identifier (OID) value

       This object can be initialized from a string of dot-separated
       integer values, representing a hierarchical namespace. All OIDs
       show have at least two components, with the first being between
       0 and 2 (indicating ITU-T, ISO, or joint assignment). In cases
       where the first component is 0 or 1, the second component must
       be in the range 0 to 39 due to the way these first two components
       are encoded.

    r>cCr�rPrBr�r1r1r2rU5r�zObjectIdentifier.__init__r!cCs|jSrPrBr^r1r1r2r�8szObjectIdentifier.__str__cCsd|j�d�S)NzObjectIdentifier('r�rBr^r1r1r2r_;r�zObjectIdentifier.__repr__r`cCr�rP)rbr�rcr>rdr1r1r2re>r�zObjectIdentifier.__eq__cCr�rPr�r^r1r1r2riDr�zObjectIdentifier.__hash__cs�dtdtfdd��td|�}z
dd�|j�d�D�}Wnty'td	�d
�wt|�dkr2td��|d
d
ks>|d
dkrBtd��|d
dkrX|dd
ksT|ddkrXtd��|d
d|dg|d
d�<d��fdd�|D��S)zEncode a DER object identifier�	componentr!cSsV|dkrtd��|d@g}|dkr"|dL}|�d|d@B�|dkst|ddd��S)z7Convert a single element of an OID to a DER byte stringrzBComponents of object identifier must be greater than or equal to 0r#r$r%Nr')r,r-r.)r�r�r1r1r2�_bytesKs
�z'ObjectIdentifier.encode.<locals>._bytesr�cSsg|]}t|��qSr1r��r��cr1r1r2�
<listcomp>\sz+ObjectIdentifier.encode.<locals>.<listcomp>�.z!Component values must be integersNrz4Object identifiers must have at least two componentsrz<First component of object identifier must be between 0 and 2r�'z>Second component of object identifier must be between 0 and 39�(r=c3s�|]}�|�VqdSrPr1r��r�r1r2r�lr�z*ObjectIdentifier.encode.<locals>.<genexpr>)	rXr.r
r>�split�
ValueErrorr,r�r�)r>�	oid_value�
componentsr1r�r2rCGs"
��$zObjectIdentifier.encoderrEcCs�|rtd��|std��|d}|dkrtt|d��nd|dg}d}|dd�D]&}|d	kr7|dkr7td
��|d	krE|�||B�d}q)||d@O}|dK}q)|rVtd
��|d�dd�|D���S)zDecode a DER object identifierz+OBJECT IDENTIFIER should not be constructedzEmpty object identifierr�Pr�rrNr$zInvalid componentr#r%zIncomplete componentr�csr�rP)rsr�r1r1r2r��r�z*ObjectIdentifier.decode.<locals>.<genexpr>)r<�list�divmodr-r�)rGrrEr�r�r�r1r1r2rHns$"
zObjectIdentifier.decodeN)r7r8r9r:rsrUr�r_rKrMrerXrirJr.rCrLrHr1r1r1r2r�'s&r�r>cCs�t|�}|ttfvrttttf|�}|��}|�|�}n|tvr.t|}|j}|�|�}nt	d|j
����t|�}|dkrDt|f�}n|�
|��ddd�}tdt|�Bf�|}|||S)a0Encode a value in DER format

       This function takes a Python value and encodes it in DER format.
       The following mapping of types is used:

       NoneType            -> NULL
       bool                -> BOOLEAN
       int                 -> INTEGER
       bytes, bytearray    -> OCTET STRING
       str                 -> UTF8 STRING
       list, tuple         -> SEQUENCE
       set, frozenset      -> SET
       BitString           -> BIT STRING
       ObjectIdentifier    -> OBJECT IDENTIFIER

       An explicitly tagged DER object can be encoded by passing in a
       TaggedDERObject which specifies the ASN.1 class, tag, and value
       to encode.

       Other types can be encoded by passing in a RawDERObject which
       specifies the ASN.1 class, tag, and raw content octets to encode.

    zCannot DER encode type r$r%r�r�)�typerYrtr
r	rnrCrr0r,r7r�r.r�r�)r>rVr0rErGr��	len_bytesr1r1r2ru�s ru�datacCs�t|�dkr
td��|d}|d?t|d@�|d@}}}d}|dkrKd}||d�D]}|d7}|d	kr<||O}n||d
@O}|dK}q,td��|t|�krUtd��||}|d7}|d	krv|d
@}t�||||�d
�}||7}n|d	kr~td��||}|||�}	|t|�kr�td��|tkr�|tvr�t|}
|
�||	�}||fS|r�t|t	|	�|�}||fSt
||	|�}||fS)zDDecode a value in DER format and return the number of bytes consumedrzIncomplete datarrr"r&rNr$r#r%zIncomplete tagr�zIndefinite length not allowed)r�r<rMrXr�r(rrHrt�
der_decoderY)r�r rrr�r�r��len_size�endrErGr>r1r1r2r��sL 

��r�cCs$t|�\}}|t|�krtd��|S)aDecode a value in DER format

       This function takes a byte string in DER format and converts it
       to a corresponding set of Python objects. The following mapping
       of ASN.1 tags to Python types is used:

       NULL              -> NoneType
       BOOLEAN           -> bool
       INTEGER           -> int
       OCTET STRING      -> bytes
       UTF8 STRING       -> str
       SEQUENCE          -> tuple
       SET               -> frozenset
       BIT_STRING        -> BitString
       OBJECT IDENTIFIER -> ObjectIdentifier

       Explicitly tagged objects are returned as type TaggedDERObject,
       with fields holding the object class, tag, and tagged value.

       Other object tags are returned as type RawDERObject, with fields
       holding the object class, tag, and raw content octets.

       If partial_ok is True, this function returns a tuple of the decoded
       value and number of bytes consumed. Otherwise, all data bytes must
       be consumed and only the decoded value is returned.

    z%Data contains unexpected bytes at end)r�r�r<)r�r>r�r1r1r2r��sr�)Ar:�typingrrrrrrrr	r
r
rr(r)r*r+�END_OF_CONTENT�BOOLEAN�INTEGER�
BIT_STRING�OCTET_STRING�NULL�OBJECT_IDENTIFIER�UTF8_STRING�SEQUENCE�SET�
IA5_STRINGr]rrXrIrrKrMr.r3r�r5r,r<rrNrYrtr�rwrzrr�r�rsr�r�r�r�r�r�r�r�r�r�rur�r�r1r1r1r2�<module>sl($).


W/e/4