U
    
;g(                  &   @  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!   P/tmp/pip-unpacked-wheel-yjz0rwd7/cryptography/hazmat/primitives/asymmetric/ec.pyr
      s&   r
   c                   @  s<   e Z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_sizeN)r   r   r   propertyabcabstractmethodr)   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"   	algorithm9   s    z)EllipticCurveSignatureAlgorithm.algorithmN)r   r   r   r-   r.   r/   r3   r!   r!   r!   r"   r1   8   s   r1   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dS )EllipticCurvePrivateKeyECDHEllipticCurvePublicKeybytes)r3   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(   r3   r8   r!   r!   r"   exchangeD   s    z EllipticCurvePrivateKey.exchanger%   c                 C  s   dS )zB
        The EllipticCurvePublicKey for this private key.
        Nr!   r'   r!   r!   r"   
public_keyM   s    z"EllipticCurvePrivateKey.public_keyr#   c                 C  s   dS z8
        The EllipticCurve that this key is on.
        Nr!   r'   r!   r!   r"   curveS   s    zEllipticCurvePrivateKey.curver*   c                 C  s   dS r+   r!   r'   r!   r!   r"   r,   Z   s    z EllipticCurvePrivateKey.key_sizer1   )datasignature_algorithmr&   c                 C  s   dS )z 
        Signs the data
        Nr!   )r(   r=   r>   r!   r!   r"   signa   s    zEllipticCurvePrivateKey.signEllipticCurvePrivateNumbersc                 C  s   dS )z9
        Returns an EllipticCurvePrivateNumbers.
        Nr!   r'   r!   r!   r"   private_numbersk   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(   rC   rD   rE   r!   r!   r"   private_bytesq   s    z%EllipticCurvePrivateKey.private_bytesN)r   r   r   r.   r/   r9   r:   r-   r<   r,   r?   rA   rG   r!   r!   r!   r"   r4   C   s    	r4   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dS )r6   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_numbersrB   z_serialization.PublicFormatr7   )rC   rD   r&   c                 C  s   dS rF   r!   )r(   rC   rD   r!   r!   r"   public_bytes   s    z#EllipticCurvePublicKey.public_bytesr1   None)	signaturer=   r>   r&   c                 C  s   dS )z5
        Verifies the signature of the data.
        Nr!   )r(   rL   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(   rZ   r!   r!   r"   __eq__   s    zEllipticCurvePublicKey.__eq__N)r   r   r   r-   r.   r/   r<   r,   rI   rJ   rM   classmethodrW   r[   r!   r!   r!   r"   r6      s    	
r6   c                   @  s   e Zd ZdZdZdS )r    	sect571r1i:  Nr   r   r   r)   r,   r!   r!   r!   r"   r       s   r    c                   @  s   e Zd ZdZdZdS )r   	sect409r1  Nr^   r!   r!   r!   r"   r      s   r   c                   @  s   e Zd ZdZdZdS )r   	sect283r1  Nr^   r!   r!   r!   r"   r      s   r   c                   @  s   e Zd ZdZdZdS )r   	sect233r1   Nr^   r!   r!   r!   r"   r      s   r   c                   @  s   e Zd ZdZdZdS )r   	sect163r2   Nr^   r!   r!   r!   r"   r      s   r   c                   @  s   e Zd ZdZdZdS )r   	sect571k1i;  Nr^   r!   r!   r!   r"   r      s   r   c                   @  s   e Zd ZdZdZdS )r   	sect409k1r`   Nr^   r!   r!   r!   r"   r      s   r   c                   @  s   e Zd ZdZdZdS )r   	sect283k1rb   Nr^   r!   r!   r!   r"   r      s   r   c                   @  s   e Zd ZdZdZdS )r   	sect233k1rd   Nr^   r!   r!   r!   r"   r      s   r   c                   @  s   e Zd ZdZdZdS )r   	sect163k1rf   Nr^   r!   r!   r!   r"   r      s   r   c                   @  s   e Zd ZdZdZdS )r   	secp521r1i	  Nr^   r!   r!   r!   r"   r      s   r   c                   @  s   e Zd ZdZdZdS )r   	secp384r1  Nr^   r!   r!   r!   r"   r      s   r   c                   @  s   e Zd ZdZdZdS )r   	secp256r1   Nr^   r!   r!   r!   r"   r     s   r   c                   @  s   e Zd ZdZdZdS )r   	secp256k1rp   Nr^   r!   r!   r!   r"   r     s   r   c                   @  s   e Zd ZdZdZdS )r   	secp224r1   Nr^   r!   r!   r!   r"   r     s   r   c                   @  s   e Zd ZdZdZdS )r   	secp192r1   Nr^   r!   r!   r!   r"   r     s   r   c                   @  s   e Zd ZdZdZdS )BrainpoolP256R1brainpoolP256r1rp   Nr^   r!   r!   r!   r"   rv     s   rv   c                   @  s   e Zd ZdZdZdS )BrainpoolP384R1brainpoolP384r1rn   Nr^   r!   r!   r!   r"   rx     s   rx   c                   @  s   e Zd ZdZdZdS )BrainpoolP512R1brainpoolP512r1i   Nr^   r!   r!   r!   r"   rz   !  s   rz   )Z
prime192v1Z
prime256v1rt   rr   ro   rm   rl   rq   rk   rj   ri   rh   rg   re   rc   ra   r_   r]   rw   ry   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 )ECDSAFr2   rY   )r3   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(   r3   r~   r   r!   r!   r"   __init__@  s    zECDSA.__init__r%   c                 C  s   | j S N)r   r'   r!   r!   r"   r3   S  s    zECDSA.algorithmc                 C  s   | j S r   )r   r'   r!   r!   r"   r~   Y  s    zECDSA.deterministic_signingN)F)r   r   r   r   r-   r3   r~   r!   r!   r!   r"   r}   ?  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*   	TypeErrorrS   rT   rU   derive_private_key)r   r<   r   r!   r!   r"   r   c  s
    
r   c                   @  s   e Zd ZdS )r5   N)r   r   r   r!   r!   r!   r"   r5   q  s   r5   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)?
__future__r   r.   typingZcryptographyr   Zcryptography.exceptionsr   r   Zcryptography.hazmat._oidr   Z"cryptography.hazmat.bindings._rustr   rT   Zcryptography.hazmat.primitivesr   r	   Z)cryptography.hazmat.primitives.asymmetricZ
asym_utilsr
   ABCMetar#   r1   r4   Z(EllipticCurvePrivateKeyWithSerializationregisterrU   ZECPrivateKeyr6   Z'EllipticCurvePublicKeyWithSerializationZECPublicKeyr@   rH   r    r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rv   rx   rz   r|   __annotations__r}   Zgenerate_private_keyr   r5   r   r   r   r   r   r!   r!   r!   r"   <module>   s    :?!                    