o
    Cjig>                     @   s  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 deZG dd dZedejejddZedejejddZedejejddZedejej ddZ!edej"ej#ddZ$edej%ej&ddZ'ed ej(ej)d!d"Z*ed#ej+ej,d$d%Z-ed&ej.ej/d'd(Z0ed)ej1ej2d*d+Z3ed,ej4ej5d-d.Z6ed/ej7ej8d0d1Z9ed2ej:ej;d3d4Z<ed5ej=ej>d6d7Z?ed8ej@ejAd9d:ZBed;ejCejDd<d=ZEed>ejFejGd?d@ZHedAejIejJdBdCZKedDejLejMdEdFZNedGejOejPdHdIZQedJejRejSdKdLZTedMejUejVdNdOZWedPejXejYdQdRZZedSej[ej\dTdUZ]edVej^ej_dWZ`edXejaejbdYZce$e'e*e-e0e3e6e<eBeHeNeTeZeeee!e`ece9e?eEeKeQeWe]gZddZd[ Zed\d] Zfd^S )_    )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   r/   r0   r1   r   r/   c                   @   s   e Zd ZdS )r   N)__name__
__module____qualname__ r5   r5   c/var/www/html/Resume-Parser/resume-parser-inhouse/venv/lib/python3.10/site-packages/ecdsa/curves.pyr   5   s    r   c                   @   s^   e Zd ZdddZdd Zdd Zdd	 ZdddZdddZe	dddZ
edddZdS )r   Nc                 C   s   || _ || _|| _|| _| | _t|tjr)t|	 d d d | _
| j
| _nt| j| _
dt|	  | _d| j
 | _|| _|rKtj| | _d S d S )Nr         r/   )nameopenssl_namecurve	generatororder
isinstancer   	CurveEdTwr   pbaselenverifying_key_lengthr	   signature_lengthoidr   
encode_oidencoded_oid)selfr9   r;   r<   rD   r:   r5   r5   r6   __init__:   s   

zCurve.__init__c                 C   s&   t |tr| j|jko| j|jkS tS N)r>   r   r;   r<   NotImplementedrG   otherr5   r5   r6   __eq__O   s   
zCurve.__eq__c                 C   s
   | |k S rI   r5   rK   r5   r5   r6   __ne__V   s   
zCurve.__ne__c                 C   s   | j S rI   r9   )rG   r5   r5   r6   __repr__Y   s   zCurve.__repr__uncompressedc                 C   s.  |du r| j r
d}nd}|dvrtd|dkr%| j stdtj| j  S t| jtjr6|dks2J td| j	 }t
d}ttjt t
|}ttt| j | |tt| j | |}t| j|}t
| j }|||||g}	| j rt
| 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
        Nnamed_curveexplicitrR   rS   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   )rD   
ValueErrorr   r   rE   r>   r;   r   r?   r@   encode_integerencode_sequencer+   encode_octet_stringr
   abr<   to_bytesr=   cofactorappend)rG   encodingpoint_encodingcurve_pversionfield_idr;   baser=   seq_elementsr\   r5   r5   r6   to_der\   sN   




zCurve.to_derc                 C   s   t | ||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   topemre   )rG   r^   r_   r5   r5   r6   to_pem   s   zCurve.to_pemc                 C   s  |st d}tdd |D stdt| } t| s7d|vr%tdt| \}}|r3tdt|S d|vr@td	t	| \}}|rNtd
t
|\}}|dkr^tdt	|\}}t	|\}}t|\}	}t
|\}
}d}|rt
|\}}t|\}}|tkrtd|tkrtd|t
|\}}|rtdt|\}}t|\}}t|}t|}t||||}tjj||	d|
dd}td||d}tD ]
}||kr|  S q|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`
        rT   c                 s   s    | ]}|d v V  qdS )rT   Nr5   ).0ir5   r5   r6   	<genexpr>   s    z!Curve.from_der.<locals>.<genexpr>z1Only named_curve and explicit encodings supportedrR   z(named_curve curve parameters not allowedzUnexpected data after OIDrS   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)rQ   
compressedhybridT)valid_encodingsr=   r<   unknown)setallrU   r   r   is_sequenceUnexpectedDERremove_objectr   remove_sequenceremove_integerremove_octet_stringr,   r   r+   formatr   r   CurveFpPointJacobi
from_bytesr   r   )datarm   rD   emptyseqra   restrb   r;   
base_bytesr=   r\   _
field_typeprimecurve_a_bytescurve_b_bytescurve_acurve_bcurve_fprc   	tmp_curveri   r5   r5   r6   from_der   s~   



zCurve.from_derc                 C   sL   t st|tr| }|d}|dkrtd| t||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   r>   strencodefindr   rr   r   unpem)clsstringrm   ec_param_indexr5   r5   r6   from_pem  s   


zCurve.from_pemrI   )NrQ   )r2   r3   r4   rH   rM   rN   rP   re   rg   staticmethodr   classmethodr   r5   r5   r5   r6   r   9   s    


<[r   r   )r         r      	secp112r1r   )r   r   r   r   r7   	secp112r2r   )r   r   r   r      	secp128r1r   )r   r   r   r   r8   	secp160r1r   )r   r/   r0   r1   r   r   r   
prime192v1r   )r   r   r   r   !   	secp224r1r   )r   r/   r0   r1   r   r   r7   
prime256v1r   )r   r   r   r   "   	secp384r1r   )r   r   r   r   #   	secp521r1r   )r   r   r   r   
   	secp256k1r   )
r   r   $   r   r   r/   r8   r   r   r   brainpoolP160r1r   )
r   r   r   r   r   r/   r8   r   r   r/   brainpoolP160t1r   )
r   r   r   r   r   r/   r8   r   r   r   brainpoolP192r1r    )
r   r   r   r   r   r/   r8   r   r      brainpoolP192t1r!   )
r   r   r   r   r   r/   r8   r   r      brainpoolP224r1r"   )
r   r   r   r   r   r/   r8   r   r   r   brainpoolP224t1r#   )
r   r   r   r   r   r/   r8   r   r   r7   brainpoolP256r1r$   )
r   r   r   r   r   r/   r8   r   r   r8   brainpoolP256t1r%   )
r   r   r   r   r   r/   r8   r   r   	   brainpoolP320r1r&   )
r   r   r   r   r   r/   r8   r   r   r   brainpoolP320t1r'   )
r   r   r   r   r   r/   r8   r   r      brainpoolP384r1r(   )
r   r   r   r   r   r/   r8   r   r      brainpoolP384t1r)   )
r   r   r   r   r   r/   r8   r   r      brainpoolP512r1r*   )
r   r   r   r   r   r/   r8   r   r      brainpoolP512t1r-   )r   r   e   p   r.   )r   r   r   q   c                 C   s6   t D ]}|j| kr|  S qtd| dd t D f )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
    zDI don't know about the curve with oid %s.I only know about these: %sc                 S      g | ]}|j qS r5   rO   rh   cr5   r5   r6   
<listcomp>5      zfind_curve.<locals>.<listcomp>)r   rD   r   )	oid_curver   r5   r5   r6   r   %  s   
r   c                 C   sF   t D ]}| |jks|jr| |jkr|  S qtd| dd t D )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}c                 S   r   r5   rO   r   r5   r5   r6   r   L  r   z!curve_by_name.<locals>.<listcomp>)r   r9   r:   r   rw   )r9   r   r5   r5   r6   r   9  s   r   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   r5   r5   r5   r6   <module>   s   & e			
																				
