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: sport3497 (1034)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/lib64/python3.10/site-packages/ecdsa/__pycache__/test_der.cpython-310.pyc
o

�h�I�@s�ddlZddlmZzddlZWn
eyddlZYnwddlZddlmZ	ddl
mZmZddl
Z
ddlmZddlmZmZddlmZmZmZmZmZmZmZmZmZmZmZmZGdd	�d	ej �Z!Gd
d�dej �Z"Gdd
�d
ej �Z#Gdd�dej �Z$Gdd�dej �Z%Gdd�dej �Z&Gdd�dej �Z'Gdd�dej �Z(Gdd�dej �Z)Gdd�dej �Z*Gdd�dej �Z+Gdd�dej �Z,e	j-d d!d"fd#d$��Z.iZ/d%ej0vr�d e/d&<ed)ie/��ee.��d'd(���Z1dS)*�N)�hexlify)�given�settings�)�str_idx_as_int)�NIST256p�NIST224p)�remove_integer�
UnexpectedDER�read_length�encode_bitstring�remove_bitstring�
remove_object�
encode_oid�remove_constructed�remove_implicit�remove_octet_string�remove_sequence�encode_implicitc@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�TestRemoveIntegercC�8|�t��
td�Wd�dS1swYdS)Ns��assertRaisesr
r	��self�r�A/usr/local/CyberCP/lib/python3.10/site-packages/ecdsa/test_der.py�test_non_minimal_encoding#�
"�z+TestRemoveInteger.test_non_minimal_encodingcCr)Ns�rrrrr�test_negative_with_high_bit_set'rz1TestRemoveInteger.test_negative_with_high_bit_setcC�(td�\}}|�|d�|�|d�dS�Ns����r	�assertEqual�r�val�remrrr�test_minimal_with_high_bit_set+�z0TestRemoveInteger.test_minimal_with_high_bit_setcCr)Ns�rrrrr�%test_two_zero_bytes_with_high_bit_set1rz7TestRemoveInteger.test_two_zero_bytes_with_high_bit_setcCr)Nsrrrrr�test_zero_length_integer5rz*TestRemoveInteger.test_zero_length_integercCr�Nr#rrrrr�test_empty_string9rz#TestRemoveInteger.test_empty_stringcCr )Nsrr#r$r&rrr�test_encoding_of_zero=r*z'TestRemoveInteger.test_encoding_of_zerocCr )Ns�r#r$r&rrr�test_encoding_of_127Cr*z&TestRemoveInteger.test_encoding_of_127cCr r!r$r&rrr�test_encoding_of_128Ir*z&TestRemoveInteger.test_encoding_of_128cC�H|�t��}td�Wd�n1swY|�dt|j��dS)Ns�zwanted type 'integer'�rr
r	�assertIn�str�	exception�r�errr�test_wrong_tagO�
�z TestRemoveInteger.test_wrong_tagcCr3)Ns��
Length longerr4r8rrr�test_wrong_lengthUr;z#TestRemoveInteger.test_wrong_lengthN)�__name__�
__module__�__qualname__rrr)r+r,r.r/r1r2r:r=rrrrr src@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�TestReadLengthcC�|�dtd��dS)N)rr��r%rrrrr�test_zero_length`�zTestReadLength.test_zero_lengthcCr)Ns��rr
rrrrr�test_two_byte_zero_lengthcrz(TestReadLength.test_two_byte_zero_lengthcCr)Ns�rGrrrr�test_two_byte_small_lengthgrz)TestReadLength.test_two_byte_small_lengthcCr)N��rGrrrr�test_long_form_with_zero_lengthkrz.TestReadLength.test_long_form_with_zero_lengthcCrB)N)r"�s��rDrrrr�test_smallest_two_byte_lengthorFz,TestReadLength.test_smallest_two_byte_lengthcCr)Ns��rGrrrr�test_zero_padded_lengthrrz&TestReadLength.test_zero_padded_lengthcCrB)N)��s�rDrrrr�test_two_three_byte_lengthvrFz)TestReadLength.test_two_three_byte_lengthcCrr-rGrrrrr.yrz TestReadLength.test_empty_stringcCr)Ns�rGrrrr�test_length_overflow}rz#TestReadLength.test_length_overflowN)r>r?r@rErHrIrKrMrNrQr.rRrrrrrA\srAc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�TestEncodeBitstringcCstt�d�t�t��}td�}Wd�n1swY|�t|�d�|�d|dj	j
d�|�|d�dS)z(This is the old way to use the function.�always��Nrzunused= needs to be specifiedr��)�warnings�simplefilter�pytest�warns�DeprecationWarningrr%�lenr5�message�args)rrZ�derrrr�test_old_call_convention�s

��z,TestEncodeBitstring.test_old_call_conventioncCsLt���t�d�tdd�}Wd�n1swY|�|d�dS)z$This is how it should be called now.�error��rNrV�rW�catch_warningsrXrr%�rr_rrr�test_new_call_convention�s


�z,TestEncodeBitstring.test_new_call_conventioncCsLt���t�d�tdd�}Wd�n1swY|�|d�dS)zU
        Writing bit string with already included the number of unused bits.
        rarUNrVrcrerrr�test_implicit_unused_bits�s


�z-TestEncodeBitstring.test_implicit_unused_bitscC�tdd�}|�|d�dS)Ns���s��)rr%rerrr�test_explicit_unused_bits�s
z-TestEncodeBitstring.test_explicit_unused_bitscCs|�tdd�d�dS)Nr#rs)r%rrrrrr.��z%TestEncodeBitstring.test_empty_stringcC�:|�t��tdd�Wd�dS1swYdS)Ns���r�
ValueErrorrrrrr�test_invalid_unused_count��"�z-TestEncodeBitstring.test_invalid_unused_countcCrl)Nr#rrnrrrr�%test_invalid_unused_with_empty_string�rqz9TestEncodeBitstring.test_invalid_unused_with_empty_stringcCrl)NrbrLrnrrrr�test_non_zero_padding_bits�rqz.TestEncodeBitstring.test_non_zero_padding_bitsN)r>r?r@r`rfrgrjr.rprrrsrrrrrS�s
	rSc@sleZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�TestRemoveBitstringcCs�t�d�t�t��}td�\}}Wd�n1swY|�t|�d�|�d|dj	j
