o
    j,!                     @  s   d dl mZ d dlZd dlZd dlZd dlmZmZ d dlm	Z
 d dlmZmZ d dlmZ d dlm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	d-d.ddZd/ddZd0ddZd1ddZd2d!d"Z d3d#d$Z!d4d%d&Z"d'Z#d5d+d,Z$dS )6    )annotationsN)gcdlcm)openssl)_serializationhashes)AsymmetricPadding)utilsc                   @  s   e Zd Zejd%ddZeejd&d	d
Zejd'ddZejd(ddZ	ejd)ddZ
ejd*ddZejd+ddZejd,d"d#Zd$S )-RSAPrivateKey
ciphertextbytespaddingr   returnc                 C     dS )z3
        Decrypts the provided ciphertext.
        N )selfr   r   r   r   s/var/www/html/fyndo/pharma/fyndo/venv/lib/python3.10/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.pydecrypt       zRSAPrivateKey.decryptintc                 C  r   z7
        The bit length of the public modulus.
        Nr   r   r   r   r   key_size   r   zRSAPrivateKey.key_sizeRSAPublicKeyc                 C  r   )zD
        The RSAPublicKey associated with this private key.
        Nr   r   r   r   r   
public_key    r   zRSAPrivateKey.public_keydata	algorithmEasym_utils.Prehashed | hashes.HashAlgorithm | asym_utils.NoDigestInfoc                 C  r   )z!
        Signs the data.
        Nr   )r   r   r   r   r   r   r   sign&   r   zRSAPrivateKey.signRSAPrivateNumbersc                 C  r   )z/
        Returns an RSAPrivateNumbers.
        Nr   r   r   r   r   private_numbers3   r   zRSAPrivateKey.private_numbersencoding_serialization.Encodingformat_serialization.PrivateFormatencryption_algorithm)_serialization.KeySerializationEncryptionc                 C  r   z6
        Returns the key serialized as bytes.
        Nr   )r   r!   r#   r%   r   r   r   private_bytes9   r   zRSAPrivateKey.private_bytesc                 C  r   z!
        Returns a copy.
        Nr   r   r   r   r   __copy__D   r   zRSAPrivateKey.__copy__memodictc                 C  r   z&
        Returns a deep copy.
        Nr   r   r+   r   r   r   __deepcopy__J   r   zRSAPrivateKey.__deepcopy__N)r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   )r!   r"   r#   r$   r%   r&   r   r   )r   r
   )r+   r,   r   r
   )__name__
__module____qualname__abcabstractmethodr   propertyr   r   r   r    r(   r*   r/   r   r   r   r   r
      s$    
r
   )	metaclassc                   @  s   e Zd Zejd*ddZeejd+d	d
Zejd,ddZejd-ddZ	ejd.ddZ
ejd/ddZejd0d!d"Zejd1d#d$Zejd2d'd(Zd)S )3r   	plaintextr   r   r   r   c                 C  r   )z/
        Encrypts the given plaintext.
        Nr   )r   r9   r   r   r   r   encryptV   r   zRSAPublicKey.encryptr   c                 C  r   r   r   r   r   r   r   r   \   r   zRSAPublicKey.key_sizeRSAPublicNumbersc                 C  r   )z-
        Returns an RSAPublicNumbers
        Nr   r   r   r   r   public_numbersc   r   zRSAPublicKey.public_numbersr!   r"   r#   _serialization.PublicFormatc                 C  r   r'   r   )r   r!   r#   r   r   r   public_bytesi   r   zRSAPublicKey.public_bytes	signaturer   r   +asym_utils.Prehashed | hashes.HashAlgorithmNonec                 C  r   )z5
        Verifies the signature of the data.
        Nr   )r   r?   r   r   r   r   r   r   verifys   r   zRSAPublicKey.verify5hashes.HashAlgorithm | asym_utils.NoDigestInfo | Nonec                 C  r   )z@
        Recovers the original data from the signature.
        Nr   )r   r?   r   r   r   r   r   recover_data_from_signature   r   z(RSAPublicKey.recover_data_from_signatureotherobjectboolc                 C  r   )z"
        Checks equality.
        Nr   )r   rE   r   r   r   __eq__   r   zRSAPublicKey.__eq__c                 C  r   r)   r   r   r   r   r   r*      r   zRSAPublicKey.__copy__r+   r,   c                 C  r   r-   r   r.   r   r   r   r/      r   zRSAPublicKey.__deepcopy__N)r9   r   r   r   r   r   r0   )r   r;   )r!   r"   r#   r=   r   r   )
