
    sIgU:                        d dl Z d dlmZ 	 d dlZd dlZd dlmZ	 d dl
mZmZ d dlZddlmZ ddlmZmZ ddlmZmZmZmZmZmZmZmZmZmZ  G d d	ej<                        Z G d
 dej<                        Z  G d dej<                        Z! G d dej<                        Z" G d dej<                        Z# G d dej<                        Z$ G d dej<                        Z% G d dej<                        Z& G d dej<                        Z' G d dej<                        Z(e	jR                  ddz  dfd       Z*i Z+d ejX                  v rde+d!<    ed#i e+ e e*             d"               Z-y# e$ r d dlZY fw xY w)$    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_octet_stringremove_sequencec                   N    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)TestRemoveIntegerc                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Ns    assertRaisesr   r
   selfs    K/var/www/html/answerous/venv/lib/python3.12/site-packages/ecdsa/test_der.pytest_non_minimal_encodingz+TestRemoveInteger.test_non_minimal_encoding!   s.    }- 	0./	0 	0 	0   +4c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Ns   r   r   s    r   test_negative_with_high_bit_setz1TestRemoveInteger.test_negative_with_high_bit_set%   s-    }- 	,?+	, 	, 	,r   c                 h    t        d      \  }}| j                  |d       | j                  |d       y Ns           r
   assertEqualr   valrems      r   test_minimal_with_high_bit_setz0TestRemoveInteger.test_minimal_with_high_bit_set)   s1    !"56Sd#c"r#   c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Ns     r   r   s    r   %test_two_zero_bytes_with_high_bit_setz7TestRemoveInteger.test_two_zero_bytes_with_high_bit_set/   s.    }- 	423	4 	4 	4r   c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Ns    r   r   s    r   test_zero_length_integerz*TestRemoveInteger.test_zero_length_integer3   s-    }- 	(;'	( 	( 	(r   c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY wNr#   r   r   s    r   test_empty_stringz#TestRemoveInteger.test_empty_string7   s-    }- 	 3	  	  	 r   c                 h    t        d      \  }}| j                  |d       | j                  |d       y )Ns    r   r#   r$   r&   s      r   test_encoding_of_zeroz'TestRemoveInteger.test_encoding_of_zero;   s0    !/2Sa c"r#   c                 h    t        d      \  }}| j                  |d       | j                  |d       y )Ns      r#   r$   r&   s      r   test_encoding_of_127z&TestRemoveInteger.test_encoding_of_127A   s0    !/2Sc"c"r#   c                 h    t        d      \  }}| j                  |d       | j                  |d       y r!   r$   r&   s      r   test_encoding_of_128z&TestRemoveInteger.test_encoding_of_128G   s1    !"56Sc"c"r#   c                     | j                  t              5 }t        d       d d d        | j                  dt	        j
                               y # 1 sw Y   /xY w)Ns    zwanted type 'integer'r   r   r
   assertInstr	exceptionr   es     r   test_wrong_tagz TestRemoveInteger.test_wrong_tagM   sJ    }- 	0./	0 	-s1;;/?@	0 	0   AAc                     | j                  t              5 }t        d       d d d        | j                  dt	        j
                               y # 1 sw Y   /xY w)Ns    Length longerr9   r=   s     r   test_wrong_lengthz#TestRemoveInteger.test_wrong_lengthS   sI    }- 	0./	0 	os1;;'78	0 	0r@   N)__name__
