
    &gk                     *   d Z ddlm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	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 G d dej                  Z G d dej        ej                  ZdS )zIECDSA (ES256) verifier and signer that use the ``cryptography`` library.
    )utilsN)backends)hashes)serialization)ec)padding)decode_dss_signature)encode_dss_signature)_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 )ES256VerifierzVerifies ECDSA cryptographic signatures using public keys.

    Args:
        public_key (
                cryptography.hazmat.primitives.asymmetric.ec.ECDSAPublicKey):
            The public key used to verify signatures.
    c                     || _         d S N)_pubkey)self
public_keys     I/var/www/api/venv/lib/python3.11/site-packages/google/auth/crypt/es256.py__init__zES256Verifier.__init__/   s    !    c                    t          j        |          }t          |          dk    rdS t          j                    r$t                              |d d         d          nt          j        |d d         d          }t          j                    r$t                              |dd          d          nt          j        |dd          d          }t          ||          }t          j        |          }	 | j	        
                    ||t          j        t          j                                         dS # t          t           j        j        f$ r Y dS w xY w)N@   F    big	byteorderT)r   to_byteslenis_python_3int
from_bytesr   int_from_bytesr
   r   verifyr   ECDSAr   SHA256
ValueErrorcryptography
exceptionsInvalidSignature)r   message	signature	sig_bytesrsasn1_sigs          r   r#   zES256Verifier.verify2   sN    %i00	y>>R5 #%%GCNN9SbS>UN;;;%inFFF 	
 #%%GCNN9RSS>UN;;;%inFFF 	

 (1--#G,,	L'28FMOO3L3LMMM4L3DE 	 	 	55	s   9?D: :EE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ES256Verifier.from_stringK   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]++  ,+0   [  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 )
ES256Signera  Signs messages with an ECDSA private key.

    Args:
        private_key (
                cryptography.hazmat.primitives.asymmetric.ec.ECDSAPrivateKey):
            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ES256Signer.__init__t   s    	r   c                     | j         S r   )rG   )r   s    r   rI   zES256Signer.key_idx   s     |r   c                    t          j        |          }| j                            |t	          j        t          j                                        }t          |          \  }}t          j	                    r/|                    dd          |                    dd          z   n*t          j        |d          t          j        |d          z   S )Nr   r   r   )r   r   rF   signr   r$   r   r%   r	   r   r   int_to_bytes)r   r*   asn1_signaturer-   r.   s        r   rL   zES256Signer.sign}   s    #G,,&-//1J1JKK &n55A #%%IQZZeZ,,qzz"z/N/NNN$Q++e.@B.G.GG	
r   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)rI   )r   r   r   load_pem_private_keyr4   )r6   keyrI   rH   s       r   r:   zES256Signer.from_string   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_algorithmrF   )
__dict__copyrF   private_bytesr   EncodingPEMPrivateFormatPKCS8NoEncryptionr   states     r   __getstate__zES256Signer.__getstate__   sZ    ""$$	//"+/ .4!.!;!=!= 0 
 
f
 r   c                 v    t          j        |d         d          |d<   | j                            |           dS )z3Pickle helper that deserializes the _key attribute.rF   N)r   rR   rX   updater`   s     r   __setstate__zES256Signer.__setstate__   s8    %:5=$OOfU#####r   r   )r;   r<   r=   r>   r   propertyr   r?   r   SignerrI   rL   rA   r:   rb   re   rB   r   r   rD   rD   h   s        	 	    XT[))  *) X XT[))

 

 *)

 / / / [/.  $ $ $ $ $r   rD   )r>   r'   r   cryptography.exceptionscryptography.hazmatr   cryptography.hazmat.primitivesr   r   )cryptography.hazmat.primitives.asymmetricr   r   /cryptography.hazmat.primitives.asymmetric.utilsr	   r
   cryptography.x509google.authr   google.auth.cryptr   r1   default_backendr4   PKCS1v15_PADDINGr@   r   rg   FromServiceAccountMixinrD   rB   r   r   <module>rt      sw              ( ( ( ( ( ( 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8 8 8 = = = = = = P P P P P P P P P P P P                 " " " " " " 5 #8#%%7? ? ? ? ?DM ? ? ?DG$ G$ G$ G$ G$$+t; G$ G$ G$ G$ G$r   