
    &g&                        d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
ZddlmZ ddlmZ d	Z ej                    Z e	j                    Z ej                    Z G d
 dej                  Z G d dej        ej                  ZdS )zRSA verifier and signer that use the ``cryptography`` library.

This is a much faster implementation than the default (in
``google.auth.crypt._python_rsa``), which depends on the pure-Python
``rsa`` library.
    N)backends)hashes)serialization)padding)_helpers)bases   -----BEGIN CERTIFICATE-----c                   j    e Zd ZdZd Z ej        ej                  d             Z	e
d             ZdS )RSAVerifierzVerifies RSA cryptographic signatures using public keys.

    Args:
        public_key (
                cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey):
            The public key used to verify signatures.
    c                     || _         d S N)_pubkey)self
public_keys     U/var/www/api/venv/lib/python3.11/site-packages/google/auth/crypt/_cryptography_rsa.py__init__zRSAVerifier.__init__/   s    !    c                     t          j        |          }	 | j                            ||t          t
                     dS # t          t          j        j	        f$ r Y dS w xY w)NTF)
r   to_bytesr   verify_PADDING_SHA256
ValueErrorcryptography
exceptionsInvalidSignature)r   message	signatures      r   r   zRSAVerifier.verify2   se    #G,,	L	7HgFFF4L3DE 	 	 	55	s   '? AAc                     t          j        |          }t          |v r:t          j                            |t                    }|                                }nt          j	        |t                    } | |          S )ay  Construct an 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:
            Verifier: The constructed verifier.

        Raises:
            ValueError: If the public key can't be parsed.
        )
r   r   _CERTIFICATE_MARKERr   x509load_pem_x509_certificate_BACKENDr   r   load_pem_public_key)clsr   public_key_datacertpubkeys        r   from_stringzRSAVerifier.from_string;   sq     #+J77/11$>> D __&&FF #6QQFs6{{r   N)__name__
__module____qualname____doc__r   r   copy_docstringr   Verifierr   classmethodr(    r   r   r
   r
   &   ss         " " " XT]++  ,+   [  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 Zd ZdS )
	RSASignera  Signs messages with an RSA private key.

    Args:
        private_key (
                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.
    Nc                 "    || _         || _        d S r   )_key_key_id)r   private_keykey_ids      r   r   zRSASigner.__init__d   s    	r   c                     | j         S r   )r5   )r   s    r   r7   zRSASigner.key_idh   s     |r   c                 v    t          j        |          }| j                            |t          t
                    S r   )r   r   r4   signr   r   )r   r   s     r   r:   zRSASigner.signm   s*    #G,,y~~gx999r   c                 |    t          j        |          }t          j        |dt                    } | ||          S )al  Construct a RSASigner from a private key in PEM format.

        Args:
            key (Union[bytes, str]): Private key in PEM format.
            key_id (str): An optional key id used to identify the private key.

        Returns:
            google.auth.crypt._cryptography_rsa.RSASigner: The
            constructed signer.

        Raises:
            ValueError: If ``key`` is not ``bytes`` or ``str`` (unicode).
            UnicodeDecodeError: If ``key`` is ``bytes`` but cannot be decoded
                into a UTF-8 ``str``.
            ValueError: If ``cryptography`` "Could not deserialize key data."
        N)passwordbackend)r7   )r   r   r   load_pem_private_keyr"   )r$   keyr7   r6   s       r   r(   zRSASigner.from_stringr   sI    $ $$#8$
 
 
 s;v....r   c                     | j                                         }| j                            t          j        j        t          j        j        t	          j	                              |d<   |S )z1Pickle helper that serializes the _key attribute.)encodingformatencryption_algorithmr4   )
__dict__copyr4   private_bytesr   EncodingPEMPrivateFormatPKCS8NoEncryptionr   states     r   __getstate__zRSASigner.__getstate__   sZ    ""$$	//"+/ .4!.!;!=!= 0 
 
f
 r   c                 v    t          j        |d         d          |d<   | j                            |           dS )z3Pickle helper that deserializes the _key attribute.r4   N)r   r>   rD   updaterL   s     r   __setstate__zRSASigner.__setstate__   s8    %:5=$OOfU#####r   r   )r)   r*   r+   r,   r   propertyr   r-   r   Signerr7   r:   r/   r(   rN   rQ   r0   r   r   r2   r2   X   s        	 	    XT[))  *) X XT[)): : *): / / / [/.  $ $ $ $ $r   r2   )r,   cryptography.exceptionsr   cryptography.hazmatr   cryptography.hazmat.primitivesr   r   )cryptography.hazmat.primitives.asymmetricr   cryptography.x509google.authr   google.auth.cryptr   r   default_backendr"   PKCS1v15r   SHA256r   r.   r
   rS   FromServiceAccountMixinr2   r0   r   r   <module>r_      s0        ( ( ( ( ( ( 1 1 1 1 1 1 8 8 8 8 8 8 = = = = = =                 " " " " " "4 #8#%%7
&-/// / / / /$- / / /d?$ ?$ ?$ ?$ ?$T9 ?$ ?$ ?$ ?$ ?$r   