HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib64/python3.6/site-packages/M2Crypto/__pycache__/RSA.cpython-36.pyc
3

6�\�8�@sddlmZddlZddlmZmZmZmZejrZddl	m
Z
mZmZm
Z
mZmZmZmZGdd�de�Zeje�ejZejZejZejZGdd�de�ZGd	d
�d
e�Zdd�Zejfd
d�Zefdd�Zej fdd�Z!ej fdd�Z"ej fdd�Z#dd�Z$dd�Z%dd�Z&dS)�)�absolute_importN)�BIO�Err�m2�util)�Any�AnyStr�Callable�Dict�List�IO�Optional�Tuplec@seZdZdS)�RSAErrorN)�__name__�
__module__�__qualname__�rr�/usr/lib64/python3.6/RSA.pyrsrc@s�eZdZdZejZd1dd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdejfdd�Zdejfdd�ZeZdejfdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd2d(d)�Zd3d*d+�Zd4d,d-�Zd5d.d/�Zd0S)6�RSAz
    RSA Key Pair.
    rcCs"tj|�std��||_||_dS)zG
        :param rsa: binary representation of OpenSSL RSA type
        z'rsa' type errorN)rZrsa_type_check�AssertionError�rsa�_pyfree)�selfrrrrr�__init__ szRSA.__init__cCst|dd�r|j|j�dS)Nrr)�getattr�m2_rsa_freer)rrrr�__del__)szRSA.__del__cCsttj|j�d>�S)N�)�intrZrsa_sizer)rrrr�__len__.szRSA.__len__cCs0|dkrtj|j�S|dkr(tj|j�St�dS)N�e�n)r�	rsa_get_er�	rsa_get_n�AttributeError)r�namerrr�__getattr__2s
zRSA.__getattr__cCs(|j�std��tj|j�tj|j�fS)Nzkey is not initialised)�	check_keyrrr#rr$)rrrr�pub;szRSA.pubcCs |j�std��tj|j||�S)Nzkey is not initialised)r(rrZrsa_public_encryptr)r�data�paddingrrr�public_encrypt@szRSA.public_encryptcCs |j�std��tj|j||�S)Nzkey is not initialised)r(rrZrsa_public_decryptr)rr*r+rrr�public_decryptEszRSA.public_decryptcCs |j�std��tj|j||�S)Nzkey is not initialised)r(rrZrsa_private_encryptr)rr*r+rrr�private_encryptJszRSA.private_encryptcCs |j�std��tj|j||�S)Nzkey is not initialised)r(rrZrsa_private_decryptr)rr*r+rrr�private_decryptOszRSA.private_decryptZaes_128_cbccCs^|dkrtj|j|j�|�Stt|d�}|dkr>td|��n|�}tj|j|j�||�SdS)aC
        Save the key pair to an M2Crypto.BIO.BIO object in PEM format.

        :param bio: M2Crypto.BIO.BIO object to save key to.

        :param cipher: Symmetric cipher to protect the key. The default
                       cipher is 'aes_128_cbc'. If cipher is None, then
                       the key is saved in the clear.

        :param callback: A Python callable object that is invoked
                         to acquire a passphrase with which to protect
                         the key.  The default is
                         util.passphrase_callback.
        Nznot such cipher %s)rZrsa_write_key_no_cipherr�_ptrrrZ
rsa_write_key)r�bio�cipher�callbackZciphrrr�save_key_bioTszRSA.save_key_biocCs&tj|d��}|j|||�SQRXdS)a%
        Save the key pair to a file in PEM format.

        :param file: Name of file to save key to.

        :param cipher: Symmetric cipher to protect the key. The default
                       cipher is 'aes_128_cbc'. If cipher is None, then
                       the key is saved in the clear.

        :param callback: A Python callable object that is invoked
                         to acquire a passphrase with which to protect
                         the key.  The default is
                         util.passphrase_callback.
        �wbN)r�openfiler4)r�filer2r3r1rrr�save_keyoszRSA.save_keycCstj�}|j|||�|j�S)zB
        Returns the key(pair) as a string in PEM format.
        )r�MemoryBufferr4�read)rr2r3r1rrr�as_pem�sz
