U
    ʹh2                  &   @  sX  U d dl mZ d dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
 d dlmZ d dlmZmZ d dlmZ G dd	 d	ZG d
d dejdZG dd dejdZG dd dejdZeZeejj G dd dejdZeZeejj ejjZejj Z G dd deZ!G dd deZ"G dd deZ#G dd deZ$G dd deZ%G dd deZ&G dd  d eZ'G d!d" d"eZ(G d#d$ d$eZ)G d%d& d&eZ*G d'd( d(eZ+G d)d* d*eZ,G d+d, d,eZ-G d-d. d.eZ.G d/d0 d0eZ/G d1d2 d2eZ0G d3d4 d4eZ1G d5d6 d6eZ2G d7d8 d8eZ3e0 e- e0 e/ e- e, e+ e. e* e) e( e' e& e% e$ e# e" e! e1 e2 e3 d9Z4d:e5d;< G d<d= d=eZ6ejj7Z7dJd>dd?dd@dAdBZ8G dCdD dDZ9ej0e0ej/e/ej.e.ej-e-ej,e,ej+e+ej:e1ej;e2ej<e3ej*e*ej%e%ej)e)ej$e$ej(e(ej#e#ej'e'ej"e"ej&e&ej!e!iZ=dEdFdGdHdIZ>dS )K    )annotationsN)utils)UnsupportedAlgorithm_Reasons)ObjectIdentifier)openssl)_serializationhashesc                   @  s   e Zd ZedZedZedZedZedZedZ	edZ
edZed	Zed
ZedZedZedZedZedZedZedZedZedZdS )EllipticCurveOIDz1.2.840.10045.3.1.1z1.3.132.0.33z1.3.132.0.10z1.2.840.10045.3.1.7z1.3.132.0.34z1.3.132.0.35z1.3.36.3.3.2.8.1.1.7z1.3.36.3.3.2.8.1.1.11z1.3.36.3.3.2.8.1.1.13z1.3.132.0.1z1.3.132.0.15z1.3.132.0.26z1.3.132.0.27z1.3.132.0.16z1.3.132.0.17z1.3.132.0.36z1.3.132.0.37z1.3.132.0.38z1.3.132.0.39N)__name__
__module____qualname__r   	SECP192R1	SECP224R1	SECP256K1	SECP256R1	SECP384R1	SECP521R1BRAINPOOLP256R1BRAINPOOLP384R1BRAINPOOLP512R1	SECT163K1	SECT163R2	SECT233K1	SECT233R1	SECT283K1	SECT283R1	SECT409K1	SECT409R1	SECT571K1	SECT571R1 r!   r!   R./venv/lib/python3.8/site-packages/cryptography/hazmat/primitives/asymmetric/ec.pyr
      s&   r
   c                   @  sT   e Zd ZeejddddZeejddddZeejdddd	Zd
S )EllipticCurvestrreturnc                 C  s   dS )z8
        The name of the curve. e.g. secp256r1.
        Nr!   selfr!   r!   r"   name)   s    zEllipticCurve.nameintc                 C  s   dS z<
        Bit size of a secret scalar for the curve.
        Nr!   r'   r!   r!   r"   key_size0   s    zEllipticCurve.key_sizec                 C  s   dS )z1
        The order of the curve's group.
        Nr!   r'   r!   r!   r"   group_order7   s    zEllipticCurve.group_orderN)	r   r   r   propertyabcabstractmethodr)   r,   r-   r!   r!   r!   r"   r#   (   s   r#   )	metaclassc                   @  s$   e Zd ZeejddddZdS )EllipticCurveSignatureAlgorithm+asym_utils.Prehashed | hashes.HashAlgorithmr%   c                 C  s   dS )z@
        The digest algorithm used with this signature.
        Nr!   r'   r!   r!   r"   	algorithm@   s    z)EllipticCurveSignatureAlgorithm.algorithmN)r   r   r   r.   r/   r0   r4   r!   r!   r!   r"   r2   ?   s   r2   c                   @  s   e Zd ZejddddddZejdddd	Zeejd
