
    tZhg>                     R   d dl mZ d dlmZ ddlmZmZmZmZ ddl	m
Z
mZmZ ddlmZmZ g dZdZd	Z G d
 de      Z G d d      Z edej,                  ej.                  dd      Z edej2                  ej4                  dd      Z edej8                  ej:                  dd      Z edej>                  ej@                  dd      Z! edejD                  ejF                  dd      Z$ edejJ                  ejL                  dd      Z' ed ejP                  ejR                  d!d"      Z* ed#ejV                  ejX                  d$d%      Z- ed&ej\                  ej^                  d'd(      Z0 ed)ejb                  ejd                  d*d+      Z3 ed,ejh                  ejj                  d-d.      Z6 ed/ejn                  ejp                  d0d1      Z9 ed2ejt                  ejv                  d3d4      Z< ed5ejz                  ej|                  d6d7      Z? ed8ej                  ej                  d9d:      ZB ed;ej                  ej                  d<d=      ZE ed>ej                  ej                  d?d@      ZH edAej                  ej                  dBdC      ZK edDej                  ej                  dEdF      ZN edGej                  ej                  dHdI      ZQ edJej                  ej                  dKdL      ZT edMej                  ej                  dNdO      ZW edPej                  ej                  dQdR      ZZ edSej                  ej                  dTdU      Z] edVej                  ej                  dW      Z` edXej                  ej                  dY      Zce$e'e*e-e0e3e6e<eBeHeNeTeZeeee!e`ece9e?eEeKeQeWe]gZddZ Zed[ Zfy\)]    )division)PY2   )derecdsaellipticcurveeddsa)orderlennumber_to_stringstring_to_number)normalise_bytes
bit_length)"UnknownCurveErrorr
   Curve	SECP112r1	SECP112r2	SECP128r1	SECP160r1NIST192pNIST224pNIST256pNIST384pNIST521pcurves
find_curvecurve_by_name	SECP256k1BRAINPOOLP160r1BRAINPOOLP160t1BRAINPOOLP192r1BRAINPOOLP192t1BRAINPOOLP224r1BRAINPOOLP224t1BRAINPOOLP256r1BRAINPOOLP256t1BRAINPOOLP320r1BRAINPOOLP320t1BRAINPOOLP384r1BRAINPOOLP384t1BRAINPOOLP512r1BRAINPOOLP512t1PRIME_FIELD_OIDCHARACTERISTIC_TWO_FIELD_OIDEd25519Ed448)r      H  ='  r   r   )r   r0   r1   r2   r   r0   c                       e Zd Zy)r   N)__name__
__module____qualname__     h/var/www/html/wine-match-dev/backend/winematch-backend/venv/lib/python3.12/site-packages/ecdsa/curves.pyr   r   5   s    r8   r   c                   Z    e Zd Zd
dZd Zd Zd ZddZddZe	d
d       Z
ed
d	       Zy)r   Nc                    || _         || _        || _        || _        |j	                         | _        t        |t        j                        r9t        |j                               dz   dz   dz  | _
        | j                  | _        n;t        | j                        | _
        dt        |j                               z  | _        d| j                  z  | _        || _        |rt        j                   | | _        y y )Nr         r0   )nameopenssl_namecurve	generatororder
isinstancer   	CurveEdTwr   pbaselenverifying_key_lengthr
   signature_lengthoidr   
encode_oidencoded_oid)selfr>   r@   rA   rI   r?   s         r9   __init__zCurve.__init__:   s    	(
"__&
e]445
 'uwwy1A59a?DL(,D%#DJJ/DL()HUWWY,?(?D% !DLL 0"~~s3D r8   c                     t        |t              r4| j                  |j                  k(  xr | j                  |j                  k(  S t        S N)rC   r   r@   rA   NotImplementedrL   others     r9   __eq__zCurve.__eq__O   s;    eU#

ekk)Odnn.O r8   c                     | |k(   S rO   r7   rQ   s     r9   __ne__zCurve.__ne__V   s    5=  r8   c                     | j                   S rO   )r>   )rL   s    r9   __repr__zCurve.__repr__Y   s    yyr8   c           	         || j                   rd}nd}|dvrt        d      |dk(  r3| j                   st        d      t        j                  | j                    S t        | j                  t        j                        r|dk(  sJ t        d      | j                  j                         }t        j                  d      }t        j                  t        j                  t         t        j                  |            }t        j                  t        j                  t        | j                  j                         |z  |            t        j                  t        | j                  j!                         |z  |                  }t        j                  | j"                  j%                  |            }t        j                  | j"                  j'                               }|||||g}	| j                  j)                         r>t        j                  | j                  j)                               }
|	j+                  |
       t        j                  |	 S )a  Serialise the curve parameters to binary string.

        :param str encoding: the format to save the curve parameters in.
            Default is ``named_curve``, with fallback being the ``explicit``
            if the OID is not set for the curve.
        :param str point_encoding: the point encoding of the generator when
            explicit curve encoding is used. Ignored for ``named_curve``
            format.

        :return: DER encoded ECParameters structure
        :rtype: bytes
        named_curveexplicitrY   rZ   z5Only 'named_curve' and 'explicit' encodings supportedzJCan't encode curve using named_curve encoding without associated curve OIDz6Twisted Edwards curves don't support explicit encodingr   )rI   
