U
    6³d  ã                   @   s²   d Z ddlZddlmZ ddlmZ zddlmZ W n ek
rL   dZY nX edk	rhdddd	d
dgZndd	d
dgZejZej	Z	ej
Z
ejZedk	r ejZejZejfdd„ZdS )a\  Cryptography helpers for verifying and signing messages.

The simplest way to verify signatures is using :func:`verify_signature`::

    cert = open('certs.pem').read()
    valid = crypt.verify_signature(message, signature, cert)

If you're going to verify many messages with the same certificate, you can use
:class:`RSAVerifier`::

    cert = open('certs.pem').read()
    verifier = crypt.RSAVerifier.from_string(cert)
    valid = verifier.verify(message, signature)

To sign messages use :class:`RSASigner` with a private key::

    private_key = open('private_key.pem').read()
    signer = crypt.RSASigner.from_string(private_key)
    signature = signer.sign(message)

The code above also works for :class:`ES256Signer` and :class:`ES256Verifier`.
Note that these two classes are only available if your `cryptography` dependency
version is at least 1.4.0.
é    N)Úbase)Úrsa)Úes256ÚES256SignerÚES256VerifierÚ	RSASignerÚRSAVerifierÚSignerÚVerifierc                 C   sB   t |tjtjfƒr|g}|D ] }| |¡}| | |¡r dS qdS )a  Verify an RSA or ECDSA cryptographic signature.

    Checks that the provided ``signature`` was generated from ``bytes`` using
    the private key associated with the ``cert``.

    Args:
        message (Union[str, bytes]): The plaintext message.
        signature (Union[str, bytes]): The cryptographic signature to check.
        certs (Union[Sequence, str, bytes]): The certificate or certificates
            to use to check the signature.
        verifier_cls (Optional[~google.auth.crypt.base.Signer]): Which verifier
            class to use for verification. This can be used to select different
            algorithms, such as RSA or ECDSA. Default value is :class:`RSAVerifier`.

    Returns:
        bool: True if the signature is valid, otherwise False.
    TF)Ú
isinstanceÚsixÚ	text_typeÚbinary_typeZfrom_stringÚverify)ÚmessageÚ	signatureÚcertsZverifier_clsÚcertZverifier© r   ú>/tmp/pip-unpacked-wheel-h3lf9jv9/google/auth/crypt/__init__.pyÚverify_signatureK   s    
r   )Ú__doc__r   Zgoogle.auth.cryptr   r   r   ÚImportErrorÚ__all__r	   r
   r   r   r   r   r   r   r   r   r   Ú<module>   s0   
ú	