__module____qualname__r   r   r)   r+   r-   r0   r2   r5   r7   r?   rC    r#   r   r   r      s:    0,#4( ###A9r#   r   c                   B    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)TestReadLengthc                 :    | j                  dt        d             y )N)r   r       r%   r   r   s    r   test_zero_lengthzTestReadLength.test_zero_length^   s    W!56r#   c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Ns    r   r   r   r   s    r   test_two_byte_zero_lengthz(TestReadLength.test_two_byte_zero_lengtha   -    }- 	%$	% 	% 	%r   c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Ns   rO   r   s    r   test_two_byte_small_lengthz)TestReadLength.test_two_byte_small_lengthe   rQ   r   c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)N   rO   r   s    r   test_long_form_with_zero_lengthz.TestReadLength.test_long_form_with_zero_lengthi   s-    }- 	! 	! 	! 	!r   c                 :    | j                  dt        d             y )N)r"      s   rL   r   s    r   test_smallest_two_byte_lengthz,TestReadLength.test_smallest_two_byte_lengthm   s    ;{#;<r#   c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Ns    rO   r   s    r   test_zero_padded_lengthz&TestReadLength.test_zero_padded_lengthp   -    }- 	)(	) 	) 	)r   c                 :    | j                  dt        d             y )N)      s    rL   r   s    r   test_two_three_byte_lengthz)TestReadLength.test_two_three_byte_lengtht   s    ;#?@r#   c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY wr/   rO   r   s    r   r0   z TestReadLength.test_empty_stringw   s-    }- 		 	 	r   c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Ns    rO   r   s    r   test_length_overflowz#TestReadLength.test_length_overflow{   r\   r   N)rD   rE   rF   rM   rP   rS   rV   rY   r[   r`   r0   rc   rG   r#   r   rI   rI   Z   s0    7%%!=)A)r#   rI   c                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
TestEncodeBitstringc                 R   t        j                  d       t        j                  t              5 }t        d      }ddd       | j                  t              d       | j                  d|d   j                  j                  d          | j                  d       y# 1 sw Y   cxY w)z(This is the old way to use the function.always    Nr   zunused= needs to be specifiedr       )warningssimplefilterpytestwarnsDeprecationWarningr   r%   lenr:   messageargs)r   rm   ders      r   test_old_call_conventionz,TestEncodeBitstring.test_old_call_convention   s    h'\\,- 	0";/C	0 	UQ'+U1X-=-=-B-B1-E	
 	12	0 	0s   BB&c                     t        j                         5  t        j                  d       t        dd      }ddd       | j	                  d       y# 1 sw Y   xY w)z$This is how it should be called now.error   r   Nri   rj   catch_warningsrk   r   r%   r   rr   s     r   test_new_call_conventionz,TestEncodeBitstring.test_new_call_convention   sR     $$& 	/!!'*"7A.C	/ 	12		/ 	/   "AAc                     t        j                         5  t        j                  d       t        dd      }ddd       | j	                  d       y# 1 sw Y   xY w)zU
        Writing bit string with already included the number of unused bits.
        ru   rh   Nri   rw   ry   s     r   test_implicit_unused_bitsz-TestEncodeBitstring.test_implicit_unused_bits   sR    
 $$& 	6!!'*";5C	6 	12		6 	6r{   c                 @    t        dd      }| j                  |d       y )Ns      s   )r   r%   ry   s     r   test_explicit_unused_bitsz-TestEncodeBitstring.test_explicit_unused_bits   s    {A.56r#   c                 <    | j                  t        dd      d       y )Nr#   r   s    )r%   r   r   s    r   r0   z%TestEncodeBitstring.test_empty_string   s    )#q1?Cr#   c                 p    | j                  t              5  t        dd       d d d        y # 1 sw Y   y xY w)Ns       r   