ValueErrorr   r   rJ   rC   r@   r   rD   rE   encode_integerencode_sequencer,   encode_octet_stringr   abrA   to_bytesrB   cofactorappend)rL   encodingpoint_encodingcurve_pversionfield_idr@   baserB   seq_elementsrc   s              r9   to_derzCurve.to_der\   s    xx(%66G  }$88'+  >>488,,

M$;$;<z)))#H 
 **,,.$$Q'&&NNO,c.@.@.I
 #### '!97C ## '!97C	
 &&t~~'>'>~'NO""4>>#7#7#9:5$>:: ))$***=*=*?@H)""L11r8   c                 N    t        j                  | j                  ||      d      S )a  
        Serialise the curve parameters to the :term:`PEM` format.

        :param str encoding: the format to save the curve parameters in.
            Default is ``named_curve``, with fallback being the ``explicit``
            if the OID is not set for the curve.
        :param str point_encoding: the point encoding of the generator when
            explicit curve encoding is used. Ignored for ``named_curve``
            format.

        :return: PEM encoded ECParameters structure
        :rtype: str
        zEC PARAMETERS)r   topemrl   )rL   re   rf   s      r9   to_pemzCurve.to_pem   s%     yyKK.1?
 	
r8   c                 p   |st        d      }t        d |D              st        d      t        |       } t	        j
                  |       sSd|vrt	        j                  d      t	        j                  |       \  }}|rt	        j                  d      t        |      S d|vrt	        j                  d      t	        j                  |       \  }}|rt	        j                  d	      t	        j                  |      \  }}|d
k7  rt	        j                  d      t	        j                  |      \  }}t	        j                  |      \  }}t	        j                  |      \  }	}t	        j                  |      \  }
}d}|rt	        j                  |      \  }}t	        j                  |      \  }}|t        k(  rt        d      |t        k7  rt        dj                  |            t	        j                  |      \  }}|rt	        j                  d      t	        j                  |      \  }}t	        j                  |      \  }}t!        |      }t!        |      }t#        j$                  ||||      }t"        j&                  j)                  ||	d|
d      }t+        d||d      }t,        D ]  }||k(  s	|c S  |S )a  Decode the curve parameters from DER file.

        :param data: the binary string to decode the parameters from
        :type data: :term:`bytes-like object`
        :param valid_encodings: set of names of allowed encodings, by default
            all (set by passing ``None``), supported ones are ``named_curve``
            and ``explicit``
        :type valid_encodings: :term:`set-like object`
        r[   c              3   $   K   | ]  }|d v  
 yw)r[   Nr7   ).0is     r9   	<genexpr>z!Curve.from_der.<locals>.<genexpr>   s     M133Ms   z1Only named_curve and explicit encodings supportedrY   z(named_curve curve parameters not allowedzUnexpected data after OIDrZ   z%explicit curve parameters not allowedz,Unexpected data after ECParameters structurer   z!Unknown parameter encoding formatNz#Characteristic 2 curves unsupportedzUnknown field type: {0}z:Unexpected data after ECParameters.fieldID.Prime-p element)uncompressed
compressedhybridT)valid_encodingsrB   rA   unknown)setallr\   r   r   is_sequenceUnexpectedDERremove_objectr   remove_sequenceremove_integerremove_octet_stringr-   r   r,   formatr   r   CurveFpPointJacobi
from_bytesr   r   )datarx   rI   emptyseqrh   restri   r@   
base_bytesrB   rc   _
field_typeprimecurve_a_bytescurve_b_bytescurve_acurve_bcurve_fprj   	tmp_curvers   s                          r9   from_derzCurve.from_der   s    !"=>OM_MMC  t$t$O3''>  **40JC''(CDDc?"_,##$KLL((.
U##>  **3/a<##$GHH,,T2$))$/t2248
D((.t ,,T2KHa ,,X6
D55#$IJJ(#)00<  ))$/u##L 
 "55e<t!55d;t #=1"=1 (((K ((33D 4 
 )XtT:	  	AA~	 r8   c                     t         s t        |t              r|j                         }|j	                  d      }|dk(  rt        j                  d      | j                  t        j                  ||d       |      S )am  Decode the curve parameters from PEM file.

        :param str string: the text string to decode the parameters from
        :param valid_encodings: set of names of allowed encodings, by default
            all (set by passing ``None``), supported ones are ``named_curve``
            and ``explicit``
        :type valid_encodings: :term:`set-like object`
        s   -----BEGIN EC PARAMETERS-----z"EC PARAMETERS PEM header not foundN)	r   rC   strencodefindr   r}   r   unpem)clsstringrx   ec_param_indexs       r9   from_pemzCurve.from_pem  sj     z&#.]]_F%EFR##$HII||IIf^_-.
 	
r8   rO   )Nru   )r4   r5   r6   rM   rS   rU   rW   rl   ro   staticmethodr   classmethodr   r7   r8   r9   r   r   9   sL    4*!:2x
$ Y Yv 
 
r8   r   r   )r         r      	secp112r1r   )r   r   r   r   r<   	secp112r2r   )r   r   r   r      	secp128r1r   )r   r   r   r   r=   	secp160r1r   )r   r0   r1   r2   r   r   r   
prime192v1r   )r   r   r   r   !   	secp224r1r   )r   r0   r1   r2   r   r   r<   
prime256v1r   )r   r   r   r   "   	secp384r1r   )r   r   r   r   #   	secp521r1r   )r   r   r   r   
   	secp256k1r   )
