U
    6d                     @   s   d Z ddlZddlZddlZddlZddlmZ dZdZe	ej
G dd deZe	ej
G dd	 d	eZe	ej
G d
d deZdS )z5Base classes for cryptographic signers and verifiers.    N)
exceptionsZprivate_keyZprivate_key_idc                   @   s   e Zd ZdZejdd ZdS )Verifierz9Abstract base class for crytographic signature verifiers.c                 C   s   t ddS )a  Verifies a message against a cryptographic signature.

        Args:
            message (Union[str, bytes]): The message to verify.
            signature (Union[str, bytes]): The cryptography signature to check.

        Returns:
            bool: True if message was signed by the private key associated
            with the public key that this object was constructed with.
        zVerify must be implementedNNotImplementedError)selfmessage	signature r	   :/tmp/pip-unpacked-wheel-h3lf9jv9/google/auth/crypt/base.pyverify!   s    zVerifier.verifyN)__name__
__module____qualname____doc__abcabstractmethodr   r	   r	   r	   r
   r      s   r   c                   @   s,   e Zd ZdZejdd Zejdd ZdS )Signerz.Abstract base class for cryptographic signers.c                 C   s   t ddS )z<Optional[str]: The key ID used to identify this private key.zKey id must be implementedNr   )r   r	   r	   r
   key_id6   s    zSigner.key_idc                 C   s   t ddS )zSigns a message.

        Args:
            message (Union[str, bytes]): The message to be signed.

        Returns:
            bytes: The signature of the message.
        zSign must be implementedNr   )r   r   r	   r	   r
   sign;   s    zSigner.signN)	r   r   r   r   r   abstractpropertyr   r   r   r	   r	   r	   r
   r   2   s
   
r   c                   @   s8   e Zd ZdZejd	ddZedd Zedd Z	dS )
FromServiceAccountMixinz3Mix-in to enable factory constructors for a Signer.Nc                 C   s   t ddS )ad  Construct an Signer instance from a private key string.

        Args:
            key (str): Private key as a string.
            key_id (str): An optional key id used to identify the private key.

        Returns:
            google.auth.crypt.Signer: The constructed signer.

        Raises:
            ValueError: If the key cannot be parsed.
        zfrom_string must be implementedNr   )clskeyr   r	   r	   r
   from_stringN   s    z#FromServiceAccountMixin.from_stringc                 C   s(   t |krtd| |t  |tS )a  Creates a Signer instance instance from a dictionary containing
        service account info in Google format.

        Args:
            info (Mapping[str, str]): The service account info in Google
                format.

        Returns:
            google.auth.crypt.Signer: The constructed signer.

        Raises:
            ValueError: If the info is not in the expected format.
        z@The private_key field was not found in the service account info.)_JSON_FILE_PRIVATE_KEYr   ZMalformedErrorr   get_JSON_FILE_PRIVATE_KEY_ID)r   infor	   r	   r
   from_service_account_info^   s     z1FromServiceAccountMixin.from_service_account_infoc              	   C   s0   t j|ddd}t|}W 5 Q R X | |S )a  Creates a Signer instance from a service account .json file
        in Google format.

        Args:
            filename (str): The path to the service account .json file.

        Returns:
            google.auth.crypt.Signer: The constructed signer.
        rzutf-8)encoding)ioopenjsonloadr   )r   filenameZ	json_filedatar	   r	   r
   from_service_account_filev   s    z1FromServiceAccountMixin.from_service_account_file)N)
r   r   r   r   r   r   r   classmethodr   r'   r	   r	   r	   r
   r   J   s   
r   )r   r   r!   r#   sixZgoogle.authr   r   r   add_metaclassABCMetaobjectr   r   r   r	   r	   r	   r
   <module>   s   


