
    Tf3                     X   	 d dl Zn# e$ r d dlZY nw xY wd dlZd dlZddlmZmZmZmZm	Z	m
Z
 ddlmZmZmZ ddlmZ ddlmZ  G d dej                  Z G d	 d
ej                  Zej                            ded eD                       d             Zej                            ded eD                       d             Zej                            ded eD                       d             Zej                            ded eD                       d             ZdS )    N   )CurveNIST256pcurvesUnknownCurveErrorPRIME_FIELD_OIDcurve_by_name)CurveFpPointJacobi	CurveEdTw)der)number_to_stringc                       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d Zd Zd Zd Zd Zd Zd Zd Zd ZdS )TestParameterEncodingc                     d| _         d S )Na0  MIHgAgEBMCwGByqGSM49AQECIQD/////AAAAAQAAAAAAAAAAAAAAAP///////////////zBEBCD/////AAAAAQAAAAAAAAAAAAAAAP///////////////AQgWsY12Ko6k+ez671VdpiGvGUdBrDMU7D2O848PifSYEsEQQRrF9Hy4SxCR/i85uVjpEDydwN9gS3rM6D0oTlF2JjClk/jQuL+Gn+bjufrSnwPnhYrzjNXazFezsu2QGg3v1H1AiEA/////wAAAAD//////////7zm+q2nF56E87nKwvxjJVECAQE=)base64_params)clss    C/var/www/html/env/lib/python3.11/site-packages/ecdsa/test_curves.py
setUpClassz TestParameterEncoding.setUpClass   s    
C 	    c                 h    d}t          j        |          }|                     |t                     d S )No  -----BEGIN EC PARAMETERS-----
MIHgAgEBMCwGByqGSM49AQECIQD/////AAAAAQAAAAAAAAAAAAAAAP/////////
//////zBEBCD/////AAAAAQAAAAAAAAAAAAAAAP///////////////AQgWsY12K
o6k+ez671VdpiGvGUdBrDMU7D2O848PifSYEsEQQRrF9Hy4SxCR/i85uVjpEDyd
wN9gS3rM6D0oTlF2JjClk/jQuL+Gn+bjufrSnwPnhYrzjNXazFezsu2QGg3v1H1
AiEA/////wAAAAD//////////7zm+q2nF56E87nKwvxjJVECAQE=
-----END EC PARAMETERS-----
)r   from_pemassertIsr   )self
pem_paramscurves      r   test_from_pemz#TestParameterEncoding.test_from_pem"   s7    , 	 z**eX&&&&&r   c                     d}|                      t          j                  5 }t          j        |dg           d d d            n# 1 swxY w Y   |                     dt          |j                             d S )Nr   named_curvezexplicit curve parameters notassertRaisesr   UnexpectedDERr   r   assertInstr	exceptionr   r   es      r   2test_from_pem_with_explicit_when_explicit_disabledzHTestParameterEncoding.test_from_pem_with_explicit_when_explicit_disabled0   s    , 	 s011 	8QN:777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	5s1;7G7GHHHHH   AA	A	c                     d}|                      t          j                  5 }t          j        |dg           d d d            n# 1 swxY w Y   |                     dt          |j                             d S )NzK-----BEGIN EC PARAMETERS-----
BggqhkjOPQMBBw==
-----END EC PARAMETERS-----
explicitz named_curve curve parameters notr!   r'   s      r   8test_from_pem_with_named_curve_with_named_curve_disabledzNTestParameterEncoding.test_from_pem_with_named_curve_with_named_curve_disabled?   s    , 	
 s011 	5QN:
|444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	8#ak:J:JKKKKKr*   c                     d}|                      t          j                  5 }t          j        |           d d d            n# 1 swxY w Y   |                     dt          |j                             d S )Nai  -----BEGIN PARAMETERS-----
MIHgAgEBMCwGByqGSM49AQECIQD/////AAAAAQAAAAAAAAAAAAAAAP/////////
//////zBEBCD/////AAAAAQAAAAAAAAAAAAAAAP///////////////AQgWsY12K
o6k+ez671VdpiGvGUdBrDMU7D2O848PifSYEsEQQRrF9Hy4SxCR/i85uVjpEDyd
wN9gS3rM6D0oTlF2JjClk/jQuL+Gn+bjufrSnwPnhYrzjNXazFezsu2QGg3v1H1
AiEA/////wAAAAD//////////7zm+q2nF56E87nKwvxjJVECAQE=
-----END PARAMETERS-----
zPARAMETERS PEM headerr!   r'   s      r   test_from_pem_with_wrong_headerz5TestParameterEncoding.test_from_pem_with_wrong_headerJ   s    ) 	 s011 	'QN:&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	-s1;/?/?@@@@@s   AA
Ac                 \    d}t          j                    }|                     ||           d S )NsK   -----BEGIN EC PARAMETERS-----
BggqhkjOPQMBBw==
-----END EC PARAMETERS-----
)r   to_pemassertEqual)r   r   encodings      r   test_to_pemz!TestParameterEncoding.test_to_pemY   s7    - 	
 ?$$X.....r   c                 <    |                      t          d           d S )N   )assertNotEqualr   )r   s    r   "test_compare_with_different_objectz8TestParameterEncoding.test_compare_with_different_objectc   s    Hc*****r   c                 X    t          j                    }|                     d|           d S )Ns
   *H=r   to_derr2   r   encodeds     r   test_named_curve_params_derz1TestParameterEncoding.test_named_curve_params_derf   s.    /## 	DgNNNNNr   c                     t          j                    }t          j        d          }|                     ||           d S Nr    r:   )r   encoded_defaultencoded_nameds      r   +test_verify_that_default_is_named_curve_derzATestParameterEncoding.test_verify_that_default_is_named_curve_derl   s:    "/++ 66-88888r   c                     t          j        d          }|                     |t          t	          j        | j                                       d S Nr,   )r   r;   r2   bytesbase64	b64decoder   r<   s     r    test_encoding_to_explicit_paramsz6TestParameterEncoding.test_encoding_to_explicit_paramsr   sC    /*--%(89K(L(L"M"MNNNNNr   c                     |                      t                    5 }t          j        d           d d d            n# 1 swxY w Y   |                     dt          |j                             d S )NunsupportedzOnly 'named_curve')r"   
