a
    còf¼(  ã                &   @  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!   úi/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/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v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y$   tdƒ‚Y n0 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¬   :?ë! ýí