RSA.as_pemcCstj|j|j��S)z�
        Save the key pair to an M2Crypto.BIO.BIO object in DER format.

        :param bio: M2Crypto.BIO.BIO object to save key to.
        )rZrsa_write_key_derrr0)rr1rrr�save_key_der_bio�szRSA.save_key_der_bioc	Cs"tj|d��}|j|�SQRXdS)zj
        Save the key pair to a file in DER format.

        :param file: Filename to save key to
        r5N)rr6r<)rr7r1rrr�save_key_der�szRSA.save_key_dercCstj|j|j��S)z�
        Save the public key to an M2Crypto.BIO.BIO object in PEM format.

        :param bio: M2Crypto.BIO.BIO object to save key to.
        )r�rsa_write_pub_keyrr0)rr1rrr�save_pub_key_bio�szRSA.save_pub_key_bioc
Cs*tj|d��}tj|j|j��SQRXdS)zq
        Save the public key to a file in PEM format.

        :param file: Name of file to save key to.
        r5N)rr6rr>rr0)rr7r1rrr�save_pub_key�szRSA.save_pub_keycCstj|j�S)a�
        Validate RSA keys.

        It checks that p and q are in fact prime, and that n = p*q.

        :return: returns 1 if rsa is a valid RSA key, and 0 otherwise.
                 -1 is returned if an error occurs while checking the key.
                 If the key is invalid or an error occurred, the reason
                 code can be obtained using ERR_get_error(3).
        )rZ
rsa_check_keyr)rrrrr(�sz
RSA.check_key�sha1�cCsBtt|d�}|dkr td|��tj|j||�|�}|j|tj�S)a�
        Signs a digest with the private key using RSASSA-PSS

        :param digest: A digest created by using the digest method

        :param salt_length: The length of the salt to use

        :param algo: The hash algorithm to use
                     Legal values like 'sha1','sha224', 'sha256',
                     'ripemd160', and 'md5'.

        :return: a string which is the signature
        Nznot such hash algorithm %s)rrrZrsa_padding_add_pkcs1_pssrr.�
no_padding)r�digest�algo�salt_length�hash�	signaturerrr�sign_rsassa_pss�s
zRSA.sign_rsassa_psscCsDtt|d�}|dkr td|��|j|tj�}tj|j|||�|�S)a�
        Verifies the signature RSASSA-PSS

        :param data: Data that has been signed

        :param signature: The signature signed with RSASSA-PSS

        :param salt_length: The length of the salt that was used

        :param algo: The hash algorithm to use
                     Legal values are for example 'sha1','sha224',
                     'sha256', 'ripemd160', and 'md5'.

        :return: 1 or 0, depending on whether the signature was
                 verified or not.
        Nznot such hash algorithm %s)rrrr-rCZrsa_verify_pkcs1_pssr)rr*rHrErFrGZplain_signaturerrr�verify_rsassa_pss�s
zRSA.verify_rsassa_psscCs2ttd|d�}|dkr"td|��tj|j||�S)aT
        Signs a digest with the private key

        :param digest: A digest created by using the digest method

        :param algo: The method that created the digest.
                     Legal values like 'sha1','sha224', 'sha256',
                     'ripemd160', and 'md5'.

        :return: a string which is the signature
        �NID_Nzunknown algorithm)rr�
ValueErrorZrsa_signr)rrDrE�digest_typerrr�sign�s

zRSA.signcCs4ttd|d�}|dkr"td|��tj|j|||�S)a�
        Verifies the signature with the public key

        :param data: Data that has been signed

        :param signature: The signature signed with the private key

        :param algo: The method use to create digest from the data
                     before it was signed.  Legal values like
                     'sha1','sha224', 'sha256', 'ripemd160', and 'md5'.

        :return: 1 or 0, depending on whether the signature was
                 verified or not.
        rKNzunknown algorithm)rrrLZ
rsa_verifyr)rr*rHrErMrrr�verifys
z
RSA.verifyN)r)rArB)rArB)rA)rA)rrr�__doc__rZrsa_freerrrr r'r)r,r-r.r/r�passphrase_callbackr4r8Zsave_pemr;r<r=r?r@r(rIrJrNrOrrrrrs4
				
	



rc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�RSA_pubz0
    Object interface to an RSA public key.
    cCs |dkrtd��n
