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__/DSA.cpython-36.opt-1.pyc
3

YݧZ�7�@s�ddlmZmZddlmZmZmZejr>ddlm	Z	m
Z
mZGdd�de�Z
eje
�Gdd�de�ZGdd	�d	e�Zejfd
d�Zdd
�Zejfdd�Zejfdd�Zejfdd�Zejfdd�Zdd�Zejfdd�Zejfdd�ZdS)�)�absolute_import�print_function)�BIO�m2�util)�AnyStr�Callable�Tuplec@seZdZdS)�DSAErrorN)�__name__�
__module__�__qualname__�rr�/usr/lib64/python3.6/DSA.pyr
sr
c@s�eZdZdZejZd)dd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdejfdd�Zdejfdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(S)*�DSAa#
    This class is a context supporting DSA key and parameter
    values, signing and verifying.

    Simple example::

        from M2Crypto import EVP, DSA, util

        message = 'Kilroy was here!'
        md = EVP.MessageDigest('sha1')
        md.update(message)
        digest = md.final()

        dsa = DSA.gen_params(1024)
        dsa.gen_key()
        r, s = dsa.sign(digest)
        good = dsa.verify(digest, r, s)
        if good:
            print('  ** success **')
        else:
            print('  ** verification failed **')
    rcCs||_||_dS)z�
        Use one of the factory functions to create an instance.
        :param dsa: binary representation of OpenSSL DSA type
        N)�dsa�_pyfree)�selfrrrrr�__init__2szDSA.__init__cCst|dd�r|j|j�dS)Nrr)�getattr�m2_dsa_freer)rrrr�__del__<szDSA.__del__cCstj|j�S)zV
        Return the key length.

        :return:  the DSA key length in bits
        )rZ
dsa_keylenr)rrrr�__len__AszDSA.__len__cCs*|dkr"ttd|f�}||j�St�dS)	z�
        Return specified DSA parameters and key values.

        :param name: name of variable to be returned.  Must be
                     one of 'p', 'q', 'g', 'pub', 'priv'.
        :return:     value of specified variable (a "byte string")
        �p�q�g�pub�privz
dsa_get_%sN)rrrrr)rrr�AttributeError)r�name�methodrrr�__getattr__Ks	
zDSA.__getattr__cCs2|dkrtd��n|d	kr$td��n
||j|<dS)
Nrrrzset (p, q, g) via set_params()rrz"generate (pub, priv) via gen_key())rrr)rr)r
�__dict__)rr�valuerrr�__setattr__[s


zDSA.__setattr__cCstj|j|||�dS)a�
        Set new parameters.

        :param p: MPI binary representation ... format that consists of
                  the number's length in bytes represented as a 4-byte
                  big-endian number, and the number itself in big-endian
                  format, where the most significant bit signals
                  a negative number (the representation of numbers with
                  the MSB set is prefixed with null byte).
        :param q: ditto
        :param g: ditto

        @warning: This does not change the private key, so it may be
                  unsafe to use this method. It is better to use
                  gen_params function to create a new DSA object.
        N)r�dsa_set_pqgr)rrrrrrr�
set_paramsdszDSA.set_paramscCstj|j�dS)z&
        Generate a key pair.
        N)rZdsa_gen_keyr)rrrr�gen_keyxszDSA.gen_keyc
