
    i                         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	ej
                  Z G 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                   j    e Zd ZdZd Z ej        ej                  d             Z	e
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                    |j         j        }t          |t                    rt          }nB|                    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   s        V/usr/local/lib/hermes-agent/venv/lib/python3.11/site-packages/google/auth/crypt/rsa.py__init__zRSAVerifier.__init__+   s    )4
j,// 	R(HH""#899 	R555555"HHPd:>N>NPPQQQ))*55


    c                 8    | j                             ||          S N)r   verify)r   message	signatures      r   r   zRSAVerifier.verify7   s    z  )444r   c                 x    |                      |           }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   instances      r   r$   zRSAVerifier.from_string;   s2     ;;s##*6BB:NNr   N)__name__r   __qualname____doc__r   r   copy_docstringr   Verifierr   classmethodr$    r   r   r	   r	       ss         
6 
6 
6 XT]++5 5 ,+5   [  r   r	   c                       e Zd ZdZddZe ej        ej	                  d                         Z
 ej        ej	                  d             Ze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                    |j         j        }t          |t                    rt          }nB|                    t                    r	ddlm} |}nt          dt          |                     |                    ||          | _        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_keyr2   r   r   r   s         r   r   zRSASigner.__init__^   s     *5
k=11 	T(HH""#899 	T555555"HHRtK?P?PRRSSS''F'CC


r   c                     | j         j        S r   )r   r2   )r   s    r   r2   zRSASigner.key_idj   s     z  r   c                 6    | j                             |          S r   )r   sign)r   r    s     r   r6   zRSASigner.signo   s    zw'''r   c                 |    |                      |           }t          j                            ||          |_        |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.
        r1   )r#   r   r/   r$   r   )r%   keyr2   r&   s       r   r$   zRSASigner.from_strings   s7     ;;s##*4@@V@TTr   r   )r'   r   r(   r)   r   propertyr   r*   r   Signerr2   r6   r,   r$   r-   r   r   r/   r/   O   s         
D 
D 
D 
D XT[))! ! *) X! XT[))( ( *)(    [  r   r/   N)r)   -cryptography.hazmat.primitives.asymmetric.rsar   r   google.authr   r   r   r   r   r+   r	   r:   FromServiceAccountMixinr/   r-   r   r   <module>r>      s     H G G G G G F F F F F F             / / / / / / " " " " " "! , , , , ,$- , , ,^5 5 5 5 5T9 5 5 5 5 5r   