dddZeejddddZ	ejddddddZ
ejddddZejdddddddZejd dddZd S )!EllipticCurvePrivateKeyECDHEllipticCurvePublicKeybytes)r4   peer_public_keyr&   c                 C  s   dS )z}
        Performs a key exchange operation using the provided algorithm with the
        provided peer's public key.
        Nr!   )r(   r4   r9   r!   r!   r"   exchangeK   s    z EllipticCurvePrivateKey.exchanger%   c                 C  s   dS )zB
        The EllipticCurvePublicKey for this private key.
        Nr!   r'   r!   r!   r"   
public_keyT   s    z"EllipticCurvePrivateKey.public_keyr#   c                 C  s   dS z8
        The EllipticCurve that this key is on.
        Nr!   r'   r!   r!   r"   curveZ   s    zEllipticCurvePrivateKey.curver*   c                 C  s   dS r+   r!   r'   r!   r!   r"   r,   a   s    z EllipticCurvePrivateKey.key_sizeutils.Bufferr2   )datasignature_algorithmr&   c                 C  s   dS )z 
        Signs the data
        Nr!   )r(   r?   r@   r!   r!   r"   signh   s    zEllipticCurvePrivateKey.signEllipticCurvePrivateNumbersc                 C  s   dS )z9
        Returns an EllipticCurvePrivateNumbers.
        Nr!   r'   r!   r!   r"   private_numbersr   s    z'EllipticCurvePrivateKey.private_numbers_serialization.Encodingz_serialization.PrivateFormatz)_serialization.KeySerializationEncryption)encodingformatencryption_algorithmr&   c                 C  s   dS z6
        Returns the key serialized as bytes.
        Nr!   )r(   rE   rF   rG   r!   r!   r"   private_bytesx   s    z%EllipticCurvePrivateKey.private_bytesc                 C  s   dS z!
        Returns a copy.
        Nr!   r'   r!   r!   r"   __copy__   s    z EllipticCurvePrivateKey.__copy__N)r   r   r   r/   r0   r:   r;   r.   r=   r,   rA   rC   rI   rK   r!   r!   r!   r"   r5   J   s$   	
r5   c                   @  s   e Zd ZeejddddZeejddddZejddd	d
ZejddddddZ	ejdddddddZ
eddd dddZejdddddZejd ddd Zd!S )"r7   r#   r%   c                 C  s   dS r<   r!   r'   r!   r!   r"   r=      s    zEllipticCurvePublicKey.curver*   c                 C  s   dS r+   r!   r'   r!   r!   r"   r,      s    zEllipticCurvePublicKey.key_sizeEllipticCurvePublicNumbersc                 C  s   dS )z8
        Returns an EllipticCurvePublicNumbers.
        Nr!   r'   r!   r!   r"   public_numbers   s    z%EllipticCurvePublicKey.public_numbersrD   z_serialization.PublicFormatr8   )rE   rF   r&   c                 C  s   dS rH   r!   )r(   rE   rF   r!   r!   r"   public_bytes   s    z#EllipticCurvePublicKey.public_bytesr>   r2   None)	signaturer?   r@   r&   c                 C  s   dS )z5
        Verifies the signature of the data.
        Nr!   )r(   rP   r?   r@   r!   r!   r"   verify   s    zEllipticCurvePublicKey.verify)r=   r?   r&   c                 C  sB   t d| t|dkr td|d dkr4tdtj||S )Nr?   r   z%data must not be an empty byte string)         z%Unsupported elliptic curve point type)r   _check_byteslen
ValueErrorrust_opensslecZfrom_public_bytes)clsr=   r?   r!   r!   r"   from_encoded_point   s    z)EllipticCurvePublicKey.from_encoded_pointobjectbool)otherr&   c                 C  s   dS )z"
        Checks equality.
        Nr!   )r(   r^   r!   r!   r"   __eq__   s    zEllipticCurvePublicKey.__eq__c                 C  s   dS rJ   r!   r'   r!   r!   r"   rK      s    zEllipticCurvePublicKey.__copy__N)r   r   r   r.   r/   r0   r=   r,   rM   rN   rQ   classmethodr[   r_   rK   r!   r!   r!   r"   r7      s$   	
r7   c                   @  s   e Zd ZdZdZdZdS )r    	sect571r1i:  l&   GN_&f.TO!9;{(c3B9LU1Nr   r   r   r)   r,   r-   r!   r!   r!   r"   r       s   r    c                   @  s   e Zd ZdZdZdZdS )r   	sect409r1  l   sD34&8x@'>R_>fK05*<                            Nrb   r!   r!   r!   r"   r      s   r   c                   @  s   e Zd ZdZdZdZdS )r   	sect283r1  l   3[_)!XeRq$?0K9Nrb   r!   r!   r!   r"   r      s   r   c                   @  s   e Zd ZdZdZdZdS )r   	sect233r1   l   `t&e9]	               Nrb   r!   r!   r!   r"   r      s   r   c                   @  s   e Zd ZdZdZdZdS )r   	sect163r2   l   3LFHJ08?/R          Nrb   r!   r!   r!   r"   r      s   r   c                   @  s   e Zd ZdZdZdZdS )r   	sect571k1i;  l&   F=^gEk;RNkKab	z95,1q!aL                                     @Nrb   r!   r!   r!   r"   r      s   r   c                   @  s   e Zd ZdZdZdZdS )r   	sect409k1rd   l   _<@Z%|4>UD (;x Nrb   r!   r!   r!   r"   r      s   r   c                   @  s   e Zd ZdZdZdZdS )r   	sect283k1rf   l   a<,<x("wK]:h..Nrb   r!   r!   r!   r"   r     s   r   c                   @  s   e Zd ZdZdZdZdS )r   	sect233k1rh   l   +bWkwFM"VN              @ Nrb   r!   r!   r!   r"   r   
  s   r   c                   @  s   e Zd ZdZdZdZdS )r   	sect163k1rj   l   %360@          Nrb   r!   r!   r!   r"   r     s   r   c                   @  s   e Zd ZdZdZdZdS )r   	secp521r1i	  l#   	dp"z\}[z3"nZ;PK#
`7roCQNrb   r!   r!   r!   r"   r     s   r   c                   @  s   e Zd ZdZdZdZdS )r   	secp384r1  l   s)e`gwlX_[nlv|Nrb   r!   r!   r!   r"   r     s   r   c                   @  s   e Zd ZdZdZdZdS )r   	secp256r1   l   Q%x+Ohbi+}s   @ Nrb   r!   r!   r!   r"   r   "  s   r   c                   @  s   e Zd ZdZdZdZdS )r   	secp256k1rt   l   AAl 3z~i9nW~ Nrb   r!   r!   r!   r"   r   *  s   r   c                   @  s   e Zd ZdZdZdZdS )r   	secp224r1   l   =*8%(?Nrb   r!   r!   r!   r"   r   2  s   r   c                   @  s   e Zd ZdZdZdZdS )r   	secp192r1   l   1(i&^#a;Nrb   r!   r!   r!   r"   r   8  s   r   c                   @  s   e Zd ZdZdZdZdS )BrainpoolP256R1brainpoolP256r1rt   l   V.
: yo4,(qvBT0C7U{h+) Nrb   r!   r!   r!   r"   rz   >  s   rz   c                   @  s   e Zd ZdZdZdZdS )BrainpoolP384R1brainpoolP384r1rr   l   eeRHA\1o+['K2s31
U{8/C{u%NQA9Nrb   r!   r!   r!   r"   r|   F  s   r|   c                   @  s   e Zd ZdZdZdZdS )BrainpoolP512R1brainpoolP512r1i   l#   i R9
Z<,-B`XG Xe3$*S .>U@Sf9fAtrY0'qjNg"qmU Nrb   r!   r!   r!   r"   r~   L  s   r~   )Z
prime192v1Z
prime256v1rx   rv   rs   rq   rp   ru   ro   rn   rm   rl   rk   ri   rg   re   rc   ra   r{   r}   r   zdict[str, EllipticCurve]_CURVE_TYPESc                   @  sB   e Zd ZddddddZedddd	Zeddd
dZdS )ECDSAFr3   r]   )r4   deterministic_signingc                 C  s4   ddl m} |r$| s$tdtj|| _|| _d S )Nr   )backendzZECDSA with deterministic signature (RFC 6979) is not supported by this version of OpenSSL.)Z,cryptography.hazmat.backends.openssl.backendr   Zecdsa_deterministic_supportedr   r   Z UNSUPPORTED_PUBLIC_KEY_ALGORITHM
_algorithm_deterministic_signing)r(   r4   r   r   r!   r!   r"   __init__l  s    zECDSA.__init__r%   c                 C  s   | j S N)r   r'   r!   r!   r"   r4     s    zECDSA.algorithmc                 C  s   | j S r   )r   r'   r!   r!   r"   r     s    zECDSA.deterministic_signingN)F)r   r   r   r   r.   r4   r   r!   r!   r!   r"   r   k  s    r   r*   z
typing.Any)private_valuer=   r   r&   c                 C  s0   t | tstd| dkr"tdtj| |S )Nz&private_value must be an integer type.r   z)private_value must be a positive integer.)
isinstancer*   	TypeErrorrW   rX   rY   derive_private_key)r   r=   r   r!   r!   r"   r     s
    
r   c                   @  s   e Zd ZdS )r6   N)r   r   r   r!   r!   r!   r"   r6     s   r6   r   ztype[EllipticCurve])oidr&   c                 C  s,   z
t |  W S  tk
r&   tdY nX d S )NzCThe provided object identifier has no matching elliptic curve class)_OID_TO_CURVEKeyErrorLookupError)r   r!   r!   r"   get_curve_for_oid  s    
r   )N)?Z
__future__r   r/   typingZcryptographyr   Zcryptography.exceptionsr   r   Zcryptography.hazmat._oidr   Z"cryptography.hazmat.bindings._rustr   rX   Zcryptography.hazmat.primitivesr   r	   Z)cryptography.hazmat.primitives.asymmetricZ
asym_utilsr
   ABCMetar#   r2   r5   Z(EllipticCurvePrivateKeyWithSerializationregisterrY   ZECPrivateKeyr7   Z'EllipticCurvePublicKeyWithSerializationZECPublicKeyrB   rL   r    r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rz   r|   r~   r   __annotations__r   Zgenerate_private_keyr   r6   r   r   r   r   r   r!   r!   r!   r"   <module>   s    @E!                    