Cs.tj|d��}tj|j|j��}WdQRX|S)z�
        Save the DSA parameters to a file.

        :param filename: Save the DSA parameters to this file.
        :return:         1 (true) if successful
        �wbN)r�openfiler�dsa_write_params_bior�_ptr)r�filename�bio�retrrr�save_params�szDSA.save_paramscCstj|j|j��S)z�
        Save DSA parameters to a BIO object.

        :param bio: Save DSA parameters to this object.
        :return:    1 (true) if successful
        )rr*rr+)rr-rrr�save_params_bio�szDSA.save_params_bioZaes_128_cbccCs*tj|d��}|j|||�}WdQRX|S)a
        Save the DSA key pair to a file.

        :param filename: Save the DSA key pair to this file.
        :param cipher:   name of symmetric key algorithm and mode
                         to encrypt the private key.
        :return:         1 (true) if successful
        r(N)rr)�save_key_bio)rr,�cipher�callbackr-r.rrr�save_key�szDSA.save_keycCs^|dkrtj|j|j�|�Stt|d�}|dkr>td|��n|�}tj|j|j�||�SdS)a
        Save DSA key pair to a BIO object.

        :param bio:    Save DSA parameters to this object.
        :param cipher: name of symmetric key algorithm and mode
                       to encrypt the private key.
        :return:       1 (true) if successful
        Nzno such cipher: %s)rZdsa_write_key_bio_no_cipherrr+rr
Zdsa_write_key_bio)rr-r2r3Zciphrrrr1�szDSA.save_key_bioc	Cs&tj|d��}|j|�}WdQRX|S)z�
        Save the DSA public key (with parameters) to a file.

        :param filename: Save DSA public key (with parameters)
                         to this file.
        :return:         1 (true) if successful
        r(N)rr)�save_pub_key_bio)rr,r-r.rrr�save_pub_key�s	zDSA.save_pub_keycCstj|j|j��S)z�
        Save DSA public key (with parameters) to a BIO object.

        :param bio: Save DSA public key (with parameters)
                    to this object.
        :return:  1 (true) if successful
        )rZdsa_write_pub_key_biorr+)rr-rrrr5�s	zDSA.save_pub_key_biocCstj|j|�S)a
        Sign the digest.

        :param digest: SHA-1 hash of message (same as output
                       from MessageDigest, a "byte string")
        :return:       DSA signature, a tuple of two values, r and s,
                       both "byte strings".
        )rZdsa_signr)r�digestrrr�sign�szDSA.signcCstj|j|||�S)a�
        Verify a newly calculated digest against the signature
        values r and s.

        :param digest: SHA-1 hash of message (same as output
                       from MessageDigest, a "byte string")
        :param r:      r value of the signature, a "byte string"
        :param s:      s value of the signature, a "byte string"
        :return:       1 (true) if verify succeeded, 0 if failed
        )rZ
dsa_verifyr)rr7�r�srrr�verify�s
z
DSA.verifycCstj|j|�S)N)rZ
dsa_sign_asn1r)rr7rrr�	sign_asn1�sz
DSA.sign_asn1cCstj|j||�S)N)rZdsa_verify_asn1r)rr7Zblobrrr�verify_asn1�szDSA.verify_asn1cCstj|j�S)z}
        Check to be sure the DSA object has a valid private key.

        :return:  1 (true) if a valid private key
        )rZ
dsa_check_keyr)rrrr�	check_key�sz
DSA.check_keyN)r)rrr
�__doc__rZdsa_freerrrrr!r$r&r'r/r0r�passphrase_callbackr4r1r6r5r8r;r<r=r>rrrrrs,


	


rc@s0eZdZdZdd�ZeZdd�ZejZ	ej
ZdS)�DSA_pubz�
    This class is a DSA context that only supports a public key
    and verification.  It does NOT support a private key or
    signing.

    cGstd��dS)Nz!DSA_pub object has no private key)r
)r�argvrrrr8
szDSA_pub.signcCstj|j�S)z:
        :return: does DSA_pub contain a pub key?
        )rZdsa_check_pub_keyr)rrrrr>szDSA_pub.check_keyN)rrr
r?r8r<r>rr6r4r5r1rrrrrAsrAcCstj||�}t|d�S)a�
    Factory function that generates DSA parameters and
    instantiates a DSA object from the output.

    :param bits: The length of the prime to be generated. If
                 'bits' < 512, it is set to 512.
    :param callback: A Python callback object that will be
                 invoked during parameter generation; it usual
                 purpose is to provide visual feedback.
    :return:  instance of DSA.
    �)rZdsa_generate_parametersr)�bitsr3rrrr�
gen_params"s
rEcCs"tj�}tj||||�t|d�S)z�
    Factory function that instantiates a DSA object with DSA
    parameters.

    :param p: value of p, a "byte string"
    :param q: value of q, a "byte string"
    :param g: value of g, a "byte string"
    :return:  instance of DSA.
    rC)r�dsa_newr%r)rrrrrrrr&3sr&c
Cs$tj|��}t||�}WdQRX|S)a�
    Factory function that instantiates a DSA object with DSA
    parameters from a file.

    :param file:     Names the file (a path) that contains the PEM
                     representation of the DSA parameters.
    :param callback: A Python callback object that will be
                     invoked if the DSA parameters file is
                     passphrase-protected.
    :return:         instance of DSA.
    N)rr)�load_params_bio)�filer3r-r.rrr�load_paramsCs
rIcCstj|j�|�}t|d�S)a�
    Factory function that instantiates a DSA object with DSA
    parameters from a M2Crypto.BIO object.

    :param bio:      Contains the PEM representation of the DSA
                     parameters.
    :param callback: A Python callback object that will be
                     invoked if the DSA parameters file is
                     passphrase-protected.
    :return:         instance of DSA.
    rC)rZdsa_read_paramsr+r)r-r3rrrrrGVs
rGc
Cs$tj|��}t||�}WdQRX|S)a�
    Factory function that instantiates a DSA object from a
    PEM encoded DSA key pair.

    :param file:     Names the file (a path) that contains the PEM
                     representation of the DSA key pair.
    :param callback: A Python callback object that will be
                     invoked if the DSA key pair is
                     passphrase-protected.
    :return:         instance of DSA.
    N)rr)�load_key_bio)rHr3r-r.rrr�load_keygs
rKcCstj|j�|�}t|d�S)a~
    Factory function that instantiates a DSA object from a
    PEM encoded DSA key pair.

    :param bio:      Contains the PEM representation of the DSA
                     key pair.
    :param callback: A Python callback object that will be
                     invoked if the DSA key pair is
                     passphrase-protected.
    :return:         instance of DSA.
    rC)rZdsa_read_keyr+r)r-r3rrrrrJzs
rJcCs.tj�}tj||||�tj||�t|d�S)a
    Factory function that instantiates a DSA_pub object using
    the parameters and public key specified.

    :param p: value of p
    :param q: value of q
    :param g: value of g
    :param pub: value of the public key
    :return:  instance of DSA_pub.
    rC)rrFr%Zdsa_set_pubrA)rrrrrrrr�pub_key_from_params�srLc
Cs$tj|��}t||�}WdQRX|S)a
    Factory function that instantiates a DSA_pub object using
    a DSA public key contained in PEM file.  The PEM file
    must contain the parameters in addition to the public key.

    :param file:     Names the file (a path) that contains the PEM
                     representation of the DSA public key.
    :param callback: A Python callback object that will be
                     invoked should the DSA public key be
                     passphrase-protected.
    :return:         instance of DSA_pub.
    N)rr)�load_pub_key_bio)rHr3r-r.rrr�load_pub_key�srNcCstj|j�|�}t|d�S)a�
    Factory function that instantiates a DSA_pub object using
    a DSA public key contained in PEM format.  The PEM
    must contain the parameters in addition to the public key.

    :param bio:      Contains the PEM representation of the DSA
                     public key (with params).
    :param callback: A Python callback object that will be
                     invoked should the DSA public key be
                     passphrase-protected.
    :return:         instance of DSA_pub.
    rC)rZdsa_read_pub_keyr+rA)r-r3ZdsapubrrrrM�srMN)Z
__future__rrZM2CryptorrrZpy27plusZtypingrrr	�	Exceptionr
Zdsa_init�objectrrAZgenparam_callbackrEr&r@rIrGrKrJrLrNrMrrrr�<module>s"
n