d�|�|d�|�|d�dS)	z)This is the old way to call the function.rTrVNrz$expect_unused= needs to be specifiedrrUr#)rWrXrYrZr[r
r%r\r5r]r^)rrZ�bits�restrrrr`�s
��z,TestRemoveBitstring.test_old_call_conventioncCs\t���t�d�tdd�\}}Wd�n1swY|�|d�|�|d�dS)NrarVrrbr#�rWrdrXr
r%�rrurvrrrrf��

�z,TestRemoveBitstring.test_new_call_conventioncCs\t���t�d�tdd�\}}Wd�n1swY|�|d�|�|d�dS)NrarV)rbrr#rwrxrrr�test_implicit_unexpected_unused�ryz3TestRemoveBitstring.test_implicit_unexpected_unusedcCs*tdd�\}}|�|d�|�|d�dS)Ns�)��rir#)r
r%)r�retrvrrr�test_with_padding�sz%TestRemoveBitstring.test_with_paddingcC�:|�t��tdd�Wd�dS1swYdS)Ns��rr
r
rrrr�test_not_a_bitstring�rqz(TestRemoveBitstring.test_not_a_bitstringcCr~)Nsrrrrr�test_empty_encoding�rqz'TestRemoveBitstring.test_empty_encodingcCr~r-rrrrrr.�rqz%TestRemoveBitstring.test_empty_stringcCr~)N�rrrrr�test_no_length�rqz"TestRemoveBitstring.test_no_lengthcCrl)NrVrrrrrr�%test_unexpected_number_of_unused_bits�rqz9TestRemoveBitstring.test_unexpected_number_of_unused_bitscCr~)Ns�rrrrr�$test_invalid_encoding_of_unused_bits�rqz8TestRemoveBitstring.test_invalid_encoding_of_unused_bitscCr~)Nsrrrrr�%test_invalid_encoding_of_empty_string�rqz9TestRemoveBitstring.test_invalid_encoding_of_empty_stringcCr~)Ns�rrrrr�test_invalid_padding_bits�rqz-TestRemoveBitstring.test_invalid_padding_bitsN)r>r?r@r`rfrzr}r�r�r.r�r�r�r�r�rrrrrt�s		rtc@s$eZdZdd�Zdd�Zdd�ZdS)�TestStrIdxAsIntcC�|�dtdd��dS)N�sr6r�r%rrrrr�test_strrkzTestStrIdxAsInt.test_strcCr��Nr�sstrrr�rrrr�
test_bytesrkzTestStrIdxAsInt.test_bytescCs|�dttd�d��dSr�)r%r�	bytearrayrrrr�test_bytearrayszTestStrIdxAsInt.test_bytearrayN)r>r?r@r�r�r�rrrrr�sr�c@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�
TestEncodeOidcCs&tdddddd�}|�t|�d�dS)NrrL�H�='s06072a8648ce3d0201)rr%r)r�oid_ecPublicKeyrrr�test_pub_key_oidszTestEncodeOid.test_pub_key_oidcC�|�ttj�d�dS)Ns06052b81040021)r%rr�encoded_oidrrrr�test_nist224p_oidrkzTestEncodeOid.test_nist224p_oidcCr�)Ns06082a8648ce3d030107)r%rrr�rrrr�test_nist256p_oids
�zTestEncodeOid.test_nist256p_oidcCstddd�}|�|d�dS)NrL��rP��7�rr%�r�oidrrr�test_large_second_subidsz%TestEncodeOid.test_large_second_subidcCrh)NrLr���7r�r�rrr�test_with_two_subids!�
z"TestEncodeOid.test_with_two_subidscCstdd�}|�|d�dS)Nr�r�r�rrr�test_zero_zero%r�zTestEncodeOid.test_zero_zerocCs>|�ttf��tdd�Wd�dS1swYdS)Nr)r�	TypeError�AssertionErrorrrrrr�test_with_wrong_types)s"�z#TestEncodeOid.test_with_wrong_typescCrl)Nr�(�rr�rrrrr�"test_with_small_first_large_second-rqz0TestEncodeOid.test_with_small_first_large_secondcCrh)Nr�'sOr�r�rrr�test_small_first_max_second1r�z)TestEncodeOid.test_small_first_max_secondcCrl)NrPr�r�rrrr�test_with_invalid_first5rqz%TestEncodeOid.test_with_invalid_firstN)
r>r?r@r�r�r�r�r�r�r�r�r�r�rrrrr�sr�c@s�eZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS) �TestRemoveObjectcCstdddddd�|_dS)NrrLr�r�)rr���clsrrr�
setUpClass;szTestRemoveObject.setUpClasscCs*t|j�\}}|�|d�|�|d�dS)Nr#�rrLr�r�rLr�rr�r%�rr�rvrrrr�?sz!TestRemoveObject.test_pub_key_oidcCs.t|jd�\}}|�|d�|�|d�dS)Nsmorer�r�r�rrr�test_with_extra_bytesDsz&TestRemoveObject.test_with_extra_bytescC�(td�\}}|�|d�|�|d�dS)Nr�r#)rLr�rP�rr%r�rrr�test_with_large_second_subidIsz-TestRemoveObject.test_with_large_second_subidcCr)Ns��rr
rrrrr�test_with_padded_first_subidOrz-TestRemoveObject.test_with_padded_first_subidcCr)Ns�7�r�rrrr�test_with_padded_second_subidSrz.TestRemoveObject.test_with_padded_second_subidcCr)Ns�7�r�rrrr�)test_with_missing_last_byte_of_multi_byteWrz:TestRemoveObject.test_with_missing_last_byte_of_multi_bytecCr�)Nr�r#)rLr�r�r�rrrr�[�z%TestRemoveObject.test_with_two_subidscCr�)Nr�r#)rrr�r�rrrr�`r�zTestRemoveObject.test_zero_zerocCrr-r�rrrrr.erz"TestRemoveObject.test_empty_stringcCr)N�r�rrrr�test_missing_lengthirz$TestRemoveObject.test_missing_lengthcCr)Nsr�rrrr�test_empty_oidmrzTestRemoveObject.test_empty_oidcCr)Nsr�rrrr�test_empty_oid_overflowqrz(TestRemoveObject.test_empty_oid_overflowcCr)Ns�7r�rrrr�test_with_wrong_typeurz%TestRemoveObject.test_with_wrong_typecCr)Ns�7r�rrrr�test_with_too_long_lengthyrz*TestRemoveObject.test_with_too_long_lengthN)r>r?r@�classmethodr�r�r�r�r�r�r�r�r�r.r�r�r�r�r�rrrrr�:s"
r�c@�eZdZdd�Zdd�ZdS)�TestRemoveConstructedcCs:d}t|�\}}}|�|d�|�|d�|�|d�dS)Ns���r���r#)rr%�r�data�tag�bodyrvrrr�test_simples
z!TestRemoveConstructed.test_simplecC�Ld}|�t��}t|�Wd�n1swY|�dt|j��dS)Ns��zconstructed tag)rr
rr5r6r7�rr�r9rrr�test_with_malformed_tag��

�z-TestRemoveConstructed.test_with_malformed_tagN�r>r?r@r�r�rrrrr�~s	r�c@sXeZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�ZdS)�TestRemoveImplicitcCs"d|_d|_d|_d|_d|_dS)N��
�F
��
��
)�exp_tag�exp_data�data_application�data_context_specific�data_privater�rrrr��s

zTestRemoveImplicit.setUpClasscCs<t|j�\}}}|�||j�|�||j�|�|d�dSr-�rr�r%r�r��rr�r�rvrrrr��szTestRemoveImplicit.test_simplecCsL|�t��}t|jd�Wd�n1swY|�dt|j��dS)N�foobarzinvalid `exp_class` value)rrorr�r5r6r7r8rrr�test_wrong_expected_class���z,TestRemoveImplicit.test_wrong_expected_classcCsJ|�t��
}t|j�Wd�n1swY|�dt|j��dS)Nz+wanted class context-specific, got 0x46 tag)rr
rr�r5r6r7r8rrr�test_with_wrong_class�s�
�z(TestRemoveImplicit.test_with_wrong_classcC�>t|jd�\}}}|�||j�|�||j�|�|d�dS)N�applicationr#)rr�r%r�r�r�rrr�test_with_application_class��z.TestRemoveImplicit.test_with_application_classcCr�)N�privater#)rr�r%r�r�r�rrr�test_with_private_class�r�z*TestRemoveImplicit.test_with_private_classcCsDd}t|j|�\}}}|�||j�|�||j�|�||�dS)Nsr�)r�
extra_datar�r�rvrrr�test_with_data_following�s
�z+TestRemoveImplicit.test_with_data_followingcCr�)Ns�
z#wanted type primitive, got 0xa6 tag)rr
rr5r6r7r�rrr�test_with_constructed�r�z(TestRemoveImplicit.test_with_constructedcCsDd}ttd|d�d�\}}}|�|d�|�||�|�|d�dS)Nssome longish stringr�r�r#)rrr%r�rrr�test_encode_decode�s
�z%TestRemoveImplicit.test_encode_decodeN)
r>r?r@r�r�r�r�r�r�r�r�r�r�rrrrr��s

