U
    /j'                     @  sT  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)e& e# e& e% e# e" e! e$ e' e( e) d%Z*d&e+d'< G d(d) d)eZ,ejj-Z-d6d*dd+dd,d-d.Z.G d/d0 d0Z/ej&e&ej%e%ej$e$ej#e#ej"e"ej!e!ej0e'ej1e(ej2e)i	Z3d1d2d3d4d5Z4dS )7    )annotationsN)utils)UnsupportedAlgorithm_Reasons)ObjectIdentifier)openssl)_serializationhashesc                   @  sT   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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.13N)__name__
__module____qualname__r   	SECP192R1	SECP224R1	SECP256K1	SECP256R1	SECP384R1	SECP521R1BRAINPOOLP256R1BRAINPOOLP384R1BRAINPOOLP512R1 r   r   P/tmp/pip-unpacked-wheel-qzbw3lpx/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_size&   s    zEllipticCurve.key_sizec                 C  s   dS )z1
        The order of the curve's group.
        Nr   r   r   r   r   group_order-   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   	algorithm6   s    z)EllipticCurveSignatureAlgorithm.algorithmN)r   r   r   r$   r%   r&   r*   r   r   r   r   r(   5   s   r(   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ejd d d!d"d#Zd$S )%EllipticCurvePrivateKeyECDHEllipticCurvePublicKeybytes)r*   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   r*   r/   r   r   r   exchangeA   s    z EllipticCurvePrivateKey.exchanger   c                 C  s   dS )zB
        The EllipticCurvePublicKey for this private key.
        Nr   r   r   r   r   
public_keyJ   s    z"EllipticCurvePrivateKey.public_keyr   c                 C  s   dS z8
        The EllipticCurve that this key is on.
        Nr   r   r   r   r   curveP   s    zEllipticCurvePrivateKey.curver    c                 C  s   dS r!   r   r   r   r   r   r"   W   s    z EllipticCurvePrivateKey.key_sizeutils.Bufferr(   )datasignature_algorithmr   c                 C  s   dS )z 
        Signs the data
        Nr   )r   r5   r6   r   r   r   sign^   s    zEllipticCurvePrivateKey.signEllipticCurvePrivateNumbersc                 C  s   dS )z9
        Returns an EllipticCurvePrivateNumbers.
        Nr   r   r   r   r   private_numbersh   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   r;   r<   r=   r   r   r   private_bytesn   s    z%EllipticCurvePrivateKey.private_bytesc                 C  s   dS z!
        Returns a copy.
        Nr   r   r   r   r   __copy__y   s    z EllipticCurvePrivateKey.__copy__dictmemor   c                 C  s   dS z&
        Returns a deep copy.
        Nr   r   rD   r   r   r   __deepcopy__   s    z$EllipticCurvePrivateKey.__deepcopy__N)r   r   r   r%   r&   r0   r1   r$   r3   r"   r7   r9   r?   rA   rG   r   r   r   r   r+   @   s(   	
r+   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ejd!d d"d#d$Zd%S )&r-   r   r   c                 C  s   dS r2   r   r   r   r   r   r3      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_numbersr:   z_serialization.PublicFormatr.   )r;   r<   r   c                 C  s   dS r>   r   )r   r;   r<   r   r   r   public_bytes   s    z#EllipticCurvePublicKey.public_bytesr4   r(   None)	signaturer5   r6   r   c                 C  s   dS )z5
        Verifies the signature of the data.
        Nr   )r   rL   r5   r6   r   r   r   verify   s    zEllipticCurvePublicKey.verify)r3   r5   r   c                 C  sB   t d| t|dkr td|d dkr4tdtj||S )Nr5   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)clsr3   r5   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__c                 C  s   dS r@   r   r   r   r   r   rA      s    zEllipticCurvePublicKey.__copy__rB   rC   c                 C  s   dS rE   r   rF   r   r   r   rG      s    z#EllipticCurvePublicKey.__deepcopy__N)r   r   r   r$   r%   r&   r3   r"   rI   rJ   rM   classmethodrW   r[   rA   rG   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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   	secp384r1  l   s)e`gwlX_[nlv|Nr^   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   @ Nr^   r   r   r   r   r      s   r   c                   @  s   e Zd ZdZdZdZdS )r   	secp256k1rb   l   AAl 3z~i9nW~ Nr^   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%(?Nr^   r   r   r   r   r      s   r   c                   @  s   e Zd ZdZdZdZdS )r   	secp192r1   l   1(i&^#a;Nr^   r   r   r   r   r      s   r   c                   @  s   e Zd ZdZdZdZdS )BrainpoolP256R1brainpoolP256r1rb   l   V.
: yo4,(qvBT0C7U{h+) Nr^   r   r   r   r   rh     s   rh   c                   @  s   e Zd ZdZdZdZdS )BrainpoolP384R1brainpoolP384r1r`   l   eeRHA\1o+['K2s31
U{8/C{u%NQA9Nr^   r   r   r   r   rj     s   rj   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 Nr^   r   r   r   r   rl     s   rl   )Z
prime192v1Z
prime256v1rf   rd   ra   r_   r]   rc   ri   rk   rm   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 )ECDSAFr)   rY   )r*   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.backendrq   Zecdsa_deterministic_supportedr   r   Z UNSUPPORTED_PUBLIC_KEY_ALGORITHM
_algorithm_deterministic_signing)r   r*   rp   rq   r   r   r   __init__(  s    zECDSA.__init__r   c                 C  s   | j S N)rr   r   r   r   r   r*   ;  s    zECDSA.algorithmc                 C  s   | j S ru   )rs   r   r   r   r   rp   A  s    zECDSA.deterministic_signingN)F)r   r   r   rt   r$   r*   rp   r   r   r   r   ro   '  s    ro   r    z
typing.Any)private_valuer3   rq   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)rv   r3   rq   r   r   r   ry   K  s
    
ry   c                   @  s   e Zd ZdS )r,   N)r   r   r   r   r   r   r   r,   Y  s   r,   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)rz   r   r   r   get_curve_for_oidj  s    
r~   )N)5
__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   r(   r+   Z(EllipticCurvePrivateKeyWithSerializationregisterrU   ZECPrivateKeyr-   Z'EllipticCurvePublicKeyWithSerializationZECPublicKeyr8   rH   r   r   r   r   r   r   rh   rj   rl   rn   __annotations__ro   Zgenerate_private_keyry   r,   r   r   r   r{   r~   r   r   r   r   <module>   s    FK!          