o
    í6Wj¢  ã                   @   sp   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dZ	G dd	„ d	ej
ƒZG d
d„ dejejƒZdS )z¶
RSA cryptography signer and verifier.

This file provides a shared wrapper, that defers to _python_rsa or _cryptography_rsa
for implmentations using different third party libraries
é    )ÚRSAPrivateKey)ÚRSAPublicKey)Ú_helpers)Ú_cryptography_rsa)Úbasezrsa.keyc                   @   s8   e Zd ZdZdd„ Ze ej¡dd„ ƒZ	e
dd„ ƒZdS )	ÚRSAVerifiera•  Verifies RSA cryptographic signatures using public keys.

    Args:
        public_key (Union["rsa.key.PublicKey", cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey]):
            The public key used to verify signatures.
    Raises:
        ImportError: if called with an rsa.key.PublicKey, when the rsa library is not installed
        ValueError: if an unrecognized public key is provided
    c                 C   sV   |j j}t|tƒrt}n| t¡rddlm} |}n	t	dt
|ƒ› �ƒ‚| |¡| _d S )Nr   ©Ú_python_rsazunrecognized public key type: )Ú	__class__Ú
__module__Ú
isinstancer   r   Ú
startswithÚRSA_KEY_MODULE_PREFIXÚgoogle.auth.cryptr	   Ú
ValueErrorÚtyper   Ú_impl)ÚselfÚ
public_keyÚ
module_strÚimpl_libr	   © r   úd/home/esfera/Documents/content_generation/venv/lib/python3.10/site-packages/google/auth/crypt/rsa.pyÚ__init__+   s   

zRSAVerifier.__init__c                 C   s   | j  ||¡S ©N)r   Úverify)r   ÚmessageÚ	signaturer   r   r   r   7   s   zRSAVerifier.verifyc                 C   s   |   | ¡}tj |¡|_|S )aŠ  Construct a Verifier instance from a public key or public
        certificate string.

        Args:
            public_key (Union[str, bytes]): The public key in PEM format or the
                x509 public key certificate.

        Returns:
            google.auth.crypt.Verifier: The constructed verifier.

        Raises:
            ValueError: If the public_key can't be parsed.
        )Ú__new__r   r   Úfrom_stringr   )Úclsr   Úinstancer   r   r   r   ;   s   
zRSAVerifier.from_stringN)Ú__name__r   Ú__qualname__Ú__doc__r   r   Úcopy_docstringr   ÚVerifierr   Úclassmethodr   r   r   r   r   r       s    


r   c                   @   sT   e Zd ZdZddd„Zee ej	¡dd„ ƒƒZ
e ej	¡dd„ ƒZedd	d
„ƒZdS )Ú	RSASignera=  Signs messages with an RSA private key.

    Args:
        private_key (Union["rsa.key.PrivateKey", cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey]):
            The private key to sign with.
        key_id (str): Optional key ID used to identify this private key. This
            can be useful to associate the private key with its associated
            public key or certificate.

    Raises:
        ImportError: if called with an rsa.key.PrivateKey, when the rsa library is not installed
        ValueError: if an unrecognized public key is provided
    Nc                 C   sZ   |j j}t|tƒrt}n| t¡rddlm} |}n	t	dt
|ƒ› �ƒ‚|j||d�| _d S )Nr   r   zunrecognized private key type: ©Úkey_id)r
   r   r   r   r   r   r   r   r	   r   r   r(   r   )r   Úprivate_keyr*   r   r   r	   r   r   r   r   ^   s   

zRSASigner.__init__c                 C   s   | j jS r   )r   r*   )r   r   r   r   r*   j   s   zRSASigner.key_idc                 C   s   | j  |¡S r   )r   Úsign)r   r   r   r   r   r,   o   s   zRSASigner.signc                 C   s    |   | ¡}tjj||d�|_|S )až  Construct a Signer instance from a private key in PEM format.

        Args:
            key (str): Private key in PEM format.
            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 as PKCS#1 or PKCS#8 in
                PEM format.
        r)   )r   r   r(   r   r   )r    Úkeyr*   r!   r   r   r   r   s   s   
zRSASigner.from_stringr   )r"   r   r#   r$   r   Úpropertyr   r%   r   ÚSignerr*   r,   r'   r   r   r   r   r   r(   O   s    



r(   N)r$   Ú-cryptography.hazmat.primitives.asymmetric.rsar   r   Úgoogle.authr   r   r   r   r   r&   r   r/   ÚFromServiceAccountMixinr(   r   r   r   r   Ú<module>   s   /