HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.52.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 15 06:39:08 EDT 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //var/opt/nydus/ops/oscrypto/__pycache__/asymmetric.cpython-39.pyc
a

�,�hV3�@s(ddlmZmZmZmZddlZddlZddlmZddl	m
Z
mZm
Z
mZmZmZmZmZmZddlmZddlmZddlmZmZdd	lmZmZdd
lmZddl m!Z!e�Z"e"dk�rdd
l#mZm$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7n�e"dk�s2e"dk�r�dd
l8mZm$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7n\dd
l9mZm$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7gd�Z:ddd�Z;ddd�Z<ddd�Z=d dd�Z>dd�Z?dS)!�)�unicode_literals�division�absolute_import�print_functionN�)�backend)	�armor�Certificate�DHParameters�EncryptedPrivateKeyInfo�Null�OrderedDict�
Pbkdf2Salt�PrivateKeyInfo�
PublicKeyInfo)�_unwrap_private_key_info)�pretty_message)�	type_name�str_cls)�pbkdf2�pbkdf2_iteration_calculator)�aes_cbc_pkcs7_encrypt)�
rand_bytes�mac)r	�dsa_sign�
dsa_verify�
ecdsa_sign�ecdsa_verify�
generate_pair�generate_dh_parameters�load_certificate�load_pkcs12�load_private_key�load_public_key�
PrivateKey�	PublicKey�rsa_pkcs1v15_sign�rsa_pkcs1v15_verify�rsa_pss_sign�rsa_pss_verify�rsa_pkcs1v15_encrypt�rsa_pkcs1v15_decrypt�rsa_oaep_encrypt�rsa_oaep_decrypt�winZ	winlegacy)r	rr�dump_certificate�dump_dh_parameters�dump_openssl_private_key�dump_private_key�dump_public_keyrrrrr r!r"r#r$r%r-r,r+r*r&r'r(r)�pemcCs\|tddg�vr"ttdt|����t|t�s>ttdt|����|��}|dkrXt	d|�}|S)a
    Serializes an asn1crypto.algos.DHParameters object into a byte string

    :param dh_parameters:
        An asn1crypto.algos.DHParameters object

    :param encoding:
        A unicode string of "pem" or "der"

    :return:
        A byte string of the encoded DH parameters
    r4�der�F
            encoding must be one of "pem", "der", not %s
            zp
            dh_parameters must be an instance of asn1crypto.algos.DHParameters,
            not %s
            z
DH PARAMETERS)
�set�
ValueErrorr�repr�
isinstancer
�	TypeErrorr�dumpr)Z
dh_parameters�encoding�output�r?�D/opt/nydus/tmp/pip-target-wkfpz8uv/lib/python/oscrypto/asymmetric.pyr0�s�
�
r0cCst|tddg�vr"ttdt|����t|t�}t|t�sL|sLttdt|����|rV|j	}|�
�}|dkrptd|�}|S)a#
    Serializes a public key object into a byte string

    :param public_key:
        An oscrypto.asymmetric.PublicKey or asn1crypto.keys.PublicKeyInfo object

    :param encoding:
        A unicode string of "pem" or "der"

    :return:
        A byte string of the encoded public key
    r4r5r6z�
            public_key must be an instance of oscrypto.asymmetric.PublicKey or
            asn1crypto.keys.PublicKeyInfo, not %s
            z
PUBLIC KEY)r7r8rr9r:r%rr;r�asn1r<r)Z
public_keyr=�is_oscryptor>r?r?r@r3�s"�
�
r3cCst|tddg�vr"ttdt|����t|t�}t|t�sL|sLttdt|����|rV|j	}|�
�}|dkrptd|�}|S)a&
    Serializes a certificate object into a byte string

    :param certificate:
        An oscrypto.asymmetric.Certificate or asn1crypto.x509.Certificate object

    :param encoding:
        A unicode string of "pem" or "der"

    :return:
        A byte string of the encoded certificate
    r4r5r6z�
            certificate must be an instance of oscrypto.asymmetric.Certificate
            or asn1crypto.x509.Certificate, not %s
            �CERTIFICATE)r7r8rr9r:r	�Asn1Certificater;rrAr<r)Zcertificater=rBr>r?r?r@r/�s"�
�
r/��cCsh|tddg�vr"ttdt|����|durZt|t�sFttdt|����|dkrZttd���t|t�}t|t	�s�|s�ttdt|����|r�|j
}|��}|du�r<d	}d
}d}t|�}	t
|||dd
�}
|
dkr�d}
|�d�}t|||	|
|�}t||d�\}
}tddtd|	d�|
|t�d�d�d�||
d�d�d�|d����}|dk�rd|du�rVd}nd}t||�}|S)aM
    Serializes a private key object into a byte string of the PKCS#8 format

    :param private_key:
        An oscrypto.asymmetric.PrivateKey or asn1crypto.keys.PrivateKeyInfo
        object

    :param passphrase:
        A unicode string of the passphrase to encrypt the private key with.
        A passphrase of None will result in no encryption. A blank string will
        result in a ValueError to help ensure that the lack of passphrase is
        intentional.

    :param encoding:
        A unicode string of "pem" or "der"

    :param target_ms:
        Use PBKDF2 with the number of iterations that takes about this many
        milliseconds on the current machine.

    :raises:
        ValueError - when a blank string is provided for the passphrase

    :return:
        A byte string of the encoded and encrypted public key
    r4r5r6N�M
                passphrase must be a unicode string, not %s
                ��x
                passphrase may not be a blank string - pass None to disable
                encryption
                z�
            private_key must be an instance of oscrypto.asymmetric.PrivateKey
            or asn1crypto.keys.PrivateKeyInfo, not %s
            Z
aes256_cbc� �sha256T)�	target_ms�quieti'�utf-8Zpbes2rZ	specified)�name�value)�	algorithm�
parameters)ZsaltZiteration_countZprf)Zkey_derivation_funcZencryption_scheme)Zencryption_algorithmZencrypted_datazPRIVATE KEYzENCRYPTED PRIVATE KEY)r7r8rr9r:rr;rr$rrAr<rr�encoderrrrrr)�private_key�
passphraser=rKrBr>�cipher�
key_lengthZkdf_hmacZkdf_saltZ
iterations�passphrase_bytes�key�ivZ
ciphertext�object_typer?r?r@r2�sz�
��
�

��������


r2c
Csl|dur8t|t�s$ttdt|����|dkr8ttd���t|t�}t|t�sb|sbttdt|����|rl|j}t	|��
�}d}|du�r*td�}t�}d|d<d	t
�|��d
�|d<d}|�d�}t�||d
d����}|t|�k�r|t�|||d
d����7}q�|d
|�}t|||�\}}|jdk�r<d}	n"|jdk�rNd}	n|jdk�r^d}	t|	||d�S)a 
    Serializes a private key object into a byte string of the PEM formats used
    by OpenSSL. The format chosen will depend on the type of private key - RSA,
    DSA or EC.

    Do not use this method unless you really must interact with a system that
    does not support PKCS#8 private keys. The encryption provided by PKCS#8 is
    far superior to the OpenSSL formats. This is due to the fact that the
    OpenSSL formats don't stretch the passphrase, making it very easy to
    brute-force.

    :param private_key:
        An oscrypto.asymmetric.PrivateKey or asn1crypto.keys.PrivateKeyInfo
        object

    :param passphrase:
        A unicode string of the passphrase to encrypt the private key with.
        A passphrase of None will result in no encryption. A blank string will
        result in a ValueError to help ensure that the lack of passphrase is
        intentional.

    :raises:
        ValueError - when a blank string is provided for the passphrase

    :return:
        A byte string of the encoded and encrypted public key
    NrFrGrHz�
            private_key must be an instance of oscrypto.asymmetric.PrivateKey or
            asn1crypto.keys.PrivateKeyInfo, not %s
            �z4,ENCRYPTEDz	Proc-TypezAES-128-CBC,%s�asciizDEK-InforMr�ZeczEC PRIVATE KEY�rsazRSA PRIVATE KEYZdsazDSA PRIVATE KEY)�headers)r:rr;rrr8r$rrArr<rr
�binascii�hexlify�decoderR�hashlib�md5�digest�lenrrPr)
rSrTrBr>r_rYrVrWrXrZr?r?r@r1usN
��
�

$r1)r4)r4)r4)r4rE)@�
__future__rrrrrcr`rGrZ_asn1rr	rDr
rrr
rrrZ_asymmetricr�_errorsr�_typesrrZkdfrrZ	symmetricr�utilrZ_backendZ_mac.asymmetricrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-Z_win.asymmetricZ_openssl.asymmetric�__all__r0r3r/r2r1r?r?r?r@�<module>s,,
^^\
%
)
)
v