r   r   $   r   r   r0   r=   r   r   r   brainpoolP160r1r   )
r   r   r   r   r   r0   r=   r   r   r0   brainpoolP160t1r    )
r   r   r   r   r   r0   r=   r   r   r   brainpoolP192r1r!   )
r   r   r   r   r   r0   r=   r   r      brainpoolP192t1r"   )
r   r   r   r   r   r0   r=   r   r      brainpoolP224r1r#   )
r   r   r   r   r   r0   r=   r   r   r   brainpoolP224t1r$   )
r   r   r   r   r   r0   r=   r   r   r<   brainpoolP256r1r%   )
r   r   r   r   r   r0   r=   r   r   r=   brainpoolP256t1r&   )
r   r   r   r   r   r0   r=   r   r   	   brainpoolP320r1r'   )
r   r   r   r   r   r0   r=   r   r   r   brainpoolP320t1r(   )
r   r   r   r   r   r0   r=   r   r      brainpoolP384r1r)   )
r   r   r   r   r   r0   r=   r   r      brainpoolP384t1r*   )
r   r   r   r   r   r0   r=   r   r      brainpoolP512r1r+   )
r   r   r   r   r   r0   r=   r   r      brainpoolP512t1r.   )r   r   e   p   r/   )r   r   r   q   c           	          t         D ]  }|j                  | k(  s|c S  t        d| dt         D cg c]  }|j                   c}      c c}w )a9  Select a curve based on its OID

    :param tuple[int,...] oid_curve: ASN.1 Object Identifier of the
        curve to return, like ``(1, 2, 840, 10045, 3, 1, 7)`` for ``NIST256p``.

    :raises UnknownCurveError: When the oid doesn't match any of the supported
        curves

    :rtype: ~ecdsa.curves.Curve
    z&I don't know about the curve with oid z.I only know about these: )r   rI   r   r>   )	oid_curvecs     r9   r   r   %  sP      55IH )2V4LQVV4L	N 4Ls   Ac           	          t         D ]1  }| |j                  k(  s|j                  s| |j                  k(  s/|c S  t        dj	                  | t         D cg c]  }|j                   c}            c c}w )a{  Select a curve based on its name.

    Returns a :py:class:`~ecdsa.curves.Curve` object with a ``name`` name.
    Note that ``name`` is case-sensitve.

    :param str name: Name of the curve to return, like ``NIST256p`` or
        ``prime256v1``

    :raises UnknownCurveError: When the name doesn't match any of the supported
        curves

    :rtype: ~ecdsa.curves.Curve
    z9Curve with name {0!r} unknown, only curves supported: {1})r   r>   r?   r   r   )r>   r   s     r9   r   r   9  sh      166>ann1GH CJJ6*a166*	
 *s   A2N)g
__future__r   sixr    r   r   r   r	   utilr
   r   r   _compatr   r   __all__r,   r-   	Exceptionr   r   curve_112r1generator_112r1r   curve_112r2generator_112r2r   curve_128r1generator_128r1r   curve_160r1generator_160r1r   	curve_192generator_192r   	curve_224generator_224r   	curve_256generator_256r   	curve_384generator_384r   	curve_521generator_521r   curve_secp256k1generator_secp256k1r   curve_brainpoolp160r1generator_brainpoolp160r1r   curve_brainpoolp160t1generator_brainpoolp160t1r   curve_brainpoolp192r1generator_brainpoolp192r1r    curve_brainpoolp192t1generator_brainpoolp192t1r!   curve_brainpoolp224r1generator_brainpoolp224r1r"   curve_brainpoolp224t1generator_brainpoolp224t1r#   curve_brainpoolp256r1generator_brainpoolp256r1r$   curve_brainpoolp256t1generator_brainpoolp256t1r%   curve_brainpoolp320r1generator_brainpoolp320r1r&   curve_brainpoolp320t1generator_brainpoolp320t1r'   curve_brainpoolp384r1generator_brainpoolp384r1r(   curve_brainpoolp384t1generator_brainpoolp384t1r)   curve_brainpoolp512r1generator_brainpoolp512r1r*   curve_brainpoolp512t1generator_brainpoolp512t1r+   curve_ed25519generator_ed25519r.   curve_ed448generator_ed448r/   r   r   r   r7   r8   r9   <module>r     s     . . > > 0
#L +7 		 	`
 `
H 			 			 			 			 	OO	 	OO	 	OO	 	OO	 	OO	 			 		### 		### 		### 		### 		### 		### 		### 		### 		### 		##$ 		##$ 		##$ 		##$ 		##$ 			 					 	5
<(r8   