ValueErrorr   r;   r$   r%   r&   r   r(   s     r   !test_encoding_to_unsupported_typez7TestParameterEncoding.test_encoding_to_unsupported_typew   s    z** 	+aOM***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	*C,<,<=====s   <A A c                     t          j        dd          }d}|                     |t          t	          j        |                               d S )Nr,   
compresseda  MIHAAgEBMCwGByqGSM49AQECIQD/////AAAAAQAAAAAAAAAAAAAAAP///////////////zBEBCD/////AAAAAQAAAAAAAAAAAAAAAP///////////////AQgWsY12Ko6k+ez671VdpiGvGUdBrDMU7D2O848PifSYEsEIQNrF9Hy4SxCR/i85uVjpEDydwN9gS3rM6D0oTlF2JjClgIhAP////8AAAAA//////////+85vqtpxeehPO5ysL8YyVRAgEB)r   r;   r2   rF   rG   rH   )r   r=   compressed_base_points      r   +test_encoding_to_explicit_compressed_paramszATestParameterEncoding.test_encoding_to_explicit_compressed_params}   sZ    /*l;; 	 	U6+,ABBCC	
 	
 	
 	
 	
r   c                     d}t          j        t          t          j        |                              }|                     t          |           d S )NaP  MIH3AgEBMCwGByqGSM49AQECIQD/////AAAAAQAAAAAAAAAAAAAAAP///////////////zBbBCD/////AAAAAQAAAAAAAAAAAAAAAP///////////////AQgWsY12Ko6k+ez671VdpiGvGUdBrDMU7D2O848PifSYEsDFQDEnTYIhucEk2pmeOETnSa3gZ9+kARBBGsX0fLhLEJH+Lzm5WOkQPJ3A32BLeszoPShOUXYmMKWT+NC4v4af5uO5+tKfA+eFivOM1drMV7Oy7ZAaDe/UfUCIQD/////AAAAAP//////////vOb6racXnoTzucrC/GMlUQIBAQ==)r   from_derrF   rG   rH   r2   r   )r   p256_explicitdecodeds      r   #test_decoding_explicit_from_opensslz9TestParameterEncoding.test_decoding_explicit_from_openssl   sL     	 .v'7'F'F!G!GHH7+++++r   c                     t          j        t          t          j        | j                                      }|                     |t                     d S N)r   rT   rF   rG   rH   r   r   r   )r   r   s     r   -test_decoding_well_known_from_explicit_paramszCTestParameterEncoding.test_decoding_well_known_from_explicit_params   sA    uV%5d6H%I%IJJKKeX&&&&&r   c                     |                      t                    5 }t          j        ddg           d d d            n# 1 swxY w Y   |                     dt          |j                             d S )Nr   
explicitCAzOnly named_curve)r"   rL   r   rT   r$   r%   r&   rM   s     r   ,test_decoding_with_incorrect_valid_encodingszBTestParameterEncoding.test_decoding_with_incorrect_valid_encodings   s    z** 	0aN3///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	(#ak*:*:;;;;;s   >AAc                     t          ddd          }t          |ddddd          }t          |dd	ddd          }t          d
||d           }t          d
||d           }|                     ||           d S )N   r            	   T	generator   unknown)r
   r   r   r7   )r   curve_fpbase_abase_bcurve_acurve_bs         r   -test_compare_curves_with_different_generatorszCTestParameterEncoding.test_compare_curves_with_different_generators   s    2q!$$Xr1adCCCXq"adCCC	8VT::	8VT::GW-----r   c                 `   t          ddd          }t          |ddddd          }t          d	||d           }|                                }t          j        |          }|                     ||           d
}|                     |t          t          j        |                               d S )Nr_   r   r`   ra   rb   rc   Trd   rg   z0MCECAQEwDAYHKoZIzj0BAQIBFzAGBAEBBAEHBAMEDQMCAQk=)	r
   r   r   r;   rT   r2   rF   rG   rH   )r   rh   
base_pointr   r=   rV   expecteds          r   $test_default_encode_for_custom_curvez:TestParameterEncoding.test_default_encode_for_custom_curve   s    2q!$$ 2q!Q$GGG
i:t<<,,...))(((E%(8(B(B"C"CDDDDDr   c                 T   t          ddd          }t          |ddddd          }t          d	||d           }|                     t                    5 }|                    d
           d d d            n# 1 swxY w Y   |                     dt          |j                             d S )Nr_   r   r`   ra   rb   rc   Trd   rg   r    zCan't encode curve)	r
   r   r   r"   r   r;   r$   r%   r&   )r   rh   ro   r   r(   s        r   (test_named_curve_encode_for_custom_curvez>TestParameterEncoding.test_named_curve_encode_for_custom_curve   s    2q!$$ 2q!Q$GGG
i:t<<011 	(QLL'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	*C,<,<=====s   A55A9<A9c                 
   d}|                      t                    5 }t          j        t	          j        |                     d d d            n# 1 swxY w Y   |                     dt          |j                             d S )NzMIGRAgEBMBwGByqGSM49AQIwEQIBcQYJKoZIzj0BAgMCAgEJMDkEDwAwiCUMpufH/mSc6Fgg9wQPAOi+5NPiJgdEGIvg6ccjAxUAEOcjqxTWluZ2h1YVF1b+v4/LSakEHwQAnXNhbzX0qxQH1zViwQ8ApSgwJ3lY7oTRMV7TGIYCDwEAAAAAAAAA2czsijnlbwIBAg==z#Characteristic 2 curves unsupported)	r"   r   r   rT   rG   rH   r$   r%   r&   )r   sect113r1_explicitr(   s      r   !test_try_decoding_binary_explicitz7TestParameterEncoding.test_try_decoding_binary_explicit   s     	 011 	AQN6+,>??@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	;S=M=MNNNNNs   'AAAc                 F   t          j        t          j         t          j        d          z   }|                     t           j                  5 }t          j        |           d d d            n# 1 swxY w Y   | 	                    dt          |j                             d S )Nr   zUnexpected data after OID)r   
