U afV3@sXddlmZmZmZmZddlZddlZddlmZddl m Z m Z m Z mZmZmZmZmZmZddlmZddlmZddlmZmZdd lmZmZdd lmZdd l m!Z!eZ"e"d krdd l#m Z m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7ne"dks2e"dkrdd l8m Z m$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 l9m Z m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7ddddddddddddddddd d!d"d#d$d%d&d'd(d)gZ:d1d+dZ;d2d,dZd0dZ?dS)5)unicode_literalsdivisionabsolute_importprint_functionN)backend) armor Certificate DHParametersEncryptedPrivateKeyInfoNull OrderedDict Pbkdf2SaltPrivateKeyInfo PublicKeyInfo)_unwrap_private_key_info)pretty_message) type_namestr_cls)pbkdf2pbkdf2_iteration_calculator)aes_cbc_pkcs7_encrypt) rand_bytesmac)r dsa_sign dsa_verify ecdsa_sign ecdsa_verify generate_pairgenerate_dh_parametersload_certificate load_pkcs12load_private_keyload_public_key PrivateKey PublicKeyrsa_pkcs1v15_signrsa_pkcs1v15_verify rsa_pss_signrsa_pss_verifyrsa_pkcs1v15_encryptrsa_pkcs1v15_decryptrsa_oaep_encryptrsa_oaep_decryptwinZ winlegacyr rrdump_certificatedump_dh_parametersdump_openssl_private_keydump_private_keydump_public_keyrrrrr r!r"r#r$r%r-r,r+r*r&r'r(r)pemcCs\|tddgkr"ttdt|t|ts>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 r4derF 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 ValueErrorrrepr isinstancer TypeErrorrdumpr)Z dh_parametersencodingoutputr?D/opt/nydus/tmp/pip-target-53d1vnqk/lib/python/oscrypto/asymmetric.pyr0s  cCst|tddgkr"ttdt|t|t}t|tsL|sLttdt||rV|j }| }|dkrpt d|}|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;rasn1r<r)Z public_keyr= is_oscryptor>r?r?r@r3s"  cCst|tddgkr"ttdt|t|t}t|tsL|sLttdt||rV|j }| }|dkrpt d|}|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)Z certificater=rBr>r?r?r@r/s"  cCsh|tddgkr"ttdt||dk rZt|tsFttdt||dkrZttdt|t}t|t s|sttdt||r|j }| }|dk rcipher key_lengthZkdf_hmacZkdf_saltZ iterationspassphrase_byteskeyivZ ciphertext object_typer?r?r@r2sz        c Csl|dk r8t|ts$ttdt||dkr8ttdt|t}t|tsb|sbttdt||rl|j}t | }d}|dk r*t d}t }d|d<d t |d |d <d}|d }t||d d}|t|kr|t|||d d7}q|d |}t|||\}}|jdkrr_rYrVrWrXrZr?r?r@r1usN     $    )r4)r4)r4)r4rE)@ __future__rrrrrcr`rGrZ_asn1rr rDr r r r rrrZ _asymmetricr_errorsr_typesrrZkdfrrZ symmetricrutilrZ_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@s` ,     ^^\ % ) ) v