o
    bi                     @   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   O/home/kim/smarthome/.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   Z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$   Z-cryptography.hazmat.primitives.asymmetric.rsar   r   Zgoogle.authr   r   r   r   r   r&   r   r.   ZFromServiceAccountMixinr(   r   r   r   r   <module>   s   /