r?   r   r   r   r   r   r   r@   r   rA   )r?   r   r   r   r   rC   r   r   )rE   rF   r   rG   r1   )r+   r,   r   r   )r2   r3   r4   r5   r6   r:   r7   r   r<   r>   rB   rD   rH   r*   r/   r   r   r   r   r   U   s(    	
r   public_exponentr   r   backend
typing.Anyr   c                 C  s   t | | tj| |S N)_verify_rsa_parametersrust_opensslrsagenerate_private_key)rI   r   rJ   r   r   r   rP      s   
rP   rA   c                 C  s$   | dvrt d|dk rt dd S )N)   i  zopublic_exponent must be either 3 (for legacy compatibility) or 65537. Almost everyone should choose 65537 here!i   z$key_size must be at least 1024-bits.
ValueError)rI   r   r   r   r   rM      s   rM   emc           	      C  sX   d\}}| |}}|dkr(t ||\}}|||  }||||f\}}}}|dks|| S )zO
    Modular Multiplicative Inverse. Returns x such that: (x*e) mod m == 1
    )   r   r   )divmod)	rT   rU   x1x2abqrxnr   r   r   _modinv   s   
r_   pr\   c                 C  s"   | dks|dkrt dt|| S )zF
    Compute the CRT (q ** -1) % p value from RSA primes p and q.
    rV   Values can't be <= 1)rS   r_   )r`   r\   r   r   r   rsa_crt_iqmp   s   
rb   private_exponentc                 C  $   | dks|dkrt d| |d  S )zg
    Compute the CRT private_exponent % (p - 1) value from the RSA
    private_exponent (d) and p.
    rV   ra   rR   )rc   r`   r   r   r   rsa_crt_dmp1      re   c                 C  rd   )zg
    Compute the CRT private_exponent % (q - 1) value from the RSA
    private_exponent (d) and q.
    rV   ra   rR   )rc   r\   r   r   r   rsa_crt_dmq1   rf   rg   c                 C  s8   | dks|dks|dkrt dt| t|d |d S )z
    Compute the RSA private_exponent (d) given the public exponent (e)
    and the RSA primes p and q.

    This uses the Carmichael totient function to generate the
    smallest possible working value of the private exponent.
    rV   ra   )rS   r_   r   )rT   r`   r\   r   r   r   rsa_recover_private_exponent   s   rh   i  ndtuple[int, int]c                 C  s>  |dks|dkrt ddtd|| | krt d|| d }|}|d dkr2|d }|d dks(d}d}|s~|tk r~td| d }|d7 }|}||k rxt||| }	|	dkrp|	| d krpt|	d| dkrpt|	d | }
d}n|d9 }||k sN|s~|tk s<|st d	t| |
\}}|dksJ t|
|fdd
\}
}|
|fS )z
    Compute factors p and q from the private exponent d. We assume that n has
    no more than two factors. This function is adapted from code in PyCrypto.
    rV   zd, e can't be <= 1   zn, d, e don't match   r   FTz2Unable to compute factors p and q from exponent d.)reverse)rS   pow_MAX_RECOVERY_ATTEMPTSrandomrandintr   rW   sorted)ri   rT   rj   ktottspottedtriesrZ   kcandr`   r\   r]   r   r   r   rsa_recover_prime_factors   s<   $rz   rL   )rI   r   r   r   rJ   rK   r   r
   )rI   r   r   r   r   rA   )rT   r   rU   r   r   r   )r`   r   r\   r   r   r   )rc   r   r`   r   r   r   )rc   r   r\   r   r   r   )rT   r   r`   r   r\   r   r   r   )ri   r   rT   r   rj   r   r   rk   )%
__future__r   r5   rq   typingmathr   r   "cryptography.hazmat.bindings._rustr   rN   cryptography.hazmat.primitivesr   r   *cryptography.hazmat.primitives._asymmetricr   )cryptography.hazmat.primitives.asymmetricr	   
asym_utilsABCMetar
   RSAPrivateKeyWithSerializationregisterrO   r   RSAPublicKeyWithSerializationr   r;   rP   rM   r_   rb   re   rg   rh   rp   rz   r   r   r   r   <module>   s6   ?H
	


	