encode_oidr   oidencode_integerr"   r#   r   rT   r$   r%   r&   r   bad_derr(   s      r   !test_decode_malformed_named_curvez7TestParameterEncoding.test_decode_malformed_named_curve   s    .(,/#2DQ2G2GGs011 	$QN7###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	13q{3C3CDDDDDs   A..A25A2c                 b   t          t          j        | j                            t	          j        d          z   }|                     t          j                  5 }t          j	        |           d d d            n# 1 swxY w Y   | 
                    dt          |j                             d S )Nr   z"Unexpected data after ECParameters)rF   rG   rH   r   r   rz   r"   r#   r   rT   r$   r%   r&   r{   s      r   4test_decode_malformed_explicit_garbage_after_ECParamzJTestParameterEncoding.test_decode_malformed_explicit_garbage_after_ECParam   s    T/00
 
q!!" s011 	$QN7###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	:C<L<LMMMMMs   A<<B B c                 8   t          j        t          j        d                    }|                     t           j                  5 }t          j        |           d d d            n# 1 swxY w Y   |                     dt          |j	                             d S )N   z!Unknown parameter encoding format)
r   encode_sequencerz   r"   r#   r   rT   r$   r%   r&   r{   s      r   ,test_decode_malformed_unknown_version_numberzBTestParameterEncoding.test_decode_malformed_unknown_version_number   s    %c&8&;&;<<s011 	$QN7###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	93q{;K;KLLLLLs   A''A+.A+c                    t           j                                        }t          j        t          j        d          t          j        t          j        ddd          t          j        |                    t          j        t          j        t          t           j        	                                |z  |                    t          j        t          t           j        
                                |                              t          j        t           j                            d                    t          j        t           j                                                            }|                     t                    5 }t!          j        |           d d d            n# 1 swxY w Y   |                     dt'          |j                             d S )Nr   r   rb   uncompressedzUnknown field type: (1, 2, 3))r   r   pr   r   rz   rx   encode_octet_stringr   abre   to_bytesorderr"   r   r   rT   r$   r%   r&   r   curve_pr|   r(   s       r   (test_decode_malformed_unknown_field_typez>TestParameterEncoding.test_decode_malformed_unknown_field_type   s   .""$$%q!!q!Q'');G)D)D  '$X^%5%5%7%7'%A7KK  '$X^%5%5%7%7AA 	  #"++N;;  x17799::!
 
& 011 	$QN7###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	5s1;7G7GHHHHHs   F((F,/F,c                    t           j                                        }t          j        t          j        d          t          j        t          j        t           t          j        |          t          j        d                    t          j        t          j        t          t           j        
                                |z  |                    t          j        t          t           j                                        |                              t          j        t           j                            d                    t          j        t           j                                                            }|                     t          j                  5 }t#          j        |           d d d            n# 1 swxY w Y   |                     dt)          |j                             d S )Nr   r   zPrime-p element)r   r   r   r   r   rz   rx   r   r   r   r   r   re   r   r   r"   r#   r   rT   r$   r%   r&   r   s       r   )test_decode_malformed_garbage_after_primez?TestParameterEncoding.test_decode_malformed_garbage_after_prime  s   .""$$%q!!0"7++"1%% 
 '$X^%5%5%7%7'%A7KK  '$X^%5%5%7%7AA 	  #"++N;;  x17799::%
 
