
    *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dlm	Z	 dZ
 G d	 d
e	j                        Z G d de	j                  e	j                        Zy)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)_python_rsa)basezrsa.keyc                   j    e Zd ZdZd Z ej                  ej                        d        Z	e
d        Zy)RSAVerifiera5  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:
        ValueError: if an unrecognized public key is provided
    c                     |j                   j                  }t        |t              rt        }n3|j                  t              rt        }nt        dt        |             |j                  |      | _        y )Nzunrecognized public key type: )	__class__
__module__
isinstancer   r   
startswithRSA_KEY_MODULE_PREFIXr   
ValueErrortyper
   _impl)self
public_key
module_strimpl_libs       Q/mnt/e/genesis-system/.venv/lib/python3.12/site-packages/google/auth/crypt/rsa.py__init__zRSAVerifier.__init__+   sa    ))44
j,/(H""#89"H=d:>N=OPQQ))*5
    c                 :    | j                   j                  ||      S N)r   verify)r   message	signatures      r   r   zRSAVerifier.verify5   s    zz  )44r   c                 p    | j                  |       }t        j                  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_string9   s/     ;;s#*66BB:Nr   N)__name__r   __qualname____doc__r   r   copy_docstringr   Verifierr   classmethodr"    r   r   r
   r
   !   sE    6 XT]]+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y)	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:
        ValueError: if an unrecognized public key is provided
    Nc                     |j                   j                  }t        |t              rt        }n3|j                  t              rt        }nt        dt        |             |j                  ||      | _        y )Nzunrecognized private key type: key_id)r   r   r   r   r   r   r   r   r   r   r-   r   )r   private_keyr0   r   r   s        r   r   zRSASigner.__init__[   sf     **55
k=1(H""#89"H>tK?P>QRSS''F'C
r   c                 .    | j                   j                  S r   )r   r0   )r   s    r   r0   zRSASigner.key_ide   s     zz   r   c                 8    | j                   j                  |      S r   )r   sign)r   r   s     r   r4   zRSASigner.signj   s    zzw''r   c                 t    | j                  |       }t        j                  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.
        r/   )r!   r   r-   r"   r   )r#   keyr0   r$   s       r   r"   zRSASigner.from_stringn   s4     ;;s#*44@@V@Tr   r   )r%   r   r&   r'   r   propertyr   r(   r   Signerr0   r4   r*   r"   r+   r   r   r-   r-   M   ss    D XT[[)! * ! XT[[)( *(  r   r-   N)r'   -cryptography.hazmat.primitives.asymmetric.rsar   r   google.authr   google.auth.cryptr   r   r   r   r)   r
   r8   FromServiceAccountMixinr-   r+   r   r   <module>r=      sN    H F   / ) "! )$-- )X2T99 2r   