o
    ÔèFhÑ  ã                   @   s8   d Z ddlmZ ddlmZ dd„ Zdd„ Zdd	„ Zd
S )zUtilites for mutual TLS.é    )Ú
exceptions)Ú_mtls_helperc                  C   s   t  t j¡} | duS )z“Check if default client SSL credentials exists on the device.

    Returns:
        bool: indicating if the default client cert source exists.
    N)r   Ú_check_dca_metadata_pathÚCONTEXT_AWARE_METADATA_PATH)Úmetadata_path© r   úS/var/www/html/loop/nvenv/lib/python3.10/site-packages/google/auth/transport/mtls.pyÚhas_default_client_cert_source   s   ÿr	   c                  C   s   t ƒ st d¡‚dd„ } | S )aˆ  Get a callback which returns the default client SSL credentials.

    Returns:
        Callable[[], [bytes, bytes]]: A callback which returns the default
            client certificate bytes and private key bytes, both in PEM format.

    Raises:
        google.auth.exceptions.DefaultClientCertSourceError: If the default
            client SSL credentials don't exist or are malformed.
    z(Default client cert source doesn't existc               
   S   sH   zt  ¡ \} }}W ||fS  tttfy# } zt |¡}||‚d }~ww )N)r   Úget_client_cert_and_keyÚOSErrorÚRuntimeErrorÚ
ValueErrorr   ÚMutualTLSChannelError)Ú_Ú
cert_bytesÚ	key_bytesÚ
caught_excÚnew_excr   r   r   Úcallback1   s   ü
€þz,default_client_cert_source.<locals>.callback©r	   r   r   )r   r   r   r   Údefault_client_cert_source!   s   ÿ	r   c                    s"   t ƒ st d¡‚‡ ‡fdd„}|S )at  Get a callback which returns the default encrpyted client SSL credentials.

    Args:
        cert_path (str): The cert file path. The default client certificate will
            be written to this file when the returned callback is called.
        key_path (str): The key file path. The default encrypted client key will
            be written to this file when the returned callback is called.

    Returns:
        Callable[[], [str, str, bytes]]: A callback which generates the default
            client certificate, encrpyted private key and passphrase. It writes
            the certificate and private key into the cert_path and key_path, and
            returns the cert_path, key_path and passphrase bytes.

    Raises:
        google.auth.exceptions.DefaultClientCertSourceError: If any problem
            occurs when loading or saving the client certificate and key.
    z2Default client encrypted cert source doesn't existc               
      sº   z@t jdd�\} }}}tˆ dƒ�}| |¡ W d   ƒ n1 s w   Y  tˆdƒ�}| |¡ W d   ƒ n1 s:w   Y  W n tjtfyW } zt |¡}||‚d }~ww ˆ ˆ|fS )NT)Úgenerate_encrypted_keyÚwb)r   Úget_client_ssl_credentialsÚopenÚwriter   ÚClientCertErrorr   r   )r   r   r   Úpassphrase_bytesÚ	cert_fileÚkey_filer   r   ©Ú	cert_pathÚkey_pathr   r   r   U   s(   
ûÿÿ€
€þ
z6default_client_encrypted_cert_source.<locals>.callbackr   )r!   r"   r   r   r    r   Ú$default_client_encrypted_cert_source=   s   ÿr#   N)Ú__doc__Úgoogle.authr   Úgoogle.auth.transportr   r	   r   r#   r   r   r   r   Ú<module>   s   