* s011 	$QN7###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	'Q[)9)9:::::s   F==GGN)__name__
__module____qualname__classmethodr   r   r)   r-   r/   r4   r8   r>   rC   rI   rN   rR   rW   rZ   r]   rm   rq   rs   rv   r}   r   r   r   r    r   r   r   r      s       	
 	
 [	
' ' 'I I I	L 	L 	LA A A/ / /+ + +O O O9 9 9O O O
> > >
 
 
, , , ' ' '
< < <. . .E E E 	> 	> 	>O O OE E EN N NM M MI I I4; ; ; ; ;r   r   c                   &    e Zd Zd Zd Zd Zd ZdS )TestCurveSearchingc                 Z    t          d          }|                     |t                     d S )Nr   r	   r   r   r   cs     r   test_correct_namez$TestCurveSearching.test_correct_name+  s)    *%%a"""""r   c                 Z    t          d          }|                     |t                     d S )N
prime256v1r   r   s     r   test_openssl_namez$TestCurveSearching.test_openssl_name/  s)    ,''a"""""r   c                     |                      t                    5 }t          d           d d d            n# 1 swxY w Y   |                     dt	          |j                             d S )Nzfoo barzFname 'foo bar' unknown, only curves supported: ['NIST192p', 'NIST224p'r"   r   r	   r$   r%   r&   rM   s     r   test_unknown_curvez%TestCurveSearching.test_unknown_curve3  s    011 	%Q)$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	&	
 	
 	
 	
 	
   7;;c                     |                      t                    5 }t          d            d d d            n# 1 swxY w Y   |                     dt	          |j                             d S )NzAname None unknown, only curves supported: ['NIST192p', 'NIST224p'r   rM   s     r   test_with_None_as_parameterz.TestCurveSearching.test_with_None_as_parameter=  s    011 	 Q$	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	&	
 	
 	
 	
 	
r   N)r   r   r   r   r   r   r   r   r   r   r   r   *  sP        # # ## # #
 
 

 
 
 
 
r   r   r   c                     g | ]	}|j         
S r   name.0is     r   
<listcomp>r   H      .F.F.F!qv.F.F.Fr   )idsc                 d    t          j        |                     d                    }| |k    sJ d S r@   r   rT   r;   r   rets     r   %test_curve_params_encode_decode_namedr   H  s.    
.m44
5
5CC<<<<<<r   c                     g | ]	}|j         
S r   r   r   s     r   r   r   O  r   r   c                 *   t          | j        t                    rIt          j        t
                    5  |                     d           d d d            d S # 1 swxY w Y   d S t          j        |                     d                    }| |k    sJ d S rE   	
isinstancer   r   pytestraisesr   r;   r   rT   r   s     r   (test_curve_params_encode_decode_explicitr   O  s    %+y)) ],-- 	% 	%LL$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% nU\\*5566||||||s   AAAc                     g | ]	}|j         
S r   r   r   s     r   r   r   Z  r   r   c                 b    t          j        |                                           }| |k    sJ d S rY   r   r   s     r   'test_curve_params_encode_decode_defaultr   Z  s*    
.
(
(CC<<<<<<r   c                     g | ]	}|j         
S r   r   r   s     r   r   r   a  r   r   c                 .   t          | j        t                    rJt          j        t
                    5  |                     dd           d d d            d S # 1 swxY w Y   d S t          j        |                     dd                    }| |k    sJ d S )Nr,   rP   r   r   s     r   3test_curve_params_encode_decode_explicit_compressedr   a  s    %+y)) ],-- 	3 	3LL\222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 nU\\*lCCDD||||||s   AAA)	unittest2unittestImportErrorrG   r   r   r   r   r   r   r	   ellipticcurver
   r   r    r   utilr   TestCaser   r   markparametrizer   r   r   r   r   r   r   <module>r      sb          OOOOO                  ; : : : : : : : : :       " " " " " "R; R; R; R; R;H- R; R; R;j
 
 
 
 
* 
 
 
< &.F.Fv.F.F.FGG  HG &.F.Fv.F.F.FGG  HG &.F.Fv.F.F.FGG  HG &.F.Fv.F.F.FGG  HG  s    	