o
    6Îhg>  ã                   @   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   ú`/var/www/html/construction_image-detection-poc/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 ¡ 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©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}|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`
        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û	û	û	û
û	û	û	û	û	û	û	û	û	û	û	û	û	û	û	û	û	û	û	û	üü
æ