ValueErrorr   r   s    r   test_invalid_unused_countz-TestEncodeBitstring.test_invalid_unused_count   s/    z* 	-[!,	- 	- 	-   ,5c                 p    | j                  t              5  t        dd       d d d        y # 1 sw Y   y xY w)Nr#   r   r   r   s    r   %test_invalid_unused_with_empty_stringz9TestEncodeBitstring.test_invalid_unused_with_empty_string   s/    z* 	%S!$	% 	% 	%r   c                 p    | j                  t              5  t        dd       d d d        y # 1 sw Y   y xY w)Nrv   rX   r   r   s    r   test_non_zero_padding_bitsz.TestEncodeBitstring.test_non_zero_padding_bits   s/    z* 	)Wa(	) 	) 	)r   N)rD   rE   rF   rs   rz   r}   r   r0   r   r   r   rG   r#   r   re   re      s+    33	37
D-%)r#   re   c                   T    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zy)TestRemoveBitstringc                 |   t        j                  d       t        j                  t              5 }t        d      \  }}ddd       | j                  t              d       | j                  d|d   j                  j                  d          | j                  d       | j                  d       y# 1 sw Y   uxY w)	z)This is the old way to call the function.rg   ri   Nr   z$expect_unused= needs to be specifiedr   rh   r#   )rj   rk   rl   rm   rn   r   r%   ro   r:   rp   rq   )r   rm   bitsrests       r   rs   z,TestRemoveBitstring.test_old_call_convention   s    h'\\,- 	?)*=>JD$	? 	UQ'2E!H4D4D4I4I!4L	
 	{+s#	? 	?s   B22B;c                     t        j                         5  t        j                  d       t        dd      \  }}d d d        | j	                  d       | j	                  d       y # 1 sw Y   .xY w)Nru   ri   r   rv   r#   rj   rx   rk   r   r%   r   r   r   s      r   rz   z,TestRemoveBitstring.test_new_call_convention   sh    $$& 	B!!'*)*=qAJD$	B 	w's#	B 	B   %A''A0c                     t        j                         5  t        j                  d       t        dd       \  }}d d d        | j	                  d       | j	                  d       y # 1 sw Y   .xY w)Nru   ri   )rv   r   r#   r   r   s      r   test_implicit_unexpected_unusedz3TestRemoveBitstring.test_implicit_unexpected_unused   sh    $$& 	E!!'*)*=tDJD$	E 	|,s#	E 	Er   c                 j    t        dd       \  }}| j                  |d       | j                  |d       y )Ns   )   r   r#   )r   r%   )r   retr   s      r   test_with_paddingz%TestRemoveBitstring.test_with_padding   s3    $%8$?	Tl+s#r#   c                 p    | j                  t              5  t        dd        d d d        y # 1 sw Y   y xY w)Ns    r   r   r   r   s    r   test_not_a_bitstringz(TestRemoveBitstring.test_not_a_bitstring   0    }- 	80$7	8 	8 	8r   c                 p    | j                  t              5  t        dd        d d d        y # 1 sw Y   y xY w)Ns    r   r   s    r   test_empty_encodingz'TestRemoveBitstring.test_empty_encoding   s/    }- 	0[$/	0 	0 	0r   c                 p    | j                  t              5  t        dd        d d d        y # 1 sw Y   y xY wr/   r   r   s    r   r0   z%TestRemoveBitstring.test_empty_string   s/    }- 	(S$'	( 	( 	(r   c                 p    | j                  t              5  t        dd        d d d        y # 1 sw Y   y xY w)N   r   r   s    r   test_no_lengthz"TestRemoveBitstring.test_no_length   s/    }- 	,Wd+	, 	, 	,r   c                 p    | j                  t              5  t        dd       d d d        y # 1 sw Y   y xY w)Nri   r   r   r   s    r   %test_unexpected_number_of_unused_bitsz9TestRemoveBitstring.test_unexpected_number_of_unused_bits   s0    }- 	50!4	5 	5 	5r   c                 p    | j                  t              5  t        dd        d d d        y # 1 sw Y   y xY w)Ns    r   r   s    r   $test_invalid_encoding_of_unused_bitsz8TestRemoveBitstring.test_invalid_encoding_of_unused_bits   s0    }- 	<4d;	< 	< 	<r   c                 p    | j                  t              5  t        dd        d d d        y # 1 sw Y   y xY w)Ns   r   r   s    r   %test_invalid_encoding_of_empty_stringz9TestRemoveBitstring.test_invalid_encoding_of_empty_string   s/    }- 	4_d3	4 	4 	4r   c                 p    | j                  t              5  t        dd        d d d        y # 1 sw Y   y xY w)Ns   r   r   s    r   test_invalid_padding_bitsz-TestRemoveBitstring.test_invalid_padding_bits   r   r   N)rD   rE   rF   rs   rz   r   r   r   r   r0   r   r   r   r   r   rG   r#   r   r   r      s>    $$$$80(,5<48r#   r   c                       e Zd Zd Zd Zd Zy)TestStrIdxAsIntc                 <    | j                  dt        dd             y )Ns   r;   r   r%   r   r   s    r   test_strzTestStrIdxAsInt.test_str  s    nUA67r#   c                 <    | j                  dt        dd             y Nr   s   strr   r   r   s    r   
test_byteszTestStrIdxAsInt.test_bytes  s    nVQ78r#   c                 N    | j                  dt        t        d      d             y r   )r%   r   	bytearrayr   s    r   test_bytearrayzTestStrIdxAsInt.test_bytearray	  s    nYv->BCr#   N)rD   rE   rF   r   r   r   rG   r#   r   r   r     s    89Dr#   r   c                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)TestEncodeOidc                 Z    t        dddddd      }| j                  t        |      d       y )Nr   rX   H  ='  s   06072a8648ce3d0201)r   r%   r   )r   oid_ecPublicKeys     r   test_pub_key_oidzTestEncodeOid.test_pub_key_oid  s,    $Q3q!<13HIr#   c                 V    | j                  t        t        j                        d       y )Ns   06052b81040021)r%   r   r	   encoded_oidr   s    r   test_nist224p_oidzTestEncodeOid.test_nist224p_oid  s    !5!568IJr#   c                 V    | j                  t        t        j                        d       y )Ns   06082a8648ce3d030107)r%   r   r   r   r   s    r   test_nist256p_oidzTestEncodeOid.test_nist256p_oid  s!    H(()+B	
r#   c                 B    t        ddd      }| j                  |d       y )NrX     r_      7r   r%   r   oids     r   test_large_second_subidz%TestEncodeOid.test_large_second_subid  s!    C#56r#   c                 @    t        dd      }| j                  |d       y )NrX   r      7r   r   s     r   test_with_two_subidsz"TestEncodeOid.test_with_two_subids  s    C 12r#   c                 @    t        dd      }| j                  |d       y )Nr       r   r   s     r   test_zero_zerozTestEncodeOid.test_zero_zero#  s    Ao.r#   c                 |    | j                  t        t        f      5  t        dd        d d d        y # 1 sw Y   y xY w)Nr   )r   	TypeErrorAssertionErrorr   r   s    r   test_with_wrong_typesz#TestEncodeOid.test_with_wrong_types'  s4    	>:; 	 q$	  	  	 s   2;c                 p    | j                  t              5  t        dd       d d d        y # 1 sw Y   y xY w)Nr   (   r   r   r   r   s    r   "test_with_small_first_large_secondz0TestEncodeOid.test_with_small_first_large_second+  /    ~. 	q"	 	 	r   c                 @    t        dd      }| j                  |d       y )Nr   '   s   Or   r   s     r   test_small_first_max_secondz)TestEncodeOid.test_small_first_max_second/  s    Bo.r#   c                 p    | j                  t              5  t        dd       d d d        y # 1 sw Y   y xY w)Nr_   r   r   r   s    r   test_with_invalid_firstz%TestEncodeOid.test_with_invalid_first3  r   r   N)rD   rE   rF   r   r   r   r   r   r   r   r   r   r   rG   r#   r   r   r     s6    JK

7
3/ /r#   r   c                   p    e Zd Zed        Zd Zd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zy)TestRemoveObjectc                 .    t        dddddd      | _        y )Nr   rX   r   r   )r   r   )clss    r   
setUpClasszTestRemoveObject.setUpClass9  s    (AsE1a@r#   c                 |    t        | j                        \  }}| j                  |d       | j                  |d       y )Nr#   r   rX   r   r   rX   r   r   r   r%   r   r   r   s      r   r   z!TestRemoveObject.test_pub_key_oid=  s7    !$"6"67	Ts#67r#   c                     t        | j                  dz         \  }}| j                  |d       | j                  |d       y )Ns   morer   r   r   s      r   test_with_extra_bytesz&TestRemoveObject.test_with_extra_bytesB  s<    !$"6"6"@A	Tw'67r#   c                 h    t        d      \  }}| j                  |d       | j                  |d       y )Nr   r#   )rX   r   r_   r   r%   r   s      r   test_with_large_second_subidz-TestRemoveObject.test_with_large_second_subidG  s1    !"9:	Ts#k*r#   c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Ns    r   r   r   r   s    r   test_with_padded_first_subidz-TestRemoveObject.test_with_padded_first_subidM  .    }- 	/-.	/ 	/ 	/r   c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Ns   7r   r   s    r   test_with_padded_second_subidz.TestRemoveObject.test_with_padded_second_subidQ  s.    }- 	756	7 	7 	7r   c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Ns   7r   r   s    r   )test_with_missing_last_byte_of_multi_bytez:TestRemoveObject.test_with_missing_last_byte_of_multi_byteU  s.    }- 	312	3 	3 	3r   c                 h    t        d      \  }}| j                  |d       | j                  |d       y )Nr   r#   )rX   r   r   r   s      r   r   z%TestRemoveObject.test_with_two_subidsY  s1    !"56	Ts#h'r#   c                 h    t        d      \  }}| j                  |d       | j                  |d       y )Nr   r#   )r   r   r   r   s      r   r   zTestRemoveObject.test_zero_zero^  s0    !/2	Ts#f%r#   c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY wr/   r   r   s    r   r0   z"TestRemoveObject.test_empty_stringc  s-    }- 	#	 	 	r   c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)N   r   r   s    r   test_missing_lengthz$TestRemoveObject.test_missing_lengthg  s-    }- 	#'"	# 	# 	#r   c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Ns    r   r   s    r   test_empty_oidzTestRemoveObject.test_empty_oidk  -    }- 	'+&	' 	' 	'r   c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Ns   r   r   s    r   test_empty_oid_overflowz(TestRemoveObject.test_empty_oid_overflowo  r   r   c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Ns   7r   r   s    r   test_with_wrong_typez%TestRemoveObject.test_with_wrong_types  r   r   c                 n    | j                  t              5  t        d       d d d        y # 1 sw Y   y xY w)Ns   7r   r   s    r   test_with_too_long_lengthz*TestRemoveObject.test_with_too_long_lengthw  r   r   N)rD   rE   rF   classmethodr   r   r   r   r   r   r   r   r   r0   r   r   r   r  r  rG   r#   r   r   r   8  s\    A A8
8
+/73(
&
#''//r#   r   c                       e Zd Zd Zd Zy)TestRemoveConstructedc                     d}t        |      \  }}}| j                  |d       | j                  |d       | j                  |d       y )Ns   r      r#   )r   r%   )r   datatagbodyr   s        r   test_simplez!TestRemoveConstructed.test_simple}  sG    ",T2T4d#{+s#r#   c                     d}| j                  t              5 }t        |       d d d        | j                  dt	        j
                               y # 1 sw Y   /xY w)Ns   zconstructed tag)r   r   r   r:   r;   r<   r   r
  r>   s      r   test_with_malformed_tagz-TestRemoveConstructed.test_with_malformed_tag  sN    "}- 	%t$	% 	'Q[[)9:	% 	%   AANrD   rE   rF   r  r  rG   r#   r   r  r  |  s    $;r#   r  c                       e Zd Zd Zd Zy)TestRemoveOctetStringc                 l    d}t        |      \  }}| j                  |d       | j                  |d       y )Ns   s   r#   )r   r%   r   r
  r  r   s       r   r  z!TestRemoveOctetString.test_simple  s5    &(.
d/s#r#   c                     d}| j                  t              5 }t        |       d d d        | j                  dt	        j
                               y # 1 sw Y   /xY w)Ns   octetstring)r   r   r   r:   r;   r<   r  s      r   r  z-TestRemoveOctetString.test_with_malformed_tag  sM    &}- 	&%	& 	mS%56	& 	&r  Nr  rG   r#   r   r  r    s    $7r#   r  c                   $    e Zd Zd Zd Zd Zd Zy)TestRemoveSequencec                 l    d}t        |      \  }}| j                  |d       | j                  |d       y )Ns   0r	  r#   )r   r%   r  s       r   r  zTestRemoveSequence.test_simple  s5    "$T*
d{+s#r#   c                     | j                  t              5 }t        d       d d d        | j                  dt	        j
                               y # 1 sw Y   /xY w)Nr#   zEmpty stringr   r   r   r:   r;   r<   r=   s     r   test_with_empty_stringz)TestRemoveSequence.test_with_empty_string  sH    }- 	!C 	! 	nc!++&67	! 	!r@   c                     d}| j                  t              5 }t        |       d d d        | j                  dt	        j
                               y # 1 sw Y   /xY w)Ns    zwanted type 'sequence'r  r  s      r   test_with_wrong_tagz&TestRemoveSequence.test_with_wrong_tag  sN    "}- 	"D!	" 	.AKK0@A	" 	"r  c                     d}| j                  t              5 }t        |       d d d        | j                  dt	        j
                               y # 1 sw Y   /xY w)Ns   0rB   r  r  s      r   test_with_wrong_lengthz)TestRemoveSequence.test_with_wrong_length  sM    "}- 	"D!	" 	os1;;'78	" 	"r  N)rD   rE   rF   r  r  r   r"  rG   r#   r   r  r    s    $8B9r#   r  rX   i   2   c                 @    | t        j                  dd            }|dk  r | t        j                  dd            }n | t        j                  d|            } | t        j                  t        j                  d|      |            }||ft        |      z   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
    r   rX   )	min_value	max_valuer   )max_size)stintegersliststuple)drawr&  r'  firstsecondr   s         r   st_oidr/    s     qA67EqybkkA<=bkkACD
KK!y9H	
D
 6?U4[((r#   z--fastmax_examplesc                 L    t        |  }t        |      \  }}|dk(  sJ || k(  sJ y r/   )r   r   )idsr   decoded_oidr   s       r   	test_oidsr4    s7     c"K%k2K3;;#r#   rG   ).rj   binasciir   	unittest2unittestImportErrorsyshypothesis.strategies
strategiesr(  
hypothesisr   r   rl   _compatr   curvesr   r	   rr   r
   r   r   r   r   r   r   r   r   r   TestCaser   rI   re   r   r   r   r   r  r  r  	compositer/  HYP_SETTINGSargvr4  rG   r#   r   <module>rC     sw       " &  # &  99)) 99x#)X&& #)L7)(++ 7)tE8(++ E8PDh'' D(H%% (VA/x(( A/H;H-- ;&7H-- 79** 9< c6B ) )(  sxx#$L  
Lvx  e  s   E* *	E76E7