o
    ¥6÷d68  ã                   @   s8  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jJdBƒZKedCejLejMdDƒZNe$e'e*e-e0e3e6e9e<e?eBeEeHeeee!eKeNgZOdEdF„ ZPdGdH„ ZQdIS )Jé    )Ú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ÚBRAINPOOLP192r1ÚBRAINPOOLP224r1ÚBRAINPOOLP256r1ÚBRAINPOOLP320r1ÚBRAINPOOLP384r1ÚBRAINPOOLP512r1ÚPRIME_FIELD_OIDÚCHARACTERISTIC_TWO_FIELD_OIDÚEd25519ÚEd448)r   é   éH  é='  r   r   )r   r(   r)   r*   r   r(   c                   @   s   e Zd ZdS )r   N)Ú__name__Ú
__module__Ú__qualname__© r.   r.   úcC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\ecdsa/curves.pyr   .   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   ÚpZbaselenZverifying_key_lengthr	   Zsignature_lengthÚoidr   Ú
encode_oidZencoded_oid)Úselfr2   r4   r5   r:   r3   r.   r.   r/   Ú__init__3   s   

ÿzCurve.__init__c                 C   s&   t |tƒr| j|jko| j|jkS tS ©N)r7   r   r4   r5   ÚNotImplemented©r<   Úotherr.   r.   r/   Ú__eq__H   s   
ÿzCurve.__eq__c                 C   s
   | |k S r>   r.   r@   r.   r.   r/   Ú__ne__O   s   
zCurve.__ne__c                 C   s   | j S r>   ©r2   )r<   r.   r.   r/   Ú__repr__R   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 ¡ r’t 
| 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©rG   rH   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   )r:   Ú
ValueErrorr   r   r;   r7   r4   r   r8   r9   Zencode_integerZencode_sequencer$   Zencode_octet_stringr
   ÚaÚbr5   Úto_bytesr6   ÚcofactorÚappend)r<   ÚencodingÚpoint_encodingZcurve_pÚversionÚfield_idr4   Úbaser6   Zseq_elementsrN   r.   r.   r/   Úto_derU   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   ZtopemrU   )r<   rP   rQ   r.   r.   r/   Ú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}|r…t 
|¡\}}t |¡\}}|tkr”tdƒ‚|tkrŸtd |¡ƒ‚t 
|¡\}}|r­t 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`
        rI   c                 s   s    | ]}|d v V  qdS )rI   Nr.   )Ú.0Úir.   r.   r/   Ú	<genexpr>°   s   € z!Curve.from_der.<locals>.<genexpr>z1Only named_curve and explicit encodings supportedrG   z(named_curve curve parameters not allowedzUnexpected data after OIDrH   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)rF   Ú
compressedZhybridT)Úvalid_encodingsr6   r5   Úunknown)ÚsetÚallrJ   r   r   Zis_sequenceÚUnexpectedDERZremove_objectr   Zremove_sequenceZremove_integerZremove_octet_stringr%   r   r$   Úformatr   r   ZCurveFpZPointJacobiÚ
from_bytesr   r   )Údatar[   r:   ÚemptyÚseqrR   ÚrestrS   r4   Z
base_bytesr6   rN   Ú_Z
field_typeÚprimeZcurve_a_bytesZcurve_b_bytesZcurve_aZcurve_bZcurve_fprT   Z	tmp_curverX   r.   r.   r/   Ú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   r7   ÚstrÚencodeÚfindr   r_   rh   Zunpem)ÚclsÚstringr[   Zec_param_indexr.   r.   r/   Úfrom_pemÿ   s   


ÿzCurve.from_pemr>   )NrF   )r+   r,   r-   r=   rB   rC   rE   rU   rV   Ústaticmethodrh   Úclassmethodro   r.   r.   r.   r/   r   2   s    


<[r   r   )r   é   é„   r   é   Z	secp112r1r   )r   rr   rs   r   r0   Z	secp112r2r   )r   rr   rs   r   é   Z	secp128r1r   )r   rr   rs   r   r1   Z	secp160r1r   )r   r(   r)   r*   rr   r   r   Z
prime192v1r   )r   rr   rs   r   é!   Z	secp224r1r   )r   r(   r)   r*   rr   r   r0   Z
prime256v1r   )r   rr   rs   r   é"   Z	secp384r1r   )r   rr   rs   r   é#   Z	secp521r1r   )r   rr   rs   r   é
   Z	secp256k1r   )
r   rr   é$   rr   rr   r(   r1   r   r   r   ZbrainpoolP160r1r   )
r   rr   rz   rr   rr   r(   r1   r   r   rr   ZbrainpoolP192r1r   )
r   rr   rz   rr   rr   r(   r1   r   r   é   ZbrainpoolP224r1r    )
r   rr   rz   rr   rr   r(   r1   r   r   r0   ZbrainpoolP256r1r!   )
r   rr   rz   rr   rr   r(   r1   r   r   é	   ZbrainpoolP320r1r"   )
r   rr   rz   rr   rr   r(   r1   r   r   é   ZbrainpoolP384r1r#   )
r   rr   rz   rr   rr   r(   r1   r   r   é   ZbrainpoolP512r1r&   )r   rr   ée   ép   r'   )r   rr   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 r.   rD   ©rW   Úcr.   r.   r/   Ú
<listcomp>è  ó    zfind_curve.<locals>.<listcomp>)r   r:   r   )Z	oid_curver„   r.   r.   r/   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‚   r.   rD   rƒ   r.   r.   r/   r…   ÿ  r†   z!curve_by_name.<locals>.<listcomp>)r   r2   r3   r   r`   )r2   r„   r.   r.   r/   r   ì  s   €ÿÿr   N)RÚ
__future__r   Úsixr   Ú r   r   r   r   Úutilr	   r
   r   Z_compatr   r   Ú__all__r$   r%   Ú	Exceptionr   r   Zcurve_112r1Zgenerator_112r1r   Zcurve_112r2Zgenerator_112r2r   Zcurve_128r1Zgenerator_128r1r   Zcurve_160r1Zgenerator_160r1r   Z	curve_192Zgenerator_192r   Z	curve_224Zgenerator_224r   Z	curve_256Zgenerator_256r   Z	curve_384Zgenerator_384r   Z	curve_521Zgenerator_521r   Zcurve_secp256k1Zgenerator_secp256k1r   Zcurve_brainpoolp160r1Zgenerator_brainpoolp160r1r   Zcurve_brainpoolp192r1Zgenerator_brainpoolp192r1r   Zcurve_brainpoolp224r1Zgenerator_brainpoolp224r1r   Zcurve_brainpoolp256r1Zgenerator_brainpoolp256r1r    Zcurve_brainpoolp320r1Zgenerator_brainpoolp320r1r!   Zcurve_brainpoolp384r1Zgenerator_brainpoolp384r1r"   Zcurve_brainpoolp512r1Zgenerator_brainpoolp512r1r#   Zcurve_ed25519Zgenerator_ed25519r&   Zcurve_ed448Zgenerator_ed448r'   r   r   r   r.   r.   r.   r/   Ú<module>   sH    eû	û	û	û
û	û	û	û	û	û	û	û	û	û	û	û	û	üü
í