||j|<dS)Nr!r"z0use factory function new_pub_key() to set (e, n))r!r")r�__dict__)rr&�valuerrr�__setattr__%s
zRSA_pub.__setattr__cGstd��dS)Nz!RSA_pub object has no private key)r)r�argvrrrr.,szRSA_pub.private_encryptcGstd��dS)Nz!RSA_pub object has no private key)r)rrVrrrr/0szRSA_pub.private_decryptcOs
|j|�S)z*
        Save public key to file.
        )r@)rr7�args�kwrrrr84szRSA_pub.save_keycOs
|j|�S)z)
        Save public key to BIO.
        )r?)rr1rWrXrrrr4;szRSA_pub.save_key_biocCstj|j�S)N)rZrsa_check_pub_keyr)rrrrr(FszRSA_pub.check_keyN)
rrrrPrUr.r/r8r4r(rrrrrRsrRcCsttj���dS)N)rrZget_error_messagerrrr�	rsa_errorKsrYcCs&ddddg}|j||�|j�dS)z)
    Default callback for gen_key().
    �.�+�*�
N)�write�flush)�pr"�outZchrrr�keygen_callbackPsrbcCsttj|||�d�S)a�
    Generate an RSA key pair.

    :param bits: Key length, in bits.

    :param e: The RSA public exponent.

    :param callback: A Python callable object that is invoked
                     during key generation; its usual purpose is to
                     provide visual feedback. The default callback is
                     keygen_callback.

    :return: M2Crypto.RSA.RSA object.
    �)rrZrsa_generate_key)�bitsr!r3rrr�gen_keyZsrec
Cs tj|��}t||�SQRXdS)aa
    Load an RSA key pair from file.

    :param file: Name of file containing RSA public key in PEM format.

    :param callback: A Python callable object that is invoked
                     to acquire a passphrase with which to unlock the
                     key.  The default is util.passphrase_callback.

    :return: M2Crypto.RSA.RSA object.
    N)rr6�load_key_bio)r7r3r1rrr�load_keyms
rgcCs(tj|j�|�}|dkrt�t|d�S)a�
    Load an RSA key pair from an M2Crypto.BIO.BIO object.

    :param bio: M2Crypto.BIO.BIO object containing RSA key pair in PEM
                format.

    :param callback: A Python callable object that is invoked
                     to acquire a passphrase with which to unlock the
                     key.  The default is util.passphrase_callback.

    :return: M2Crypto.RSA.RSA object.
    Nrc)rZrsa_read_keyr0rYr)r1r3rrrrrf~srfcCstj|�}t||�S)a^
    Load an RSA key pair from a string.

    :param string: String containing RSA key pair in PEM format.

    :param callback: A Python callable object that is invoked
                     to acquire a passphrase with which to unlock the
                     key. The default is util.passphrase_callback.

    :return: M2Crypto.RSA.RSA object.
    )rr9rf)�stringr3r1rrr�load_key_string�s
ric	Cstj|��
}t|�SQRXdS)z�
    Load an RSA public key from file.

    :param file: Name of file containing RSA public key in PEM format.

    :return: M2Crypto.RSA.RSA_pub object.
    N)rr6�load_pub_key_bio)r7r1rrr�load_pub_key�s	rkcCs&tj|j��}|dkrt�t|d�S)z�
    Load an RSA public key from an M2Crypto.BIO.BIO object.

    :param bio: M2Crypto.BIO.BIO object containing RSA public key in PEM
                format.

    :return: M2Crypto.RSA.RSA_pub object.
    Nrc)rZrsa_read_pub_keyr0rYrR)r1rrrrrj�s
rjcCs(|\}}tj�}tj|||�t|d�S)a�
    Instantiate an RSA_pub object from an (e, n) tuple.

    :param e: The RSA public exponent; it is a string in OpenSSL's MPINT
              format - 4-byte big-endian bit-count followed by the
              appropriate number of bits.

    :param n: The RSA composite of primes; it is a string in OpenSSL's
              MPINT format - 4-byte big-endian bit-count followed by the
              appropriate number of bits.

    :return: M2Crypto.RSA.RSA_pub object.
    rc)rZrsa_newZ
rsa_set_enrR)Ze_nr!r"rrrr�new_pub_key�srl)'Z
__future__r�sysZM2CryptorrrrZpy27plusZtypingrrr	r
rrr
r�	ExceptionrZrsa_initrCZ
pkcs1_paddingZsslv23_paddingZpkcs1_oaep_padding�objectrrRrY�stdoutrbrerQrgrfrirkrjrlrrrr�<module>s.(
,