r�c@sHeZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dS)�TestEncodeImplicitcCsd|_d|_d|_d|_dS)Nr�r�r�r�)r�r�r�r�r�rrrr��s
zTestEncodeImplicit.setUpClasscCstd|j�}|�||j�dS)Nr��rr�r%r��rr|rrr�test_encode_with_default_class�sz1TestEncodeImplicit.test_encode_with_default_classcC� td|jd�}|�||j�dS)Nr�r�)rr�r%r�r�rrr�"test_encode_with_application_class��z5TestEncodeImplicit.test_encode_with_application_classcCr�)Nr�zcontext-specificr�r�rrr�'test_encode_with_context_specific_class�r�z:TestEncodeImplicit.test_encode_with_context_specific_classcCr�)Nr�r�)rr�r%r�r�rrr�test_encode_with_private_class�r�z1TestEncodeImplicit.test_encode_with_private_classcCsN|�t��}td|jd�Wd�n1swY|�dt|j��dS)Nr�r�zinvalid tag class�rrorr�r5r6r7r8rrr�test_encode_with_invalid_class�s�z1TestEncodeImplicit.test_encode_with_invalid_classcCsL|�t��}td|j�Wd�n1swY|�dt|j��dS)N� zLong tags not supportedr�r8rrr�test_encode_with_too_large_tagr�z1TestEncodeImplicit.test_encode_with_too_large_tagN)r>r?r@r�r�r�r�r�r�r�r�rrrrr��s
	r�c@r�)�TestRemoveOctetStringcC�,d}t|�\}}|�|d�|�|d�dS)Ns���s���r#)rr%�rr�r�rvrrrr��z!TestRemoveOctetString.test_simplecCr�)Ns����octetstring)rr
rr5r6r7r�rrrr�s

�z-TestRemoveOctetString.test_with_malformed_tagNr�rrrrr�sr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestRemoveSequencecCr�)Ns0��r�r#)rr%r�rrrr�r�zTestRemoveSequence.test_simplecCr3)Nr#zEmpty string�rr
rr5r6r7r8rrr�test_with_empty_string!r;z)TestRemoveSequence.test_with_empty_stringcCr�)Ns ��zwanted type 'sequence'rr�rrr�test_with_wrong_tag'r�z&TestRemoveSequence.test_with_wrong_tagcCr�)Ns0��r<rr�rrr�test_with_wrong_length/r�z)TestRemoveSequence.test_with_wrong_lengthN)r>r?r@r�rrrrrrrr�s
r�rLi�2cCsl|tjddd��}|dkr|tjddd��}n	|tjd|d��}|tjtjd|d�|d��}||ft|�S)z�
    Hypothesis strategy that returns valid OBJECT IDENTIFIERs as tuples

    :param max_value: maximum value of any single sub-identifier
    :param max_size: maximum length of the generated OID
    rrL)�	min_value�	max_valuer�)�max_size)�st�integers�lists�tuple)�drawrr�first�secondrvrrr�st_oid8s��rz--fast�max_examplescCs0t|�}t|�\}}|dksJ�||ksJ�dSr-)rr)�idsr��decoded_oidrvrrr�	test_oidsTsrr)2rW�binasciir�	unittest2�unittest�ImportError�sys�hypothesis.strategies�
strategiesr�
hypothesisrrrY�_compatr�curvesrrr_r	r
rrr
rrrrrrr�TestCaserrArSrtr�r�r�r�r�r�r�r��	compositer�HYP_SETTINGS�argvrrrrr�<module>sD�8<&:H+DN,